diff options
author | Victor Stinner <vstinner@python.org> | 2021-01-25 13:24:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-25 13:24:42 +0100 |
commit | db584bdad32d81e42b71871077a8008036f5c048 (patch) | |
tree | ef018339067b08456b55a083547f9427b817f1b3 /Lib | |
parent | bpo-43013: Fix old tkinter module names in idlelib (GH-24326) (diff) | |
download | cpython-db584bdad32d81e42b71871077a8008036f5c048.tar.gz cpython-db584bdad32d81e42b71871077a8008036f5c048.tar.bz2 cpython-db584bdad32d81e42b71871077a8008036f5c048.zip |
bpo-42955: Add sys.modules_names (GH-24238)
Add sys.module_names, containing the list of the standard library
module names.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_capi.py | 17 | ||||
-rw-r--r-- | Lib/test/test_faulthandler.py | 8 | ||||
-rw-r--r-- | Lib/test/test_sys.py | 5 |
3 files changed, 24 insertions, 6 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index 67175cd044a..5f5c0d038d9 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -569,12 +569,23 @@ class CAPITest(unittest.TestCase): self.assertEqual(len(modules), total) def test_fatal_error(self): + # By default, stdlib extension modules are ignored, + # but not test modules. expected = ('_testcapi',) - not_expected = ('sys', 'builtins', '_imp', '_thread', '_weakref', - '_io', 'marshal', '_signal', '_abc') - code = 'import _testcapi; _testcapi.fatal_error(b"MESSAGE")' + not_expected = ('sys',) + code = 'import _testcapi, sys; _testcapi.fatal_error(b"MESSAGE")' self.check_fatal_error(code, expected, not_expected) + # Mark _testcapi as stdlib module, but not sys + expected = ('sys',) + not_expected = ('_testcapi',) + code = textwrap.dedent(''' + import _testcapi, sys + sys.module_names = frozenset({"_testcapi"}) + _testcapi.fatal_error(b"MESSAGE") + ''') + self.check_fatal_error(code, expected) + class TestPendingCalls(unittest.TestCase): diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py index b4a654f8a9c..02077a69bb4 100644 --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -334,8 +334,9 @@ class FaultHandlerTests(unittest.TestCase): def test_dump_ext_modules(self): code = """ import faulthandler - # _testcapi is a test module and not considered as a stdlib module - import _testcapi + import sys + # Don't filter stdlib module names + sys.module_names = frozenset() faulthandler.enable() faulthandler._sigsegv() """ @@ -346,7 +347,8 @@ class FaultHandlerTests(unittest.TestCase): if not match: self.fail(f"Cannot find 'Extension modules:' in {stderr!r}") modules = set(match.group(1).strip().split(', ')) - self.assertIn('_testcapi', modules) + for name in ('sys', 'faulthandler'): + self.assertIn(name, modules) def test_is_enabled(self): orig_stderr = sys.stderr diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 3af5b117aff..729b8667fc8 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -986,6 +986,11 @@ class SysModuleTest(unittest.TestCase): self.assertEqual(proc.stdout.rstrip().splitlines(), expected, proc) + def test_module_names(self): + self.assertIsInstance(sys.module_names, frozenset) + for name in sys.module_names: + self.assertIsInstance(name, str) + @test.support.cpython_only class UnraisableHookTest(unittest.TestCase): |