-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-29514: Check magic number for bugfix release #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be better to write this as a comment rather than a docstring. If you want, add a one-line docstring, but most test methods don't have docstrings. |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can change to a
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 1e32a1b |
||
EXPECTED_MAGIC_NUMBER = 3379 | ||
actual = int.from_bytes(self.util.MAGIC_NUMBER[:2], 'little') | ||
|
||
msg = ( | ||
"Candidate and final releases require the current " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd start this message with "To avoid breaking backwards compatibility with cached bytecode files that can't be automatically regenerated by the current user, ..." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in 1e32a1b |
||
"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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inherit from
unittest.TestCase
hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially avoided this and followed the test machinery as I wasn't sure about directly importing
importlib.util
within this test module, but after looking at the way the test specialization works I don't see how this is an issue. Changed in 1e32a1b.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this module does some interesting things to create "real" test classes in different configurations, but we don't need those kinds of tricks for the new test.