mirror of
https://gerrit.googlesource.com/git-repo
synced 2026-05-30 22:49:48 +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:
+1
-1
@@ -111,7 +111,7 @@ class GitConfig:
|
|||||||
return cls(configfile=os.path.join(gitdir, "config"), defaults=defaults)
|
return cls(configfile=os.path.join(gitdir, "config"), defaults=defaults)
|
||||||
|
|
||||||
def __init__(self, configfile, defaults=None, jsonFile=None):
|
def __init__(self, configfile, defaults=None, jsonFile=None):
|
||||||
self.file = configfile
|
self.file = str(configfile)
|
||||||
self.defaults = defaults
|
self.defaults = defaults
|
||||||
self._cache_dict = None
|
self._cache_dict = None
|
||||||
self._section_dict = None
|
self._section_dict = None
|
||||||
|
|||||||
+2
-8
@@ -14,23 +14,17 @@
|
|||||||
|
|
||||||
"""Unittests for the color.py module."""
|
"""Unittests for the color.py module."""
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
import utils_for_test
|
||||||
|
|
||||||
import color
|
import color
|
||||||
import git_config
|
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
|
@pytest.fixture
|
||||||
def coloring() -> color.Coloring:
|
def coloring() -> color.Coloring:
|
||||||
"""Create a Coloring object for testing."""
|
"""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)
|
config = git_config.GitConfig(config_fixture)
|
||||||
color.SetDefaultColoring("true")
|
color.SetDefaultColoring("true")
|
||||||
return color.Coloring(config, "status")
|
return color.Coloring(config, "status")
|
||||||
|
|||||||
@@ -14,24 +14,19 @@
|
|||||||
|
|
||||||
"""Unittests for the git_config.py module."""
|
"""Unittests for the git_config.py module."""
|
||||||
|
|
||||||
import os
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
import utils_for_test
|
||||||
|
|
||||||
import git_config
|
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
|
@pytest.fixture
|
||||||
def readonly_config() -> git_config.GitConfig:
|
def readonly_config() -> git_config.GitConfig:
|
||||||
"""Create a GitConfig object using the test.gitconfig fixture."""
|
"""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)
|
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:
|
def test_get_string_from_missing_file() -> None:
|
||||||
"""Test missing config file."""
|
"""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)
|
config = git_config.GitConfig(config_fixture)
|
||||||
val = config.GetString("empty")
|
val = config.GetString("empty")
|
||||||
assert val is None
|
assert val is None
|
||||||
|
|||||||
@@ -29,11 +29,6 @@ import main
|
|||||||
import wrapper
|
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):
|
class RepoWrapperTestCase(unittest.TestCase):
|
||||||
"""TestCase for the wrapper module."""
|
"""TestCase for the wrapper module."""
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ from typing import Optional, Union
|
|||||||
import git_command
|
import git_command
|
||||||
|
|
||||||
|
|
||||||
|
THIS_FILE = Path(__file__).resolve()
|
||||||
|
THIS_DIR = THIS_FILE.parent
|
||||||
|
FIXTURES_DIR = THIS_DIR / "fixtures"
|
||||||
|
|
||||||
|
|
||||||
def init_git_tree(
|
def init_git_tree(
|
||||||
path: Union[str, Path],
|
path: Union[str, Path],
|
||||||
ref_format: Optional[str] = None,
|
ref_format: Optional[str] = None,
|
||||||
|
|||||||
Reference in New Issue
Block a user