Skip to content

Commit 42449cb

Browse files
committed
tests(pytest plugin) Test git_remote_repo_single_commit_post_init()
1 parent 9e97123 commit 42449cb

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

tests/test_pytest_plugin.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,104 @@ def test_repo_git_remote_repo_and_sync(
112112
result.assert_outcomes(passed=1)
113113

114114

115+
def test_git_remote_repo(
116+
pytester: pytest.Pytester,
117+
monkeypatch: pytest.MonkeyPatch,
118+
tmp_path: pathlib.Path,
119+
) -> None:
120+
"""Tests for libvcs pytest plugin git configuration."""
121+
monkeypatch.setenv("HOME", str(tmp_path))
122+
123+
# Initialize variables
124+
pytester.plugins = ["pytest_plugin"]
125+
pytester.makefile(
126+
".ini",
127+
pytest=textwrap.dedent(
128+
"""
129+
[pytest]
130+
addopts=-vv
131+
""".strip(),
132+
),
133+
)
134+
pytester.makeconftest(
135+
textwrap.dedent(
136+
r"""
137+
import pathlib
138+
import pytest
139+
140+
@pytest.fixture(scope="session")
141+
def vcs_email() -> str:
142+
143+
144+
@pytest.fixture(autouse=True)
145+
def setup(
146+
request: pytest.FixtureRequest,
147+
gitconfig: pathlib.Path,
148+
set_home: pathlib.Path,
149+
) -> None:
150+
pass
151+
""",
152+
),
153+
)
154+
tests_path = pytester.path / "tests"
155+
files = {
156+
"example.py": textwrap.dedent(
157+
"""
158+
import pathlib
159+
160+
from libvcs.sync.git import GitSync
161+
from libvcs.pytest_plugin import (
162+
CreateRepoPytestFixtureFn,
163+
git_remote_repo_single_commit_post_init
164+
)
165+
166+
def test_git_bare_repo_sync_and_commit(
167+
create_git_remote_bare_repo: CreateRepoPytestFixtureFn,
168+
tmp_path: pathlib.Path,
169+
projects_path: pathlib.Path,
170+
) -> None:
171+
git_server = create_git_remote_bare_repo()
172+
git_repo_checkout_dir = projects_path / "my_git_checkout"
173+
git_repo = GitSync(path=str(git_repo_checkout_dir), url=f"file://{git_server!s}")
174+
175+
git_repo.obtain()
176+
git_repo.update_repo()
177+
178+
assert git_repo.get_revision() == "initial"
179+
180+
assert git_repo_checkout_dir.exists()
181+
assert pathlib.Path(git_repo_checkout_dir / ".git").exists()
182+
183+
git_remote_repo_single_commit_post_init(
184+
remote_repo_path=git_repo_checkout_dir
185+
)
186+
187+
assert git_repo.get_revision() != "initial"
188+
189+
last_committer_email = git_repo.cmd.run(["log", "-1", "--pretty=format:%ae"])
190+
191+
assert last_committer_email == "[email protected]", (
192+
'Email should use the override from the "vcs_email" fixture'
193+
)
194+
""",
195+
),
196+
}
197+
first_test_key = next(iter(files.keys()))
198+
first_test_filename = str(tests_path / first_test_key)
199+
200+
tests_path.mkdir()
201+
for file_name, text in files.items():
202+
test_file = tests_path / file_name
203+
test_file.write_text(
204+
text,
205+
encoding="utf-8",
206+
)
207+
208+
# Test
209+
result = pytester.runpytest(str(first_test_filename))
210+
result.assert_outcomes(passed=1)
211+
212+
115213
def test_gitconfig(
116214
gitconfig: pathlib.Path,
117215
set_gitconfig: pathlib.Path,

0 commit comments

Comments
 (0)