diff options
| author | Mike Frysinger <vapier@google.com> | 2026-04-03 22:33:52 -0400 |
|---|---|---|
| committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2026-04-06 11:15:14 -0700 |
| commit | 3d819e8e3ec49a2f44274aed8aa7eb4736df9b5f (patch) | |
| tree | 50b72f8bb0025be7cadde88e5ebab6a20acf698f /tests | |
| parent | 573983948ae0550b0f655ea81431bb08ce0bd540 (diff) | |
| download | git-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.py | 10 | ||||
| -rw-r--r-- | tests/test_git_config.py | 11 | ||||
| -rw-r--r-- | tests/test_wrapper.py | 5 | ||||
| -rw-r--r-- | tests/utils_for_test.py | 5 |
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 | ||
| 17 | import os | ||
| 18 | |||
| 19 | import pytest | 17 | import pytest |
| 18 | import utils_for_test | ||
| 20 | 19 | ||
| 21 | import color | 20 | import color |
| 22 | import git_config | 21 | import git_config |
| 23 | 22 | ||
| 24 | 23 | ||
| 25 | def 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 |
| 31 | def coloring() -> color.Coloring: | 25 | def 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 | ||
| 17 | import os | ||
| 18 | from pathlib import Path | 17 | from pathlib import Path |
| 19 | from typing import Any | 18 | from typing import Any |
| 20 | 19 | ||
| 21 | import pytest | 20 | import pytest |
| 21 | import utils_for_test | ||
| 22 | 22 | ||
| 23 | import git_config | 23 | import git_config |
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | def 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 |
| 32 | def readonly_config() -> git_config.GitConfig: | 27 | def 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 | ||
| 64 | def test_get_string_from_missing_file() -> None: | 59 | def 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 | |||
| 29 | import wrapper | 29 | import wrapper |
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | def fixture(*paths): | ||
| 33 | """Return a path relative to tests/fixtures.""" | ||
| 34 | return os.path.join(os.path.dirname(__file__), "fixtures", *paths) | ||
| 35 | |||
| 36 | |||
| 37 | class RepoWrapperTestCase(unittest.TestCase): | 32 | class 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 | |||
| 27 | import git_command | 27 | import git_command |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | THIS_FILE = Path(__file__).resolve() | ||
| 31 | THIS_DIR = THIS_FILE.parent | ||
| 32 | FIXTURES_DIR = THIS_DIR / "fixtures" | ||
| 33 | |||
| 34 | |||
| 30 | def init_git_tree( | 35 | def 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, |
