MCPcopy Index your code
hub / github.com/python/cpython / test_del_on_shutdown

Method test_del_on_shutdown

Lib/test/test_tempfile.py:1880–1910  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1878 f"TemporaryDirectory {temp_path!s} existence state unexpected")
1879
1880 def test_del_on_shutdown(self):
1881 # A TemporaryDirectory may be cleaned up during shutdown
1882 with self.do_create() as dir:
1883 for mod in ('builtins', 'os', 'shutil', 'sys', 'tempfile', 'warnings'):
1884 code = """if True:
1885 import builtins
1886 import os
1887 import shutil
1888 import sys
1889 import tempfile
1890 import warnings
1891
1892 tmp = tempfile.TemporaryDirectory(dir={dir!r})
1893 sys.stdout.buffer.write(tmp.name.encode())
1894
1895 tmp2 = os.path.join(tmp.name, 'test_dir')
1896 os.mkdir(tmp2)
1897 with open(os.path.join(tmp2, "test0.txt"), "w") as f:
1898 f.write("Hello world!")
1899
1900 {mod}.tmp = tmp
1901
1902 warnings.filterwarnings("always", category=ResourceWarning)
1903 """.format(dir=dir, mod=mod)
1904 rc, out, err = script_helper.assert_python_ok("-c", code)
1905 tmp_name = out.decode().strip()
1906 self.assertFalse(os.path.exists(tmp_name),
1907 "TemporaryDirectory %s exists after cleanup" % tmp_name)
1908 err = err.decode('utf-8', 'backslashreplace')
1909 self.assertNotIn("Exception ", err)
1910 self.assertIn("ResourceWarning: Implicitly cleaning up", err)
1911
1912 def test_del_on_shutdown_ignore_errors(self):
1913 """Test ignoring errors works when a tempdir is gc'ed on shutdown."""

Callers

nothing calls this directly

Calls 9

do_createMethod · 0.95
assert_python_okMethod · 0.80
assertFalseMethod · 0.80
assertNotInMethod · 0.80
assertInMethod · 0.80
formatMethod · 0.45
stripMethod · 0.45
decodeMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected