| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -4,6 +4,7 @@ | |
| machinery = util.import_importlib('importlib.machinery') | ||
| importlib_util = util.import_importlib('importlib.util') | ||
|
|
||
| import importlib.util | ||
| import os | ||
| import pathlib | ||
| import string | ||
| Expand Down Expand Up | @@ -757,5 +758,48 @@ def test_source_from_cache_path_like_arg(self): | |
| ) = util.test_both(PEP3147Tests, util=importlib_util) | ||
|
|
||
|
|
||
| class MagicNumberTests(unittest.TestCase): | ||
| """ | ||
| Test release compatibility issues relating to importlib | ||
| """ | ||
| @unittest.skipUnless( | ||
| sys.version_info.releaselevel in ('final', 'release'), | ||
| 'only applies to candidate or final python release levels' | ||
| ) | ||
| 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. | ||
| """ | ||
| EXPECTED_MAGIC_NUMBER = 3379 | ||
| actual = int.from_bytes(importlib.util.MAGIC_NUMBER[:2], 'little') | ||
|
|
||
| msg = ( | ||
| "To avoid breaking backwards compatibility with cached bytecode " | ||
|
Comment thread
Copy link
Copy Markdown
Member
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityWouldn't be better to use a multiline string literal if you want such verbose error message? But I think that "broken *.pyc files compatibility" would be enough.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThen you'd have to dedent it, etc. This message is perfectly legible to me.
Sorry, something went wrong.
All reactions
|
||
| "files that can't be automatically regenerated by the current " | ||
| "user, 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) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI 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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.