|
1 | 1 | import os |
2 | 2 | import re |
3 | | -import subprocess |
4 | 3 | from pathlib import Path |
5 | 4 |
|
6 | 5 | import pytest |
7 | 6 |
|
| 7 | +from diffpy.cmi import installer |
8 | 8 | from diffpy.cmi.packsmanager import PacksManager |
9 | 9 |
|
10 | 10 |
|
@@ -372,21 +372,24 @@ def test_copy_examples_force(example_cases, expected_paths, force): |
372 | 372 |
|
373 | 373 | @pytest.mark.parametrize("packs_to_install,expected", install_params) |
374 | 374 | 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 |
376 | 376 | ): |
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 = [] |
380 | 381 | 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) |
390 | 393 | pm.print_packs() |
391 | 394 | pm.print_examples() |
392 | 395 | captured = capsys.readouterr() |
|
0 commit comments