Skip to content

Commit a1c8d0e

Browse files
committed
refactor(tests): convert test_finder.py pure name test to use NamedTuple fixtures
1 parent 5ac4a0c commit a1c8d0e

File tree

1 file changed

+75
-15
lines changed

1 file changed

+75
-15
lines changed

tests/workspace/test_finder.py

Lines changed: 75 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,73 @@
2222
import _pytest.capture
2323

2424

25+
class PureNameTestFixture(t.NamedTuple):
26+
"""Test fixture for verifying pure name path validation."""
27+
28+
test_id: str
29+
path: str
30+
expect: bool
31+
32+
33+
PURE_NAME_TEST_FIXTURES: list[PureNameTestFixture] = [
34+
PureNameTestFixture(
35+
test_id="current_dir",
36+
path=".",
37+
expect=False,
38+
),
39+
PureNameTestFixture(
40+
test_id="current_dir_slash",
41+
path="./",
42+
expect=False,
43+
),
44+
PureNameTestFixture(
45+
test_id="empty_path",
46+
path="",
47+
expect=False,
48+
),
49+
PureNameTestFixture(
50+
test_id="tmuxp_yaml",
51+
path=".tmuxp.yaml",
52+
expect=False,
53+
),
54+
PureNameTestFixture(
55+
test_id="parent_tmuxp_yaml",
56+
path="../.tmuxp.yaml",
57+
expect=False,
58+
),
59+
PureNameTestFixture(
60+
test_id="parent_dir",
61+
path="../",
62+
expect=False,
63+
),
64+
PureNameTestFixture(
65+
test_id="absolute_path",
66+
path="/hello/world",
67+
expect=False,
68+
),
69+
PureNameTestFixture(
70+
test_id="home_tmuxp_path",
71+
path="~/.tmuxp/hey",
72+
expect=False,
73+
),
74+
PureNameTestFixture(
75+
test_id="home_work_path",
76+
path="~/work/c/tmux/",
77+
expect=False,
78+
),
79+
PureNameTestFixture(
80+
test_id="home_work_tmuxp_yaml",
81+
path="~/work/c/tmux/.tmuxp.yaml",
82+
expect=False,
83+
),
84+
PureNameTestFixture(
85+
test_id="pure_name",
86+
path="myproject",
87+
expect=True,
88+
),
89+
]
90+
91+
2592
def test_in_dir_from_config_dir(tmp_path: pathlib.Path) -> None:
2693
"""config.in_dir() finds configs config dir."""
2794
cli.startup(tmp_path)
@@ -64,22 +131,15 @@ def test_get_configs_cwd(
64131

65132

66133
@pytest.mark.parametrize(
67-
("path", "expect"),
68-
[
69-
(".", False),
70-
("./", False),
71-
("", False),
72-
(".tmuxp.yaml", False),
73-
("../.tmuxp.yaml", False),
74-
("../", False),
75-
("/hello/world", False),
76-
("~/.tmuxp/hey", False),
77-
("~/work/c/tmux/", False),
78-
("~/work/c/tmux/.tmuxp.yaml", False),
79-
("myproject", True),
80-
],
134+
list(PureNameTestFixture._fields),
135+
PURE_NAME_TEST_FIXTURES,
136+
ids=[test.test_id for test in PURE_NAME_TEST_FIXTURES],
81137
)
82-
def test_is_pure_name(path: str, expect: bool) -> None:
138+
def test_is_pure_name(
139+
test_id: str,
140+
path: str,
141+
expect: bool,
142+
) -> None:
83143
"""Test is_pure_name() is truthy when file, not directory or config alias."""
84144
assert is_pure_name(path) == expect
85145

0 commit comments

Comments
 (0)