|
4 | 4 |
|
5 | 5 |
|
6 | 6 | @pytest.mark.parametrize( |
7 | | - "expected_dict", |
| 7 | + "expected", |
8 | 8 | [ |
9 | 9 | { |
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", |
15 | 15 | ] |
16 | | - } |
| 16 | + }, |
| 17 | + { |
| 18 | + # test pack with no examples |
| 19 | + "no_examples": [] |
| 20 | + }, |
17 | 21 | ], |
18 | 22 | ) |
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) |
33 | 40 |
|
34 | 41 |
|
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) |
38 | 44 | pkmg.print_info() |
39 | 45 | captured = capsys.readouterr() |
40 | 46 | output = captured.out.strip() |
|
0 commit comments