Skip to content

Commit 79fa679

Browse files
committed
modify test for new tmp dir structure
1 parent d57e7fa commit 79fa679

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

tests/test_cli.py

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from pathlib import Path
23

34
import pytest
@@ -25,7 +26,6 @@
2526
# each user input
2627
case_params = [
2728
(
28-
"case1", # empty pack
2929
[
3030
["empty_pack"], # 4) all examples from a pack (but pack is empty)
3131
["all"], # 6) all examples from all packs (but pack is empty)
@@ -36,7 +36,6 @@
3636
],
3737
),
3838
(
39-
"case2", # one pack with multiple examples
4039
[
4140
["ex1"], # 1) single example
4241
["ex1", "ex2"], # 2) multiple examples from same pack
@@ -63,7 +62,6 @@
6362
],
6463
),
6564
(
66-
"case3", # multiple packs with multiple examples
6765
[
6866
["ex1"], # 1) single example from packA
6967
["ex1", "ex2"], # 2) list of examples from same pack
@@ -102,7 +100,6 @@
102100
],
103101
),
104102
(
105-
"case4", # no packs (empty examples directory)
106103
[
107104
["all"], # 6) all examples from all packs (but examples exist)
108105
],
@@ -111,7 +108,6 @@
111108
],
112109
),
113110
(
114-
"case5", # multiple packs containing examples with the same name
115111
[
116112
["ex1"], # 1) single example (ambiguous, should get both)
117113
[
@@ -145,20 +141,43 @@
145141
]
146142

147143

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
152164
pm = PacksManager(root_path=case_dir)
153165
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
156168
else:
157-
target_dir = case_dir
158-
target_dir.mkdir(parents=True, exist_ok=True)
169+
target_dir = case_dir / "user_target"
159170
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:
161177
for exp_paths in expected:
162178
for path in exp_paths:
163179
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

Comments
 (0)