Skip to content
Prev Previous commit
Next Next commit
Pull HIDE_WINDOWS_*_ERRORS tests out of TestUtils
And make them pure pytest tests. This creates the TestEnvParsing
class, which does not inherit from TestCase.

Because unlike @ddt.data (and @ddt.idata) @pytest.mark.parametrize
can be nested (applied multiple times, creating tests for all
combinations), that is used for the HIDE_WINDOWS_*_ERRORS tests
instead of subtests. Because there were not any other uses of
subtests in the test suite, the pytest-subtest plugin is
accordingly removed from test-requirements. It may be put back
anytime in the future.
  • Loading branch information
EliahKagan committed Nov 3, 2023
commit c4da058ba99aafd16a01b0692b13bafb833969ac
1 change: 0 additions & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ pytest >= 7.3.1
pytest-cov
pytest-instafail
pytest-mock
pytest-subtests
pytest-sugar
82 changes: 48 additions & 34 deletions test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,38 +155,26 @@ def test_does_not_wrap_other_errors(self, mocker, file_not_found_tmpdir, hide_wi
self.fail(f"rmtree unexpectedly attempts skip: {ex!r}")


class _Member:
"""A member of an IterableList."""

__slots__ = ("name",)

def __init__(self, name):
self.name = name

def __repr__(self):
return f"{type(self).__name__}({self.name!r})"

class TestEnvParsing:
"""Tests for environment variable parsing logic in :mod:`git.util`."""

@staticmethod
def _run_parse(name, 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)

@ddt.ddt
class TestUtils(TestBase):
"""Tests for utilities in :mod:`git.util` other than :func:`git.util.rmtree`."""

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

for env_var_value, expected_truth_value in (
@pytest.mark.parametrize(
"env_var_value, expected_truth_value",
[
(None, os.name == "nt"), # True on Windows when the environment variable is unset.
("", False),
(" ", False),
Expand All @@ -202,9 +190,35 @@ def run_parse(value):
("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)
],
)
@pytest.mark.parametrize(
"name",
[
"HIDE_WINDOWS_KNOWN_ERRORS",
"HIDE_WINDOWS_FREEZE_ERRORS",
],
)
def test_env_vars_for_windows_tests(self, name, env_var_value, expected_truth_value):
actual_parsed_value = self._run_parse(name, env_var_value)
assert actual_parsed_value is expected_truth_value


class _Member:
"""A member of an IterableList."""

__slots__ = ("name",)

def __init__(self, name):
self.name = name

def __repr__(self):
return f"{type(self).__name__}({self.name!r})"


@ddt.ddt
class TestUtils(TestBase):
"""Tests for most utilities in :mod:`git.util`."""

_norm_cygpath_pairs = (
(R"foo\bar", "foo/bar"),
Expand Down