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

Method test_init_setpythonhome

Lib/test/test_embed.py:1474–1517  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1472 yield tmpdir
1473
1474 def test_init_setpythonhome(self):
1475 # Test Py_SetPythonHome(home) with PYTHONPATH env var
1476 config = self._get_expected_config()
1477 paths = config['config']['module_search_paths']
1478 paths_str = os.path.pathsep.join(paths)
1479
1480 for path in paths:
1481 if not os.path.isdir(path):
1482 continue
1483 if os.path.exists(os.path.join(path, 'os.py')):
1484 home = os.path.dirname(path)
1485 break
1486 else:
1487 self.fail(f"Unable to find home in {paths!r}")
1488
1489 prefix = exec_prefix = home
1490 if MS_WINDOWS:
1491 stdlib = os.path.join(home, "Lib")
1492 # Because we are specifying 'home', module search paths
1493 # are fairly static
1494 expected_paths = [paths[0], os.path.join(home, 'DLLs'), stdlib]
1495 else:
1496 version = f'{sys.version_info.major}.{sys.version_info.minor}'
1497 stdlib = os.path.join(home, sys.platlibdir, f'python{version}{ABI_THREAD}')
1498 expected_paths = self.module_search_paths(prefix=home, exec_prefix=home)
1499
1500 config = {
1501 'home': home,
1502 'module_search_paths': expected_paths,
1503 'prefix': prefix,
1504 'base_prefix': prefix,
1505 'exec_prefix': exec_prefix,
1506 'base_exec_prefix': exec_prefix,
1507 'pythonpath_env': paths_str,
1508 'stdlib_dir': stdlib,
1509 }
1510 self.default_program_name(config)
1511 env = {'TESTHOME': home, 'PYTHONPATH': paths_str}
1512 # When running from source, TESTHOME will be the build directory, which
1513 # isn't a valid home unless _is_python_build is set. getpath will then
1514 # fail to find the standard library and show a warning, so we need to
1515 # ignore stderr.
1516 self.check_all_configs("test_init_setpythonhome", config,
1517 api=API_COMPAT, env=env, ignore_stderr=True)
1518
1519 def test_init_is_python_build_with_home(self):
1520 # Test _Py_path_config._is_python_build configuration (gh-91985)

Callers

nothing calls this directly

Calls 9

_get_expected_configMethod · 0.95
module_search_pathsMethod · 0.95
default_program_nameMethod · 0.95
check_all_configsMethod · 0.95
joinMethod · 0.45
isdirMethod · 0.45
existsMethod · 0.45
dirnameMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected