-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose git_repo and hg_repo as fixtures and add commit_tree method.
- Loading branch information
Showing
6 changed files
with
76 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,36 @@ | ||
import pathlib | ||
|
||
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(mgr): | ||
try: | ||
mgr.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="", | ||
), | ||
) | ||
|
||
|
||
source_tree = dict( | ||
rev2 = dict( | ||
bar=dict( | ||
baz="", | ||
baz="content", | ||
), | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def hg_repo(temp_work_dir): | ||
repo = vcs.Mercurial() | ||
_ensure_present(repo) | ||
repo._invoke('init', '.') | ||
jaraco.path.build(source_tree) | ||
repo._invoke('addremove') | ||
repo._invoke('ci', '-m', 'committed') | ||
pathlib.Path('bar/baz').write_text('content', encoding='utf-8') | ||
repo._invoke('ci', '-m', 'added content') | ||
def hg_repo(hg_repo): | ||
repo = hg_repo | ||
repo.commit_tree(rev1, 'committed') | ||
repo.commit_tree(rev2, 'added content') | ||
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') | ||
jaraco.path.build(source_tree) | ||
repo._invoke('add', '.') | ||
repo._invoke('commit', '-m', 'committed') | ||
pathlib.Path('bar/baz').write_text('content', encoding='utf-8') | ||
repo._invoke('commit', '-am', 'added content') | ||
def git_repo(git_repo): | ||
repo = git_repo | ||
repo.commit_tree(rev1, 'committed') | ||
repo.commit_tree(rev2, 'added content') | ||
return repo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', 'vip@example.com') | ||
repo._invoke('config', 'user.name', 'Important User') | ||
return repo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Presented hg_repo and git_repo as fixtures. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters