From c2b5b2a787e2a495b45201122619bb0d2cc1a1ce Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sat, 7 Oct 2023 15:31:25 -0400 Subject: [PATCH] Add initial test_env_vars_for_windows_tests 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 muliple failures from the subtests can be seen in the same test run. --- test-requirements.txt | 1 + test/test_util.py | 45 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/test-requirements.txt b/test-requirements.txt index 9414da09c..a69181be1 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -7,4 +7,5 @@ pre-commit pytest pytest-cov pytest-instafail +pytest-subtests pytest-sugar diff --git a/test/test_util.py b/test/test_util.py index 2b1e518ed..8b789036e 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -4,8 +4,10 @@ # This module is part of GitPython and is released under # the BSD License: https://opensource.org/license/bsd-3-clause/ +import ast import os import pickle +import subprocess import sys import tempfile import time @@ -417,3 +419,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))