From 1d11098a200e163756287feac4f2f52df6ba1cb3 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 6 Aug 2024 14:50:00 -0400 Subject: [PATCH] Presented hg_repo and git_repo as fixtures. Closes #36 --- conftest.py | 28 ++++------------------------ jaraco/vcs/fixtures.py | 34 ++++++++++++++++++++++++++++++++++ newsfragments/36.feature.rst | 1 + pyproject.toml | 3 +++ 4 files changed, 42 insertions(+), 24 deletions(-) create mode 100644 jaraco/vcs/fixtures.py create mode 100644 newsfragments/36.feature.rst diff --git a/conftest.py b/conftest.py index 6295d88..3e2008c 100644 --- a/conftest.py +++ b/conftest.py @@ -1,7 +1,6 @@ import pytest import jaraco.path -from jaraco import vcs @pytest.fixture(autouse=True) @@ -9,19 +8,6 @@ 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="", @@ -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') @@ -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', 'vip@example.com') - 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') diff --git a/jaraco/vcs/fixtures.py b/jaraco/vcs/fixtures.py new file mode 100644 index 0000000..f24479e --- /dev/null +++ b/jaraco/vcs/fixtures.py @@ -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', 'vip@example.com') + repo._invoke('config', 'user.name', 'Important User') + return repo diff --git a/newsfragments/36.feature.rst b/newsfragments/36.feature.rst new file mode 100644 index 0000000..278cf0e --- /dev/null +++ b/newsfragments/36.feature.rst @@ -0,0 +1 @@ +Presented hg_repo and git_repo as fixtures. diff --git a/pyproject.toml b/pyproject.toml index 882e1d5..c93c2e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,3 +59,6 @@ doc = [ ] [tool.setuptools_scm] + +[project.entry-points] +pytest11 = {"jaraco.vcs.fixtures" = "jaraco.vcs.fixtures"}