Skip to content

Commit

Permalink
Presented hg_repo and git_repo as fixtures.
Browse files Browse the repository at this point in the history
Closes #36
  • Loading branch information
jaraco committed Aug 6, 2024
1 parent 1b3f18b commit 1d11098
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 24 deletions.
28 changes: 4 additions & 24 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
import pytest

import jaraco.path
from jaraco import vcs


@pytest.fixture(autouse=True)
def _isolate_home(tmp_home_dir):
"""Isolate the tests from a developer's VCS config."""


def _ensure_present(repo):
try:
repo.version()
except Exception:
pytest.skip()


@pytest.fixture
def temp_work_dir(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
return tmp_path


rev1 = dict(
bar=dict(
baz="",
Expand All @@ -37,10 +23,8 @@ def temp_work_dir(tmp_path, monkeypatch):


@pytest.fixture
def hg_repo(temp_work_dir):
repo = vcs.Mercurial()
_ensure_present(repo)
repo._invoke('init', '.')
def hg_repo(hg_repo):
repo = hg_repo
jaraco.path.build(rev1)
repo._invoke('addremove')
repo._invoke('ci', '-m', 'committed')
Expand All @@ -50,12 +34,8 @@ def hg_repo(temp_work_dir):


@pytest.fixture
def git_repo(temp_work_dir):
repo = vcs.Git()
_ensure_present(repo)
repo._invoke('init')
repo._invoke('config', 'user.email', '[email protected]')
repo._invoke('config', 'user.name', 'Important User')
def git_repo(git_repo):
repo = git_repo
jaraco.path.build(rev1)
repo._invoke('add', '.')
repo._invoke('commit', '-m', 'committed')
Expand Down
34 changes: 34 additions & 0 deletions jaraco/vcs/fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest

from .. import vcs


def _ensure_present(repo):
try:
repo.version()
except Exception:
pytest.skip()


@pytest.fixture
def temp_work_dir(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
return tmp_path


@pytest.fixture
def hg_repo(temp_work_dir):
repo = vcs.Mercurial()
_ensure_present(repo)
repo._invoke('init', '.')
return repo


@pytest.fixture
def git_repo(temp_work_dir):
repo = vcs.Git()
_ensure_present(repo)
repo._invoke('init')
repo._invoke('config', 'user.email', '[email protected]')
repo._invoke('config', 'user.name', 'Important User')
return repo
1 change: 1 addition & 0 deletions newsfragments/36.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Presented hg_repo and git_repo as fixtures.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ doc = [
]

[tool.setuptools_scm]

[project.entry-points]
pytest11 = {"jaraco.vcs.fixtures" = "jaraco.vcs.fixtures"}

0 comments on commit 1d11098

Please sign in to comment.