Skip to content

Commit d9e4093

Browse files
committed
refactor(tests): convert test_import.py tests to use NamedTuple fixtures
1 parent 5faffb5 commit d9e4093

File tree

1 file changed

+83
-31
lines changed

1 file changed

+83
-31
lines changed

tests/cli/test_import.py

Lines changed: 83 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,82 @@
1515
import pathlib
1616

1717

18-
@pytest.mark.parametrize("cli_args", [(["import"])])
18+
class ImportTestFixture(t.NamedTuple):
19+
"""Test fixture for basic tmuxp import command tests."""
20+
21+
test_id: str
22+
cli_args: list[str]
23+
24+
25+
class ImportTeamocilTestFixture(t.NamedTuple):
26+
"""Test fixture for tmuxp import teamocil command tests."""
27+
28+
test_id: str
29+
cli_args: list[str]
30+
inputs: list[str]
31+
32+
33+
class ImportTmuxinatorTestFixture(t.NamedTuple):
34+
"""Test fixture for tmuxp import tmuxinator command tests."""
35+
36+
test_id: str
37+
cli_args: list[str]
38+
inputs: list[str]
39+
40+
41+
IMPORT_TEST_FIXTURES: list[ImportTestFixture] = [
42+
ImportTestFixture(
43+
test_id="basic_import",
44+
cli_args=["import"],
45+
),
46+
]
47+
48+
49+
IMPORT_TEAMOCIL_TEST_FIXTURES: list[ImportTeamocilTestFixture] = [
50+
ImportTeamocilTestFixture(
51+
test_id="import_teamocil_config_file",
52+
cli_args=["import", "teamocil", "./.teamocil/config.yaml"],
53+
inputs=["\n", "y\n", "./la.yaml\n", "y\n"],
54+
),
55+
ImportTeamocilTestFixture(
56+
test_id="import_teamocil_config_file_exists",
57+
cli_args=["import", "teamocil", "./.teamocil/config.yaml"],
58+
inputs=["\n", "y\n", "./exists.yaml\n", "./la.yaml\n", "y\n"],
59+
),
60+
ImportTeamocilTestFixture(
61+
test_id="import_teamocil_config_name",
62+
cli_args=["import", "teamocil", "config"],
63+
inputs=["\n", "y\n", "./exists.yaml\n", "./la.yaml\n", "y\n"],
64+
),
65+
]
66+
67+
68+
IMPORT_TMUXINATOR_TEST_FIXTURES: list[ImportTmuxinatorTestFixture] = [
69+
ImportTmuxinatorTestFixture(
70+
test_id="import_tmuxinator_config_file",
71+
cli_args=["import", "tmuxinator", "./.tmuxinator/config.yaml"],
72+
inputs=["\n", "y\n", "./la.yaml\n", "y\n"],
73+
),
74+
ImportTmuxinatorTestFixture(
75+
test_id="import_tmuxinator_config_file_exists",
76+
cli_args=["import", "tmuxinator", "./.tmuxinator/config.yaml"],
77+
inputs=["\n", "y\n", "./exists.yaml\n", "./la.yaml\n", "y\n"],
78+
),
79+
ImportTmuxinatorTestFixture(
80+
test_id="import_tmuxinator_config_name",
81+
cli_args=["import", "tmuxinator", "config"],
82+
inputs=["\n", "y\n", "./exists.yaml\n", "./la.yaml\n", "y\n"],
83+
),
84+
]
85+
86+
87+
@pytest.mark.parametrize(
88+
list(ImportTestFixture._fields),
89+
IMPORT_TEST_FIXTURES,
90+
ids=[test.test_id for test in IMPORT_TEST_FIXTURES],
91+
)
1992
def test_import(
93+
test_id: str,
2094
cli_args: list[str],
2195
tmp_path: pathlib.Path,
2296
monkeypatch: pytest.MonkeyPatch,
@@ -30,23 +104,12 @@ def test_import(
30104

31105

32106
@pytest.mark.parametrize(
33-
("cli_args", "inputs"),
34-
[
35-
(
36-
["import", "teamocil", "./.teamocil/config.yaml"],
37-
["\n", "y\n", "./la.yaml\n", "y\n"],
38-
),
39-
(
40-
["import", "teamocil", "./.teamocil/config.yaml"],
41-
["\n", "y\n", "./exists.yaml\n", "./la.yaml\n", "y\n"],
42-
),
43-
(
44-
["import", "teamocil", "config"],
45-
["\n", "y\n", "./exists.yaml\n", "./la.yaml\n", "y\n"],
46-
),
47-
],
107+
list(ImportTeamocilTestFixture._fields),
108+
IMPORT_TEAMOCIL_TEST_FIXTURES,
109+
ids=[test.test_id for test in IMPORT_TEAMOCIL_TEST_FIXTURES],
48110
)
49111
def test_import_teamocil(
112+
test_id: str,
50113
cli_args: list[str],
51114
inputs: list[str],
52115
tmp_path: pathlib.Path,
@@ -77,23 +140,12 @@ def test_import_teamocil(
77140

78141

79142
@pytest.mark.parametrize(
80-
("cli_args", "inputs"),
81-
[
82-
(
83-
["import", "tmuxinator", "./.tmuxinator/config.yaml"],
84-
["\n", "y\n", "./la.yaml\n", "y\n"],
85-
),
86-
(
87-
["import", "tmuxinator", "./.tmuxinator/config.yaml"],
88-
["\n", "y\n", "./exists.yaml\n", "./la.yaml\n", "y\n"],
89-
),
90-
(
91-
["import", "tmuxinator", "config"],
92-
["\n", "y\n", "./exists.yaml\n", "./la.yaml\n", "y\n"],
93-
),
94-
],
143+
list(ImportTmuxinatorTestFixture._fields),
144+
IMPORT_TMUXINATOR_TEST_FIXTURES,
145+
ids=[test.test_id for test in IMPORT_TMUXINATOR_TEST_FIXTURES],
95146
)
96147
def test_import_tmuxinator(
148+
test_id: str,
97149
cli_args: list[str],
98150
inputs: list[str],
99151
tmp_path: pathlib.Path,

0 commit comments

Comments
 (0)