-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-43381: Add frozen module co_lines() test #24712
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,23 +7,36 @@ | |
# | ||
# The test_importlib also tests this module but because those tests | ||
# are much more complicated, it might be unclear why they are failing. | ||
# Invalid marshalled data in frozen.c could case the interpreter to | ||
# crash when __hello__ is imported. | ||
|
||
import sys | ||
import unittest | ||
from test.support import captured_stdout | ||
from test.support import captured_stdout, impl_detail | ||
|
||
|
||
class TestFrozen(unittest.TestCase): | ||
def test_frozen(self): | ||
name = '__hello__' | ||
if name in sys.modules: | ||
del sys.modules[name] | ||
# Invalid marshalled data in frozen.c could case the interpreter to | ||
# crash when __hello__ is imported. Ensure we can import the module | ||
# and that it generates the correct output. | ||
with captured_stdout() as out: | ||
import __hello__ | ||
self.assertEqual(out.getvalue(), 'Hello world!\n') | ||
|
||
@impl_detail('code object line table', cpython=True) | ||
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. a small nitpick: cpython arg is not needed and other uses of @impl_detail in tests leave it out (with just one exception). |
||
def test_frozen_linetab(self): | ||
with captured_stdout(): | ||
import __hello__ | ||
# get the code object for the module | ||
co = __hello__.__spec__.loader.get_code('__hello__') | ||
# verify that line number table is as expected. This is intended to | ||
# catch bugs like bpo-43372. The __hello__ module would import | ||
# successfully but the frozen code was out-of-date and co_lines() | ||
# would cause a crash. | ||
self.assertEqual(list(co.co_lines()), [(0, 4, 1), (4, 16, 2)]) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Tests/2021-03-02-16-55-37.bpo-43381.45RrT9.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add a small test for frozen code co_lines(). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
case/cause