diff --git a/news/fix-print-test.rst b/news/fix-print-test.rst new file mode 100644 index 0000000..27fc85d --- /dev/null +++ b/news/fix-print-test.rst @@ -0,0 +1,23 @@ +**Added:** + +* No news needed. + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/tests/conftest.py b/tests/conftest.py index 0f51a62..af72bd5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,31 +1,10 @@ import json -import os -import subprocess from pathlib import Path import matplotlib import pytest -@pytest.fixture(scope="function") -def conda_env(tmp_path): - env_dir = tmp_path / "fake_env" - env_dir_str = env_dir.as_posix() - shell = os.name == "nt" - subprocess.run( - ["conda", "create", "-y", "-p", env_dir_str], - check=True, - capture_output=True, - shell=shell, - ) - yield env_dir_str - subprocess.run( - ["conda", "env", "remove", "-p", env_dir_str, "-y"], - check=True, - shell=shell, - ) - - @pytest.fixture(scope="function") def example_cases(tmp_path_factory): """Copy the entire examples tree into a temp directory once per test diff --git a/tests/test_packsmanager.py b/tests/test_packsmanager.py index c0adf49..a870479 100644 --- a/tests/test_packsmanager.py +++ b/tests/test_packsmanager.py @@ -1,10 +1,10 @@ import os import re -import subprocess from pathlib import Path import pytest +from diffpy.cmi import installer from diffpy.cmi.packsmanager import PacksManager @@ -372,21 +372,26 @@ def test_copy_examples_force(example_cases, expected_paths, force): @pytest.mark.parametrize("packs_to_install,expected", install_params) def test_print_packs_and_examples( - packs_to_install, expected, example_cases, capsys, conda_env + packs_to_install, expected, example_cases, capsys, mocker ): - env_dir_str = Path(conda_env).as_posix() - shell = os.name == "nt" - req_dir = example_cases / "case5" / "requirements" / "packs" + case5dir = example_cases / "case5" + req_dir = case5dir / "requirements" / "packs" + + installed_reqs = [] for pack in packs_to_install: - req_file = (req_dir / f"{pack}.txt").as_posix() - subprocess.run( - ["conda", "install", "-y", "--file", req_file, "-p", env_dir_str], - check=True, - capture_output=True, - text=True, - shell=shell, - ) - pm = PacksManager(root_path=example_cases / "case5") + req_file = req_dir / f"{pack}.txt" + for line in req_file.read_text().splitlines(): + line = line.strip() + if line and not line.startswith("#"): + installed_reqs.append(line) + + def mock_is_installed(name: str) -> bool: + return name in installed_reqs + + mocker.patch.object( + installer, "_is_installed", side_effect=mock_is_installed + ) + pm = PacksManager(root_path=case5dir) pm.print_packs() pm.print_examples() captured = capsys.readouterr()