ยปCore Development>Code coverage>Lib/test/test_crashers.py

Python code coverage for Lib/test/test_crashers.py

#countcontent
1n/a# Tests that the crashers in the Lib/test/crashers directory actually
2n/a# do crash the interpreter as expected
3n/a#
4n/a# If a crasher is fixed, it should be moved elsewhere in the test suite to
5n/a# ensure it continues to work correctly.
6n/a
7n/aimport unittest
8n/aimport glob
9n/aimport os.path
10n/aimport test.support
11n/afrom test.support.script_helper import assert_python_failure
12n/a
13n/aCRASHER_DIR = os.path.join(os.path.dirname(__file__), "crashers")
14n/aCRASHER_FILES = os.path.join(CRASHER_DIR, "*.py")
15n/a
16n/ainfinite_loops = ["infinite_loop_re.py", "nasty_eq_vs_dict.py"]
17n/a
18n/aclass CrasherTest(unittest.TestCase):
19n/a
20n/a @unittest.skip("these tests are too fragile")
21n/a @test.support.cpython_only
22n/a def test_crashers_crash(self):
23n/a for fname in glob.glob(CRASHER_FILES):
24n/a if os.path.basename(fname) in infinite_loops:
25n/a continue
26n/a # Some "crashers" only trigger an exception rather than a
27n/a # segfault. Consider that an acceptable outcome.
28n/a if test.support.verbose:
29n/a print("Checking crasher:", fname)
30n/a assert_python_failure(fname)
31n/a
32n/a
33n/adef tearDownModule():
34n/a test.support.reap_children()
35n/a
36n/aif __name__ == "__main__":
37n/a unittest.main()