Skip to content

Commit

Permalink
Simplify magic number release test
Browse files Browse the repository at this point in the history
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
  • Loading branch information
appeltel committed Mar 11, 2017
1 parent 51835c7 commit 9ea7c52
Show file tree
Hide file tree
Showing 5 changed files with 2,240 additions and 2,277 deletions.
15 changes: 0 additions & 15 deletions Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,21 +248,6 @@ def _write_atomic(path, data, mode=0o666):
#
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.
#
# In general, the MAGIC_NUMBER should not change for maintenance releases
# although this may be required under exceptional circumstances. When
# each release reaches candidate status, an entry in EXPECTED_MAGIC_NUMBERS
# should be added for this release. This value is tested against the actual
# MAGIC_NUMBER to ensure that if a change is required within a minor
# release, the exception is first discussed with python-dev and relevant
# community stakeholders such as OS distribution package maintainers
# are properly informed of the change.

EXPECTED_MAGIC_NUMBERS = {
(2, 7): 62211,
(3, 5): 3350,
(3, 6): 3379
}

MAGIC_NUMBER = (3390).to_bytes(2, 'little') + b'\r\n'
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
Expand Down
1 change: 0 additions & 1 deletion Lib/importlib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from ._bootstrap import _resolve_name
from ._bootstrap import spec_from_loader
from ._bootstrap import _find_spec
from ._bootstrap_external import EXPECTED_MAGIC_NUMBERS
from ._bootstrap_external import MAGIC_NUMBER
from ._bootstrap_external import cache_from_source
from ._bootstrap_external import decode_source
Expand Down
57 changes: 0 additions & 57 deletions Lib/test/test_importlib/test_release.py

This file was deleted.

44 changes: 44 additions & 0 deletions Lib/test/test_importlib/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,5 +757,49 @@ def test_source_from_cache_path_like_arg(self):
) = util.test_both(PEP3147Tests, util=importlib_util)


class MagicNumberTests:
"""
Test release compatibility issues relating to importlib
"""
def test_magic_number(self):
"""
Each python minor release should generally have a MAGIC_NUMBER
that does not change once the release reaches candidate status.
Once a release reaches candidate status, the value of the constant
EXPECTED_MAGIC_NUMBER in this test should be changed.
This test will then check that the actual MAGIC_NUMBER matches
the expected value for the release.
In exceptional cases, it may be required to change the MAGIC_NUMBER
for a maintenance release. In this case the change should be
discussed in python-dev. If a change is required, community
stakeholders such as OS package maintainers must be notified
in advance. Such exceptional releases will then require an
adjustment to this test case.
"""
if sys.version_info.releaselevel not in ('final', 'candidate'):
return
EXPECTED_MAGIC_NUMBER = 3379
actual = int.from_bytes(self.util.MAGIC_NUMBER[:2], 'little')

msg = (
"Candidate and final releases require the current "
"importlib.util.MAGIC_NUMBER to match the expected "
"magic number in this test. Set the expected "
"magic number in this test to the current MAGIC_NUMBER to "
"continue with the release.\n\n"
"Changing the MAGIC_NUMBER for a maintenance release "
"requires discussion in python-dev and notification of "
"community stakeholders."
)
self.assertEqual(EXPECTED_MAGIC_NUMBER, actual, msg)


Source_MagicNumberTests = util.specialize_class(
MagicNumberTests, 'Source', None, util=importlib_util
)


if __name__ == '__main__':
unittest.main()
Loading

0 comments on commit 9ea7c52

Please sign in to comment.