|
20 | 20 | import stat |
21 | 21 | import subprocess |
22 | 22 | import sys |
| 23 | +import tempfile |
23 | 24 | import textwrap |
24 | 25 | import threading |
25 | 26 | import time |
@@ -1272,23 +1273,25 @@ def test_import_from_undecodable_path(self): |
1272 | 1273 | origin = _testsinglephase.__file__ |
1273 | 1274 | # The module is cached by its path, so restore it afterwards. |
1274 | 1275 | self.addCleanup(restore__testsinglephase) |
1275 | | - with os_helper.temp_dir() as tempdir: |
1276 | | - subdir = os.path.join(os.fsencode(tempdir), |
1277 | | - os_helper.TESTFN_UNDECODABLE) |
1278 | | - try: |
1279 | | - os.mkdir(subdir) |
1280 | | - except OSError: |
1281 | | - self.skipTest('undecodable paths are not supported') |
1282 | | - path = os.path.join(subdir, os.fsencode(os.path.basename(origin))) |
1283 | | - shutil.copyfile(origin, path) |
1284 | | - path = os.fsdecode(path) |
1285 | | - spec = importlib.util.spec_from_file_location('_testsinglephase', |
1286 | | - path) |
1287 | | - module = importlib.util.module_from_spec(spec) |
1288 | | - spec.loader.exec_module(module) |
1289 | | - self.assertEqual(module.__name__, '_testsinglephase') |
1290 | | - self.assertEqual(module.__file__, path) |
1291 | | - _testinternalcapi.clear_extension('_testsinglephase', path) |
| 1276 | + tempdir = tempfile.mkdtemp() |
| 1277 | + # The copied extension module stays loaded, so on Windows it cannot |
| 1278 | + # be removed. |
| 1279 | + self.addCleanup(shutil.rmtree, tempdir, ignore_errors=True) |
| 1280 | + subdir = os.path.join(os.fsencode(tempdir), |
| 1281 | + os_helper.TESTFN_UNDECODABLE) |
| 1282 | + try: |
| 1283 | + os.mkdir(subdir) |
| 1284 | + except OSError: |
| 1285 | + self.skipTest('undecodable paths are not supported') |
| 1286 | + path = os.path.join(subdir, os.fsencode(os.path.basename(origin))) |
| 1287 | + shutil.copyfile(origin, path) |
| 1288 | + path = os.fsdecode(path) |
| 1289 | + spec = importlib.util.spec_from_file_location('_testsinglephase', path) |
| 1290 | + module = importlib.util.module_from_spec(spec) |
| 1291 | + spec.loader.exec_module(module) |
| 1292 | + self.assertEqual(module.__name__, '_testsinglephase') |
| 1293 | + self.assertEqual(module.__file__, path) |
| 1294 | + _testinternalcapi.clear_extension('_testsinglephase', path) |
1292 | 1295 |
|
1293 | 1296 | def test_create_builtin(self): |
1294 | 1297 | class Spec: |
|
0 commit comments