Skip to content

Commit 485141a

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 a9a3117 commit 485141a

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
@@ -19,6 +19,41 @@
1919
# Tests directly on env_select functionality.
2020

2121

22+
@pytest.mark.parametrize(
23+
("userinput", "envnames", "isall", "isdefault" ), [
24+
(None, (), False, True ),
25+
("", (), False, True ),
26+
("a1", ("a1",), False, False ),
27+
("a1,b2,c3", ("a1", "b2", "c3"), False, False ),
28+
# If the user gives "ALL" as any envname, this becomes an "is_all" and other envnames are ignored.
29+
("ALL", (), True, False ),
30+
("a1,ALL,b2", (), True, False ),
31+
# Zero-length envnames are ignored as being not present. This is not intentional.
32+
(",,a1,,,b2,,", ("a1", "b2"), False, False ),
33+
(",,", (), False, True ),
34+
# Environment names with "invalid" characters are accepted here; the client is expected to deal with this.
35+
("\x01.-@\x02,xxx", ("\x01.-@\x02", "xxx"), False, False ),
36+
],
37+
)
38+
def test_clienv(userinput: str, envnames: tuple[str], isall: bool, isdefault: bool) -> None:
39+
c = CliEnv(userinput)
40+
assert (c.is_all, c.is_default_list, tuple(c)) \
41+
== (isall, isdefault, tuple(envnames))
42+
43+
@pytest.mark.parametrize(
44+
("userinput", "expected"),
45+
[
46+
("", False),
47+
("all", False),
48+
("All", False),
49+
("ALL", True),
50+
("a,ALL,b", True),
51+
],
52+
)
53+
def test_clienv_is_all(userinput: str, expected: bool) -> None:
54+
assert CliEnv(userinput).is_all is expected
55+
56+
2257
def test_env_select_lazily_looks_at_envs() -> None:
2358
state = State(get_options(), [])
2459
env_selector = EnvSelector(state)

0 commit comments

Comments
 (0)