mirror of
https://gerrit.googlesource.com/git-repo
synced 2026-05-07 11:29:27 +00:00
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>
This commit is contained in:
+2
-8
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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."""
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user