Skip to content

Commit

Permalink
Add initial test_env_vars_for_windows_tests
Browse files Browse the repository at this point in the history
The new test method just verifies the current behavior of the
HIDE_WINDOWS_KNOWN_ERRORS and HIDE_WINDOWS_FREEZE_ERRORS
environment variables. This is so there is a test to modify when
changing that behavior. The purpose of these tests is *not* to
claim that the behavior of either variable is something code that
uses GitPython can (or has ever been able to) rely on.

This also adds pytest-subtests as a dependency, so multiple
failures from the subtests can be seen in the same test run.
  • Loading branch information
EliahKagan committed Oct 9, 2023
1 parent 196cfbe commit 100ab98
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ pre-commit
pytest
pytest-cov
pytest-instafail
pytest-subtests
pytest-sugar
45 changes: 45 additions & 0 deletions test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
# This module is part of GitPython and is released under
# the BSD License: https://opensource.org/license/bsd-3-clause/

import ast
import contextlib
from datetime import datetime
import os
import pathlib
import pickle
import stat
import subprocess
import sys
import tempfile
import time
Expand Down Expand Up @@ -502,3 +504,46 @@ def test_remove_password_from_command_line(self):

assert cmd_4 == remove_password_if_present(cmd_4)
assert cmd_5 == remove_password_if_present(cmd_5)

@ddt.data("HIDE_WINDOWS_KNOWN_ERRORS", "HIDE_WINDOWS_FREEZE_ERRORS")
def test_env_vars_for_windows_tests(self, name):
def run_parse(value):
command = [
sys.executable,
"-c",
f"from git.util import {name}; print(repr({name}))",
]
output = subprocess.check_output(
command,
env=None if value is None else dict(os.environ, **{name: value}),
text=True,
)
return ast.literal_eval(output)

assert_true_iff_win = self.assertTrue if os.name == "nt" else self.assertFalse

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

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))

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))

0 comments on commit 100ab98

Please sign in to comment.