Skip to content

Commit

Permalink
Simplify HIDE_* env var test; add missing cases
Browse files Browse the repository at this point in the history
Now that the expected truth values are intuitive, it is no longer
necessary to group them by result and include messages that
acknowldge the unintuitive cases. This reorders them so that pairs
(like "yes" and "no") appear together, removes the messages that
are no longer necessary, and reduces test code duplication.

This also adds cases to test leading/trailing whitespace in
otherwise nonempty strings, so it is clearer what the test is
asserting overall, and so a bug where lstrip or rstrip (or
equivalent with a regex) were used instead strip would be caught.
  • Loading branch information
EliahKagan committed Oct 7, 2023
1 parent f0e38f8 commit 3929062
Showing 1 changed file with 19 additions and 27 deletions.
46 changes: 19 additions & 27 deletions test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,30 +435,22 @@ def run_parse(value):
)
return ast.literal_eval(output)

true_iff_win = os.name == "nt" # Same as is_win, but don't depend on that here.

truthy_cases = [
("unset", None),
("true-seeming", "1"),
("true-seeming", "true"),
("true-seeming", "True"),
("true-seeming", "yes"),
("true-seeming", "YES"),
]
falsy_cases = [
("empty", ""),
("whitespace", " "),
("false-seeming", "0"),
("false-seeming", "false"),
("false-seeming", "False"),
("false-seeming", "no"),
("false-seeming", "NO"),
]

for msg, env_var_value in truthy_cases:
with self.subTest(msg, env_var_value=env_var_value):
self.assertIs(run_parse(env_var_value), true_iff_win)

for msg, env_var_value in falsy_cases:
with self.subTest(msg, env_var_value=env_var_value):
self.assertIs(run_parse(env_var_value), False)
for env_var_value, expected_truth_value in (
(None, os.name == "nt"), # True on Windows when the environment variable is unset.
("", False),
(" ", False),
("0", False),
("1", os.name == "nt"),
("false", False),
("true", os.name == "nt"),
("False", False),
("True", os.name == "nt"),
("no", False),
("yes", os.name == "nt"),
("NO", False),
("YES", os.name == "nt"),
(" no ", False),
(" yes ", os.name == "nt"),
):
with self.subTest(env_var_value=env_var_value):
self.assertIs(run_parse(env_var_value), expected_truth_value)

0 comments on commit 3929062

Please sign in to comment.