Skip to content

Commit 9ea7c52

Browse files
committed
Simplify magic number release test
Simplify the magic number release test by removing EXPECTED_MAGIC_NUMBERS table and making the expected magic number self-contained within the test. BPO: 29514
1 parent 51835c7 commit 9ea7c52

File tree

5 files changed

+2240
-2277
lines changed

5 files changed

+2240
-2277
lines changed

Lib/importlib/_bootstrap_external.py

-15
Original file line numberDiff line numberDiff line change
@@ -248,21 +248,6 @@ def _write_atomic(path, data, mode=0o666):
248248
#
249249
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
250250
# in PC/launcher.c must also be updated.
251-
#
252-
# In general, the MAGIC_NUMBER should not change for maintenance releases
253-
# although this may be required under exceptional circumstances. When
254-
# each release reaches candidate status, an entry in EXPECTED_MAGIC_NUMBERS
255-
# should be added for this release. This value is tested against the actual
256-
# MAGIC_NUMBER to ensure that if a change is required within a minor
257-
# release, the exception is first discussed with python-dev and relevant
258-
# community stakeholders such as OS distribution package maintainers
259-
# are properly informed of the change.
260-
261-
EXPECTED_MAGIC_NUMBERS = {
262-
(2, 7): 62211,
263-
(3, 5): 3350,
264-
(3, 6): 3379
265-
}
266251

267252
MAGIC_NUMBER = (3390).to_bytes(2, 'little') + b'\r\n'
268253
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c

Lib/importlib/util.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from ._bootstrap import _resolve_name
55
from ._bootstrap import spec_from_loader
66
from ._bootstrap import _find_spec
7-
from ._bootstrap_external import EXPECTED_MAGIC_NUMBERS
87
from ._bootstrap_external import MAGIC_NUMBER
98
from ._bootstrap_external import cache_from_source
109
from ._bootstrap_external import decode_source

Lib/test/test_importlib/test_release.py

-57
This file was deleted.

Lib/test/test_importlib/test_util.py

+44
Original file line numberDiff line numberDiff line change
@@ -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+
760804
if __name__ == '__main__':
761805
unittest.main()

0 commit comments

Comments
 (0)