summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2026-04-03 22:33:52 -0400
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2026-04-06 11:15:14 -0700
commit3d819e8e3ec49a2f44274aed8aa7eb4736df9b5f (patch)
tree50b72f8bb0025be7cadde88e5ebab6a20acf698f /tests
parent573983948ae0550b0f655ea81431bb08ce0bd540 (diff)
downloadgit-repo-3d819e8e3ec49a2f44274aed8aa7eb4736df9b5f.tar.gz
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 <vapier@google.com> Commit-Queue: Mike Frysinger <vapier@google.com> Reviewed-by: Gavin Mak <gavinmak@google.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test_color.py10
-rw-r--r--tests/test_git_config.py11
-rw-r--r--tests/test_wrapper.py5
-rw-r--r--tests/utils_for_test.py5
4 files changed, 10 insertions, 21 deletions
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 @@
14 14
15"""Unittests for the color.py module.""" 15"""Unittests for the color.py module."""
16 16
17import os
18
19import pytest 17import pytest
18import utils_for_test
20 19
21import color 20import color
22import git_config 21import git_config
23 22
24 23
25def fixture(*paths: str) -> str:
26 """Return a path relative to test/fixtures."""
27 return os.path.join(os.path.dirname(__file__), "fixtures", *paths)
28
29
30@pytest.fixture 24@pytest.fixture
31def coloring() -> color.Coloring: 25def coloring() -> color.Coloring:
32 """Create a Coloring object for testing.""" 26 """Create a Coloring object for testing."""
33 config_fixture = fixture("test.gitconfig") 27 config_fixture = utils_for_test.FIXTURES_DIR / "test.gitconfig"
34 config = git_config.GitConfig(config_fixture) 28 config = git_config.GitConfig(config_fixture)
35 color.SetDefaultColoring("true") 29 color.SetDefaultColoring("true")
36 return color.Coloring(config, "status") 30 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 @@
14 14
15"""Unittests for the git_config.py module.""" 15"""Unittests for the git_config.py module."""
16 16
17import os
18from pathlib import Path 17from pathlib import Path
19from typing import Any 18from typing import Any
20 19
21import pytest 20import pytest
21import utils_for_test
22 22
23import git_config 23import git_config
24 24
25 25
26def fixture_path(*paths: str) -> str:
27 """Return a path relative to test/fixtures."""
28 return os.path.join(os.path.dirname(__file__), "fixtures", *paths)
29
30
31@pytest.fixture 26@pytest.fixture
32def readonly_config() -> git_config.GitConfig: 27def readonly_config() -> git_config.GitConfig:
33 """Create a GitConfig object using the test.gitconfig fixture.""" 28 """Create a GitConfig object using the test.gitconfig fixture."""
34 config_fixture = fixture_path("test.gitconfig") 29 config_fixture = utils_for_test.FIXTURES_DIR / "test.gitconfig"
35 return git_config.GitConfig(config_fixture) 30 return git_config.GitConfig(config_fixture)
36 31
37 32
@@ -63,7 +58,7 @@ def test_get_string_with_true_value(
63 58
64def test_get_string_from_missing_file() -> None: 59def test_get_string_from_missing_file() -> None:
65 """Test missing config file.""" 60 """Test missing config file."""
66 config_fixture = fixture_path("not.present.gitconfig") 61 config_fixture = utils_for_test.FIXTURES_DIR / "not.present.gitconfig"
67 config = git_config.GitConfig(config_fixture) 62 config = git_config.GitConfig(config_fixture)
68 val = config.GetString("empty") 63 val = config.GetString("empty")
69 assert val is None 64 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
29import wrapper 29import wrapper
30 30
31 31
32def fixture(*paths):
33 """Return a path relative to tests/fixtures."""
34 return os.path.join(os.path.dirname(__file__), "fixtures", *paths)
35
36
37class RepoWrapperTestCase(unittest.TestCase): 32class RepoWrapperTestCase(unittest.TestCase):
38 """TestCase for the wrapper module.""" 33 """TestCase for the wrapper module."""
39 34
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
27import git_command 27import git_command
28 28
29 29
30THIS_FILE = Path(__file__).resolve()
31THIS_DIR = THIS_FILE.parent
32FIXTURES_DIR = THIS_DIR / "fixtures"
33
34
30def init_git_tree( 35def init_git_tree(
31 path: Union[str, Path], 36 path: Union[str, Path],
32 ref_format: Optional[str] = None, 37 ref_format: Optional[str] = None,