From 3d819e8e3ec49a2f44274aed8aa7eb4736df9b5f Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Fri, 3 Apr 2026 22:33:52 -0400 Subject: [PATCH] tests: unify fixture() helper with Path constant Change-Id: I63751042391f5cc3e06af7067bc83d67bd0716dc Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/569441 Tested-by: Mike Frysinger Commit-Queue: Mike Frysinger Reviewed-by: Gavin Mak --- git_config.py | 2 +- tests/test_color.py | 10 ++-------- tests/test_git_config.py | 11 +++-------- tests/test_wrapper.py | 5 ----- tests/utils_for_test.py | 5 +++++ 5 files changed, 11 insertions(+), 22 deletions(-) diff --git a/git_config.py b/git_config.py index c58edab32..e80a0322d 100644 --- a/git_config.py +++ b/git_config.py @@ -111,7 +111,7 @@ class GitConfig: return cls(configfile=os.path.join(gitdir, "config"), defaults=defaults) def __init__(self, configfile, defaults=None, jsonFile=None): - self.file = configfile + self.file = str(configfile) self.defaults = defaults self._cache_dict = None self._section_dict = None diff --git a/tests/test_color.py b/tests/test_color.py index 923f7e355..8b75d2199 100644 --- a/tests/test_color.py +++ b/tests/test_color.py @@ -14,23 +14,17 @@ """Unittests for the color.py module.""" -import os - import pytest +import utils_for_test import color import git_config -def fixture(*paths: str) -> str: - """Return a path relative to test/fixtures.""" - return os.path.join(os.path.dirname(__file__), "fixtures", *paths) - - @pytest.fixture def coloring() -> color.Coloring: """Create a Coloring object for testing.""" - config_fixture = fixture("test.gitconfig") + config_fixture = utils_for_test.FIXTURES_DIR / "test.gitconfig" config = git_config.GitConfig(config_fixture) color.SetDefaultColoring("true") return color.Coloring(config, "status") diff --git a/tests/test_git_config.py b/tests/test_git_config.py index 496d97141..2ece4c6e3 100644 --- a/tests/test_git_config.py +++ b/tests/test_git_config.py @@ -14,24 +14,19 @@ """Unittests for the git_config.py module.""" -import os from pathlib import Path from typing import Any import pytest +import utils_for_test import git_config -def fixture_path(*paths: str) -> str: - """Return a path relative to test/fixtures.""" - return os.path.join(os.path.dirname(__file__), "fixtures", *paths) - - @pytest.fixture def readonly_config() -> git_config.GitConfig: """Create a GitConfig object using the test.gitconfig fixture.""" - config_fixture = fixture_path("test.gitconfig") + config_fixture = utils_for_test.FIXTURES_DIR / "test.gitconfig" return git_config.GitConfig(config_fixture) @@ -63,7 +58,7 @@ def test_get_string_with_true_value( def test_get_string_from_missing_file() -> None: """Test missing config file.""" - config_fixture = fixture_path("not.present.gitconfig") + config_fixture = utils_for_test.FIXTURES_DIR / "not.present.gitconfig" config = git_config.GitConfig(config_fixture) val = config.GetString("empty") assert val is None diff --git a/tests/test_wrapper.py b/tests/test_wrapper.py index 36465e737..89d8b2385 100644 --- a/tests/test_wrapper.py +++ b/tests/test_wrapper.py @@ -29,11 +29,6 @@ import main import wrapper -def fixture(*paths): - """Return a path relative to tests/fixtures.""" - return os.path.join(os.path.dirname(__file__), "fixtures", *paths) - - class RepoWrapperTestCase(unittest.TestCase): """TestCase for the wrapper module.""" diff --git a/tests/utils_for_test.py b/tests/utils_for_test.py index f48613f34..3f1bed486 100644 --- a/tests/utils_for_test.py +++ b/tests/utils_for_test.py @@ -27,6 +27,11 @@ from typing import Optional, Union import git_command +THIS_FILE = Path(__file__).resolve() +THIS_DIR = THIS_FILE.parent +FIXTURES_DIR = THIS_DIR / "fixtures" + + def init_git_tree( path: Union[str, Path], ref_format: Optional[str] = None,