Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions news/fix-print-test.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* No news needed.

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
21 changes: 0 additions & 21 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
33 changes: 19 additions & 14 deletions tests/test_packsmanager.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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()
Expand Down
Loading