Skip to content

Commit

Permalink
Make HIDE_* attributes always bool
Browse files Browse the repository at this point in the history
For now, this doesn't change how the correspondng environment
variables are interpreted, in terms of truth and falsehood.
But it does *convert* them to bool, so that the values of the
HIDE_WINDOWS_KNOWN_ERRORS and HIDE_WINDOWS_FREEZE_ERRORS
attributes are always bools.

It also updates the tests accordingly, to validate this behavior.
  • Loading branch information
EliahKagan committed Oct 9, 2023
1 parent 7604da1 commit eb51277
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions git/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
log = logging.getLogger(__name__)


def _read_env_flag(name: str, default: bool) -> Union[bool, str]:
def _read_env_flag(name: str, default: bool) -> bool:
try:
value = os.environ[name]
except KeyError:
Expand All @@ -121,9 +121,8 @@ def _read_env_flag(name: str, default: bool) -> Union[bool, str]:
name,
)

# FIXME: This should always return bool, as that is how it is used.
# FIXME: This should treat some values besides "" as expressing falsehood.
return value
return bool(value)


#: We need an easy way to see if Appveyor TCs start failing,
Expand Down
6 changes: 3 additions & 3 deletions test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ def run_parse(value):
)
return ast.literal_eval(output)

assert_true_iff_win = self.assertTrue if os.name == "nt" else self.assertFalse
true_iff_win = os.name == "nt" # Same as is_win, but don't depend on that here.

truthy_cases = [
("unset", None),
Expand All @@ -542,8 +542,8 @@ def run_parse(value):

for msg, env_var_value in truthy_cases:
with self.subTest(msg, env_var_value=env_var_value):
assert_true_iff_win(run_parse(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.assertFalse(run_parse(env_var_value))
self.assertIs(run_parse(env_var_value), False)

0 comments on commit eb51277

Please sign in to comment.