Skip to content

Commit 9fcef71

Browse files
committed
update available_examples test
1 parent db2ac9a commit 9fcef71

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

tests/test_packsmanager.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,43 @@
44

55

66
@pytest.mark.parametrize(
7-
"expected_dict",
7+
"expected",
88
[
99
{
10-
"pdf": [
11-
"ch03NiModelling",
12-
"ch06RefineCrystalStructureGen",
13-
"ch07StructuralPhaseTransition",
14-
"ch08NPRefinement",
10+
# test with pack that has examples
11+
"pack1": [
12+
"ex1",
13+
"ex2",
14+
"ex3",
1515
]
16-
}
16+
},
17+
{
18+
# test pack with no examples
19+
"no_examples": []
20+
},
1721
],
1822
)
19-
def test_available_examples(expected_dict):
20-
"""Test that available_examples returns a dict."""
21-
pkmg = PacksManager()
22-
returned_dict = pkmg.available_examples()
23-
expected_pack = list(expected_dict.keys())
24-
returned_pack = list(returned_dict.keys())
25-
for pack in expected_pack:
26-
assert pack in returned_pack, f"{pack} not found in returned packs."
27-
expected_examples = expected_dict[pack]
28-
returned_examples = returned_dict.get(pack, [])
29-
for ex in expected_examples:
30-
assert (
31-
ex in returned_examples
32-
), f"{ex} not found under pack {pack}."
23+
def test_available_examples(temp_path, expected):
24+
for pack, examples in expected.items():
25+
pack_dir = temp_path / pack
26+
pack_dir.mkdir(parents=True, exist_ok=True)
27+
for ex in examples:
28+
ex_dir = pack_dir / ex
29+
ex_dir.mkdir(parents=True, exist_ok=True)
30+
pkmg = PacksManager(temp_path)
31+
actual = pkmg.available_examples(temp_path)
32+
assert actual == expected
33+
34+
35+
def test_available_examples_bad(temp_path):
36+
pkmg = PacksManager(temp_path)
37+
bad_path = temp_path / "nonexistent"
38+
with pytest.raises(FileNotFoundError):
39+
pkmg.available_examples(bad_path)
3340

3441

35-
def test_print_info(capsys):
36-
"""Test that print_info prints expected information to stdout."""
37-
pkmg = PacksManager()
42+
def test_print_info(temp_path, capsys):
43+
pkmg = PacksManager(temp_path)
3844
pkmg.print_info()
3945
captured = capsys.readouterr()
4046
output = captured.out.strip()

0 commit comments

Comments
 (0)