diff options
Diffstat (limited to 'Lib/test')
| -rw-r--r-- | Lib/test/test_faulthandler.py | 15 | ||||
| -rw-r--r-- | Lib/test/test_import.py | 18 |
2 files changed, 24 insertions, 9 deletions
diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py index 1138f8f..8c12b21 100644 --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -7,6 +7,7 @@ import signal import subprocess import sys from test import support, script_helper +from test.script_helper import assert_python_ok import tempfile import unittest @@ -256,6 +257,20 @@ faulthandler._read_null() finally: sys.stderr = orig_stderr + def test_disabled_by_default(self): + # By default, the module should be disabled + code = "import faulthandler; print(faulthandler.is_enabled())" + rc, stdout, stderr = assert_python_ok("-c", code) + stdout = (stdout + stderr).strip() + self.assertEqual(stdout, b"False") + + def test_sys_xoptions(self): + # Test python -X faulthandler + code = "import faulthandler; print(faulthandler.is_enabled())" + rc, stdout, stderr = assert_python_ok("-X", "faulthandler", "-c", code) + stdout = (stdout + stderr).strip() + self.assertEqual(stdout, b"True") + def check_dump_traceback(self, filename): """ Explicitly call dump_traceback() function and check its output. diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py index 3e61577..2e58199 100644 --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -785,11 +785,13 @@ class ImportTracebackTests(unittest.TestCase): sys.path[:] = self.old_path rmtree(TESTFN) - def create_module(self, mod, contents): - with open(os.path.join(TESTFN, mod + ".py"), "w") as f: + def create_module(self, mod, contents, ext=".py"): + fname = os.path.join(TESTFN, mod + ext) + with open(fname, "w") as f: f.write(contents) self.addCleanup(unload, mod) importlib.invalidate_caches() + return fname def assert_traceback(self, tb, files): deduped_files = [] @@ -857,16 +859,14 @@ class ImportTracebackTests(unittest.TestCase): def _setup_broken_package(self, parent, child): pkg_name = "_parent_foo" - def cleanup(): - rmtree(pkg_name) - unload(pkg_name) - os.mkdir(pkg_name) - self.addCleanup(cleanup) + self.addCleanup(unload, pkg_name) + pkg_path = os.path.join(TESTFN, pkg_name) + os.mkdir(pkg_path) # Touch the __init__.py - init_path = os.path.join(pkg_name, '__init__.py') + init_path = os.path.join(pkg_path, '__init__.py') with open(init_path, 'w') as f: f.write(parent) - bar_path = os.path.join(pkg_name, 'bar.py') + bar_path = os.path.join(pkg_path, 'bar.py') with open(bar_path, 'w') as f: f.write(child) importlib.invalidate_caches() |
