@@ -757,5 +757,49 @@ def test_source_from_cache_path_like_arg(self):
757757 ) = util .test_both (PEP3147Tests , util = importlib_util )
758758
759759
760+ class MagicNumberTests :
761+ """
762+ Test release compatibility issues relating to importlib
763+ """
764+ def test_magic_number (self ):
765+ """
766+ Each python minor release should generally have a MAGIC_NUMBER
767+ that does not change once the release reaches candidate status.
768+
769+ Once a release reaches candidate status, the value of the constant
770+ EXPECTED_MAGIC_NUMBER in this test should be changed.
771+ This test will then check that the actual MAGIC_NUMBER matches
772+ the expected value for the release.
773+
774+ In exceptional cases, it may be required to change the MAGIC_NUMBER
775+ for a maintenance release. In this case the change should be
776+ discussed in python-dev. If a change is required, community
777+ stakeholders such as OS package maintainers must be notified
778+ in advance. Such exceptional releases will then require an
779+ adjustment to this test case.
780+ """
781+ if sys .version_info .releaselevel not in ('final' , 'candidate' ):
782+ return
783+ EXPECTED_MAGIC_NUMBER = 3379
784+ actual = int .from_bytes (self .util .MAGIC_NUMBER [:2 ], 'little' )
785+
786+ msg = (
787+ "Candidate and final releases require the current "
788+ "importlib.util.MAGIC_NUMBER to match the expected "
789+ "magic number in this test. Set the expected "
790+ "magic number in this test to the current MAGIC_NUMBER to "
791+ "continue with the release.\n \n "
792+ "Changing the MAGIC_NUMBER for a maintenance release "
793+ "requires discussion in python-dev and notification of "
794+ "community stakeholders."
795+ )
796+ self .assertEqual (EXPECTED_MAGIC_NUMBER , actual , msg )
797+
798+
799+ Source_MagicNumberTests = util .specialize_class (
800+ MagicNumberTests , 'Source' , None , util = importlib_util
801+ )
802+
803+
760804if __name__ == '__main__' :
761805 unittest .main ()
0 commit comments