Skip to content

Commit ab35d75

Browse files
committed
monkeypatch _is_installed function
1 parent f6ce689 commit ab35d75

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

tests/test_packsmanager.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import os
22
import re
3-
import subprocess
43
from pathlib import Path
54

65
import pytest
76

7+
from diffpy.cmi import installer
88
from diffpy.cmi.packsmanager import PacksManager
99

1010

@@ -372,21 +372,24 @@ def test_copy_examples_force(example_cases, expected_paths, force):
372372

373373
@pytest.mark.parametrize("packs_to_install,expected", install_params)
374374
def test_print_packs_and_examples(
375-
packs_to_install, expected, example_cases, capsys, conda_env
375+
packs_to_install, expected, example_cases, capsys, monkeypatch
376376
):
377-
env_dir_str = Path(conda_env).as_posix()
378-
shell = os.name == "nt"
379-
req_dir = example_cases / "case5" / "requirements" / "packs"
377+
case5dir = example_cases / "case5"
378+
req_dir = case5dir / "requirements" / "packs"
379+
380+
installed_reqs = []
380381
for pack in packs_to_install:
381-
req_file = (req_dir / f"{pack}.txt").as_posix()
382-
subprocess.run(
383-
["conda", "install", "-y", "--file", req_file, "-p", env_dir_str],
384-
check=True,
385-
capture_output=True,
386-
text=True,
387-
shell=shell,
388-
)
389-
pm = PacksManager(root_path=example_cases / "case5")
382+
req_file = req_dir / f"{pack}.txt"
383+
for line in req_file.read_text().splitlines():
384+
line = line.strip()
385+
installed_reqs.append(line)
386+
387+
def mock_is_installed(name: str) -> bool:
388+
return name in installed_reqs
389+
390+
monkeypatch.setattr(installer, "_is_installed", mock_is_installed)
391+
392+
pm = PacksManager(root_path=case5dir)
390393
pm.print_packs()
391394
pm.print_examples()
392395
captured = capsys.readouterr()

0 commit comments

Comments
 (0)