Skip to content

Commit 296c941

Browse files
authored
Merge pull request #89 from cadenmyers13/fix-print-test
test: monkeypatch `print_info` test
2 parents e2b11a8 + cd1eb20 commit 296c941

File tree

3 files changed

+42
-35
lines changed

3 files changed

+42
-35
lines changed

news/fix-print-test.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* No news needed.
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

tests/conftest.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,10 @@
11
import json
2-
import os
3-
import subprocess
42
from pathlib import Path
53

64
import matplotlib
75
import pytest
86

97

10-
@pytest.fixture(scope="function")
11-
def conda_env(tmp_path):
12-
env_dir = tmp_path / "fake_env"
13-
env_dir_str = env_dir.as_posix()
14-
shell = os.name == "nt"
15-
subprocess.run(
16-
["conda", "create", "-y", "-p", env_dir_str],
17-
check=True,
18-
capture_output=True,
19-
shell=shell,
20-
)
21-
yield env_dir_str
22-
subprocess.run(
23-
["conda", "env", "remove", "-p", env_dir_str, "-y"],
24-
check=True,
25-
shell=shell,
26-
)
27-
28-
298
@pytest.fixture(scope="function")
309
def example_cases(tmp_path_factory):
3110
"""Copy the entire examples tree into a temp directory once per test

tests/test_packsmanager.py

Lines changed: 19 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,26 @@ 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, mocker
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+
if line and not line.startswith("#"):
386+
installed_reqs.append(line)
387+
388+
def mock_is_installed(name: str) -> bool:
389+
return name in installed_reqs
390+
391+
mocker.patch.object(
392+
installer, "_is_installed", side_effect=mock_is_installed
393+
)
394+
pm = PacksManager(root_path=case5dir)
390395
pm.print_packs()
391396
pm.print_examples()
392397
captured = capsys.readouterr()

0 commit comments

Comments
 (0)