(self)
| 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.""" |
nothing calls this directly
no test coverage detected