|
| 1 | +import os |
1 | 2 | from pathlib import Path |
2 | 3 |
|
3 | 4 | import pytest |
|
25 | 26 | # each user input |
26 | 27 | case_params = [ |
27 | 28 | ( |
28 | | - "case1", # empty pack |
29 | 29 | [ |
30 | 30 | ["empty_pack"], # 4) all examples from a pack (but pack is empty) |
31 | 31 | ["all"], # 6) all examples from all packs (but pack is empty) |
|
36 | 36 | ], |
37 | 37 | ), |
38 | 38 | ( |
39 | | - "case2", # one pack with multiple examples |
40 | 39 | [ |
41 | 40 | ["ex1"], # 1) single example |
42 | 41 | ["ex1", "ex2"], # 2) multiple examples from same pack |
|
63 | 62 | ], |
64 | 63 | ), |
65 | 64 | ( |
66 | | - "case3", # multiple packs with multiple examples |
67 | 65 | [ |
68 | 66 | ["ex1"], # 1) single example from packA |
69 | 67 | ["ex1", "ex2"], # 2) list of examples from same pack |
|
102 | 100 | ], |
103 | 101 | ), |
104 | 102 | ( |
105 | | - "case4", # no packs (empty examples directory) |
106 | 103 | [ |
107 | 104 | ["all"], # 6) all examples from all packs (but examples exist) |
108 | 105 | ], |
|
111 | 108 | ], |
112 | 109 | ), |
113 | 110 | ( |
114 | | - "case5", # multiple packs containing examples with the same name |
115 | 111 | [ |
116 | 112 | ["ex1"], # 1) single example (ambiguous, should get both) |
117 | 113 | [ |
|
145 | 141 | ] |
146 | 142 |
|
147 | 143 |
|
148 | | -@pytest.mark.parametrize("target", ["cwd", "target"]) |
149 | | -@pytest.mark.parametrize("input,user_inputs,expected", case_params) |
150 | | -def test_copy_examples(input, expected, user_inputs, target, example_cases): |
151 | | - case_dir = example_cases / input |
| 144 | +@pytest.mark.parametrize( |
| 145 | + "case,target", |
| 146 | + [ |
| 147 | + ("case1", None), |
| 148 | + ("case1", "user_target"), |
| 149 | + ("case2", None), |
| 150 | + ("case2", "user_target"), |
| 151 | + ("case3", None), |
| 152 | + ("case3", "user_target"), |
| 153 | + ("case4", None), |
| 154 | + ("case4", "user_target"), |
| 155 | + ("case5", None), |
| 156 | + ("case5", "user_target"), |
| 157 | + ], |
| 158 | +) |
| 159 | +@pytest.mark.parametrize("user_inputs,expected", case_params) |
| 160 | +def test_copy_examples(case, user_inputs, expected, target, example_cases): |
| 161 | + cwd = example_cases / "cwd" |
| 162 | + os.chdir(cwd) |
| 163 | + case_dir = example_cases / case |
152 | 164 | pm = PacksManager(root_path=case_dir) |
153 | 165 | examples_dict = pm.available_examples() |
154 | | - if target == "target": |
155 | | - target_dir = case_dir / "target_dir" |
| 166 | + if target is None: |
| 167 | + target_dir = cwd |
156 | 168 | else: |
157 | | - target_dir = case_dir |
158 | | - target_dir.mkdir(parents=True, exist_ok=True) |
| 169 | + target_dir = case_dir / "user_target" |
159 | 170 | for command in user_inputs: |
160 | | - copy_examples(examples_dict, user_input=command, target_dir=target_dir) |
| 171 | + copy_examples( |
| 172 | + examples_dict, |
| 173 | + user_input=command, |
| 174 | + target_dir=None if target is None else target_dir, |
| 175 | + ) |
| 176 | + if expected: |
161 | 177 | for exp_paths in expected: |
162 | 178 | for path in exp_paths: |
163 | 179 | dest_file = target_dir / path |
164 | | - assert dest_file.exists(), f"{dest_file} missing" |
| 180 | + assert dest_file.exists() |
| 181 | + else: |
| 182 | + empty_dir = list(target_dir.rglob("*")) |
| 183 | + assert not empty_dir, f"Expected nothing, but found: {empty_dir}" |
0 commit comments