|
4 | 4 | machinery = util.import_importlib('importlib.machinery')
|
5 | 5 | importlib_util = util.import_importlib('importlib.util')
|
6 | 6 |
|
| 7 | +import importlib.util |
7 | 8 | import os
|
8 | 9 | import pathlib
|
9 | 10 | import string
|
@@ -757,5 +758,48 @@ def test_source_from_cache_path_like_arg(self):
|
757 | 758 | ) = util.test_both(PEP3147Tests, util=importlib_util)
|
758 | 759 |
|
759 | 760 |
|
| 761 | +class MagicNumberTests(unittest.TestCase): |
| 762 | + """ |
| 763 | + Test release compatibility issues relating to importlib |
| 764 | + """ |
| 765 | + @unittest.skipUnless( |
| 766 | + sys.version_info.releaselevel in ('final', 'release'), |
| 767 | + 'only applies to candidate or final python release levels' |
| 768 | + ) |
| 769 | + def test_magic_number(self): |
| 770 | + """ |
| 771 | + Each python minor release should generally have a MAGIC_NUMBER |
| 772 | + that does not change once the release reaches candidate status. |
| 773 | +
|
| 774 | + Once a release reaches candidate status, the value of the constant |
| 775 | + EXPECTED_MAGIC_NUMBER in this test should be changed. |
| 776 | + This test will then check that the actual MAGIC_NUMBER matches |
| 777 | + the expected value for the release. |
| 778 | +
|
| 779 | + In exceptional cases, it may be required to change the MAGIC_NUMBER |
| 780 | + for a maintenance release. In this case the change should be |
| 781 | + discussed in python-dev. If a change is required, community |
| 782 | + stakeholders such as OS package maintainers must be notified |
| 783 | + in advance. Such exceptional releases will then require an |
| 784 | + adjustment to this test case. |
| 785 | + """ |
| 786 | + EXPECTED_MAGIC_NUMBER = 3379 |
| 787 | + actual = int.from_bytes(importlib.util.MAGIC_NUMBER[:2], 'little') |
| 788 | + |
| 789 | + msg = ( |
| 790 | + "To avoid breaking backwards compatibility with cached bytecode " |
| 791 | + "files that can't be automatically regenerated by the current " |
| 792 | + "user, candidate and final releases require the current " |
| 793 | + "importlib.util.MAGIC_NUMBER to match the expected " |
| 794 | + "magic number in this test. Set the expected " |
| 795 | + "magic number in this test to the current MAGIC_NUMBER to " |
| 796 | + "continue with the release.\n\n" |
| 797 | + "Changing the MAGIC_NUMBER for a maintenance release " |
| 798 | + "requires discussion in python-dev and notification of " |
| 799 | + "community stakeholders." |
| 800 | + ) |
| 801 | + self.assertEqual(EXPECTED_MAGIC_NUMBER, actual, msg) |
| 802 | + |
| 803 | + |
760 | 804 | if __name__ == '__main__':
|
761 | 805 | unittest.main()
|
0 commit comments