Skip to content

Commit 9f44bf3

Browse files
committed
session/test_env_select: Reverse-engineer CliEnv and add tests for it
Some of the behaviour here, such as treatment of zero-length environment names specified by the user, is not really intentional, but apparently an artifact of the method used to parse the environment name list supplied by the user.
1 parent 5466cce commit 9f44bf3

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/session/test_env_select.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,41 @@
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+
(None, (), False, True ),
22+
("", (), False, True ),
23+
("a1", ("a1",), False, False ),
24+
("a1,b2,c3", ("a1", "b2", "c3"), False, False ),
25+
# If the user gives "ALL" as any envname, this becomes an "is_all" and other envnames are ignored.
26+
("ALL", (), True, False ),
27+
("a1,ALL,b2", (), True, False ),
28+
# Zero-length envnames are ignored as being not present. This is not intentional.
29+
(",,a1,,,b2,,", ("a1", "b2"), False, False ),
30+
(",,", (), False, True ),
31+
# Environment names with "invalid" characters are accepted here; the client is expected to deal with this.
32+
("\x01.-@\x02,xxx", ("\x01.-@\x02", "xxx"), False, False ),
33+
],
34+
)
35+
def test_clienv(user_input: str, env_names: tuple[str], is_all: bool, is_default: bool) -> None:
36+
ce = CliEnv(user_input)
37+
assert (ce.is_all, ce.is_default_list, tuple(ce)) \
38+
== (is_all, is_default, tuple(env_names))
39+
40+
@pytest.mark.parametrize(
41+
("user_input", "expected"),
42+
[
43+
("", False),
44+
("all", False),
45+
("All", False),
46+
("ALL", True),
47+
("a,ALL,b", True),
48+
],
49+
)
50+
def test_clienv_is_all(user_input: str, expected: bool) -> None:
51+
assert CliEnv(user_input).is_all is expected
52+
53+
1954
def test_env_select_lazily_looks_at_envs() -> None:
2055
state = State(get_options(), [])
2156
env_selector = EnvSelector(state)

0 commit comments

Comments
 (0)