Skip to content

Commit d78efd5

Browse files
committed
test print_profiles function
1 parent 2ab0101 commit d78efd5

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/test_profilesmanager.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import pytest
2+
import yaml
3+
4+
from diffpy.cmi.profilesmanager import ProfilesManager
5+
6+
install_params = [
7+
( # input: profiles to install
8+
# expected: print_profile output showing profileA
9+
# installed but not profileB
10+
("profileA",),
11+
"""Installed Profiles:
12+
-------------------
13+
profileA
14+
15+
Available Profiles:
16+
-------------------
17+
profileB
18+
""",
19+
),
20+
]
21+
22+
23+
@pytest.mark.parametrize("profiles_to_install,expected", install_params)
24+
def test_print_profiles(
25+
profiles_to_install, expected, example_cases, capsys, mocker
26+
):
27+
case5dir = example_cases / "case5"
28+
req_dir = case5dir / "requirements" / "profiles"
29+
30+
installed_reqs = []
31+
for profile in profiles_to_install:
32+
req_file = req_dir / f"{profile}.yml"
33+
content = yaml.safe_load(req_file.read_text())
34+
for pack in content.get("packs", []):
35+
installed_reqs.append(pack)
36+
37+
def fake_check_profile(identifier):
38+
return identifier == "profileA"
39+
40+
mocker.patch.object(
41+
ProfilesManager, "check_profile", side_effect=fake_check_profile
42+
)
43+
pfm = ProfilesManager(root_path=case5dir)
44+
pfm.print_profiles()
45+
captured = capsys.readouterr()
46+
actual = captured.out
47+
assert actual.strip() == expected.strip()

0 commit comments

Comments
 (0)