(self, subdir=None)
| 1445 | |
| 1446 | @contextlib.contextmanager |
| 1447 | def tmpdir_with_python(self, subdir=None): |
| 1448 | # Temporary directory with a copy of the Python program |
| 1449 | with tempfile.TemporaryDirectory() as tmpdir: |
| 1450 | # bpo-38234: On macOS and FreeBSD, the temporary directory |
| 1451 | # can be symbolic link. For example, /tmp can be a symbolic link |
| 1452 | # to /var/tmp. Call realpath() to resolve all symbolic links. |
| 1453 | tmpdir = os.path.realpath(tmpdir) |
| 1454 | if subdir: |
| 1455 | tmpdir = os.path.normpath(os.path.join(tmpdir, subdir)) |
| 1456 | os.makedirs(tmpdir) |
| 1457 | |
| 1458 | if MS_WINDOWS: |
| 1459 | # Copy pythonXY.dll (or pythonXY_d.dll) |
| 1460 | import fnmatch |
| 1461 | exedir = os.path.dirname(self.test_exe) |
| 1462 | for f in os.listdir(exedir): |
| 1463 | if fnmatch.fnmatch(f, '*.dll'): |
| 1464 | shutil.copyfile(os.path.join(exedir, f), os.path.join(tmpdir, f)) |
| 1465 | |
| 1466 | # Copy Python program |
| 1467 | exec_copy = os.path.join(tmpdir, os.path.basename(self.test_exe)) |
| 1468 | shutil.copyfile(self.test_exe, exec_copy) |
| 1469 | shutil.copystat(self.test_exe, exec_copy) |
| 1470 | self.test_exe = exec_copy |
| 1471 | |
| 1472 | yield tmpdir |
| 1473 | |
| 1474 | def test_init_setpythonhome(self): |
| 1475 | # Test Py_SetPythonHome(home) with PYTHONPATH env var |
no test coverage detected