diff options
author | Victor Stinner <vstinner@python.org> | 2021-01-19 23:35:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-19 23:35:27 +0100 |
commit | 66f77caca39ba39ebe1e4a95dba6d19b20d51951 (patch) | |
tree | 5a3e9d28e72c0c15c2e313b51eef7b239a0a4bdc /Lib/test/test_capi.py | |
parent | cad8020cb83ec6d904f874c0e4f599e651022196 (diff) | |
download | cpython-git-66f77caca39ba39ebe1e4a95dba6d19b20d51951.tar.gz |
bpo-42923: _Py_DumpExtensionModules() ignores stdlib ext (GH-24254)
Diffstat (limited to 'Lib/test/test_capi.py')
-rw-r--r-- | Lib/test/test_capi.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index 5e72ba9eb0..67175cd044 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -547,8 +547,7 @@ class CAPITest(unittest.TestCase): self.assertRaises(TypeError, pynumber_tobase, '123', 10) self.assertRaises(SystemError, pynumber_tobase, 123, 0) - def test_fatal_error(self): - code = 'import _testcapi; _testcapi.fatal_error(b"MESSAGE")' + def check_fatal_error(self, code, expected, not_expected=()): with support.SuppressCrashReport(): rc, out, err = assert_python_failure('-sSI', '-c', code) @@ -556,15 +555,25 @@ class CAPITest(unittest.TestCase): self.assertIn('Fatal Python error: test_fatal_error: MESSAGE\n', err) - match = re.search('^Extension modules:(.*)$', err, re.MULTILINE) + match = re.search(r'^Extension modules:(.*) \(total: ([0-9]+)\)$', + err, re.MULTILINE) if not match: self.fail(f"Cannot find 'Extension modules:' in {err!r}") modules = set(match.group(1).strip().split(', ')) - # Test _PyModule_IsExtension(): the list doesn't have to - # be exhaustive. - for name in ('sys', 'builtins', '_imp', '_thread', '_weakref', - '_io', 'marshal', '_signal', '_abc', '_testcapi'): + total = int(match.group(2)) + + for name in expected: self.assertIn(name, modules) + for name in not_expected: + self.assertNotIn(name, modules) + self.assertEqual(len(modules), total) + + def test_fatal_error(self): + expected = ('_testcapi',) + not_expected = ('sys', 'builtins', '_imp', '_thread', '_weakref', + '_io', 'marshal', '_signal', '_abc') + code = 'import _testcapi; _testcapi.fatal_error(b"MESSAGE")' + self.check_fatal_error(code, expected, not_expected) class TestPendingCalls(unittest.TestCase): |