MCPcopy Create free account
hub / github.com/conda/constructor / test_initialization

Function test_initialization

tests/test_examples.py:1365–1443  ·  view source on GitHub ↗
(tmp_path, request, monkeypatch, method)

Source from the content-addressed store, hash-verified

1363@pytest.mark.skipif(not ON_CI, reason="Run on CI only")
1364@pytest.mark.parametrize("method", ("classic", "condabin", True, False))
1365def test_initialization(tmp_path, request, monkeypatch, method):
1366 request.addfinalizer(
1367 lambda: subprocess.run([sys.executable, "-m", "conda", "init", "--reverse"])
1368 )
1369 monkeypatch.setenv("initialization_method", str(method).lower())
1370 input_path = _example_path("initialization")
1371 initialize = method is not False
1372 for installer, install_dir in create_installer(input_path, tmp_path):
1373 if installer.suffix == ".sh" and initialize:
1374 options = ["-c"]
1375 elif installer.suffix == ".exe":
1376 # GHA runs on an admin user account, but AllUsers (admin) installs
1377 # do not add to PATH due to CVE-2022-26526, so force single user install
1378 options = ["/AddToPath=1", "/InstallationType=JustMe"]
1379 elif installer.suffix == ".msi":
1380 # MSI uses OPTION_INITIALIZE_CONDA property instead of /AddToPath
1381 options = ["OPTION_INITIALIZE_CONDA=1"] if initialize else []
1382 else:
1383 options = []
1384 _run_installer(
1385 input_path,
1386 installer,
1387 install_dir,
1388 request=request,
1389 check_subprocess=True,
1390 uninstall=False,
1391 options=options,
1392 )
1393 if installer.suffix == ".exe":
1394 try:
1395 paths = []
1396 for root, keyname in (
1397 (winreg.HKEY_CURRENT_USER, r"Environment"),
1398 (
1399 winreg.HKEY_LOCAL_MACHINE,
1400 r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment",
1401 ),
1402 ):
1403 with winreg.OpenKey(root, keyname, 0, winreg.KEY_QUERY_VALUE) as key:
1404 value = winreg.QueryValueEx(key, "PATH")[0]
1405 paths += value.strip().split(os.pathsep)
1406 if method == "condabin":
1407 assert (str(install_dir / "condabin") in paths) == initialize
1408 else:
1409 assert (str(install_dir) in paths) == initialize
1410 assert (str(install_dir / "Scripts") in paths) == initialize
1411 assert (str(install_dir / "Library" / "bin") in paths) == initialize
1412
1413 finally:
1414 _run_uninstaller_exe(install_dir, check=True)
1415 elif installer.suffix == ".msi":
1416 try:
1417 prefix = install_dir / "base"
1418 with winreg.OpenKey(
1419 winreg.HKEY_CURRENT_USER, "Environment", 0, winreg.KEY_QUERY_VALUE
1420 ) as key:
1421 value = winreg.QueryValueEx(key, "Path")[0]
1422 paths = value.strip().split(os.pathsep)

Callers

nothing calls this directly

Calls 6

_example_pathFunction · 0.85
create_installerFunction · 0.85
_run_installerFunction · 0.85
_run_uninstaller_exeFunction · 0.85
_run_uninstaller_msiFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected