Skip to content

Commit b3eb86a

Browse files
authored
Add tests for CliEnv (#3204)
1 parent 5ec42c6 commit b3eb86a

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

tests/session/test_env_select.py

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,50 @@
1616
CURRENT_PY_ENV = f"py{sys.version_info[0]}{sys.version_info[1]}" # e.g. py310
1717

1818

19+
@pytest.mark.parametrize(
20+
("user_input", "env_names", "is_all", "is_default"),
21+
[
22+
(None, (), False, True),
23+
("", (), False, True),
24+
("a1", ("a1",), False, False),
25+
("a1,b2,c3", ("a1", "b2", "c3"), False, False),
26+
# If the user gives "ALL" as any envname, this becomes an "is_all" and other envnames are ignored.
27+
("ALL", (), True, False),
28+
("a1,ALL,b2", (), True, False),
29+
# Zero-length envnames are ignored as being not present. This is not intentional.
30+
(",,a1,,,b2,,", ("a1", "b2"), False, False),
31+
(",,", (), False, True),
32+
# Environment names with "invalid" characters are accepted here; the client is expected to deal with this.
33+
("\x01.-@\x02,xxx", ("\x01.-@\x02", "xxx"), False, False),
34+
],
35+
)
36+
def test_clienv(user_input: str, env_names: tuple[str], is_all: bool, is_default: bool) -> None:
37+
ce = CliEnv(user_input)
38+
assert (ce.is_all, ce.is_default_list, tuple(ce)) == (is_all, is_default, tuple(env_names))
39+
40+
41+
@pytest.mark.parametrize(
42+
("user_input", "expected"),
43+
[
44+
("", False),
45+
("all", False),
46+
("All", False),
47+
("ALL", True),
48+
("a,ALL,b", True),
49+
],
50+
)
51+
def test_clienv_is_all(user_input: str, expected: bool) -> None:
52+
assert CliEnv(user_input).is_all is expected
53+
54+
55+
def test_env_select_lazily_looks_at_envs() -> None:
56+
state = State(get_options(), [])
57+
env_selector = EnvSelector(state)
58+
# late-assigning env should be reflected in env_selector
59+
state.conf.options.env = CliEnv("py")
60+
assert set(env_selector.iter()) == {"py"}
61+
62+
1963
def test_label_core_can_define(tox_project: ToxProjectCreator) -> None:
2064
ini = """
2165
[tox]
@@ -130,14 +174,6 @@ def test_tox_skip_env_logs(tox_project: ToxProjectCreator, monkeypatch: MonkeyPa
130174
outcome.assert_out_err("ROOT: skip environment mypy, matches filter 'm[y]py'\npy310\npy39\n", "")
131175

132176

133-
def test_env_select_lazily_looks_at_envs() -> None:
134-
state = State(get_options(), [])
135-
env_selector = EnvSelector(state)
136-
# late-assigning env should be reflected in env_selector
137-
state.conf.options.env = CliEnv("py")
138-
assert set(env_selector.iter()) == {"py"}
139-
140-
141177
def test_cli_env_can_be_specified_in_default(tox_project: ToxProjectCreator) -> None:
142178
proj = tox_project({"tox.ini": "[tox]\nenv_list=exists"})
143179
outcome = proj.run("r", "-e", "exists")

0 commit comments

Comments
 (0)