Skip to content

Commit 24e099e

Browse files
committed
tests(pytest plugin) Test git_remote_repo_single_commit_post_init()
1 parent cfcb1b4 commit 24e099e

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

tests/test_pytest_plugin.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,94 @@ def test_repo_git_remote_checkout(
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 at large."""
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(autouse=True)
141+
def setup(
142+
request: pytest.FixtureRequest,
143+
gitconfig: pathlib.Path,
144+
set_home: pathlib.Path,
145+
) -> None:
146+
pass
147+
""",
148+
),
149+
)
150+
tests_path = pytester.path / "tests"
151+
files = {
152+
"example.py": textwrap.dedent(
153+
"""
154+
import pathlib
155+
156+
from libvcs.sync.git import GitSync
157+
from libvcs.pytest_plugin import (
158+
CreateRepoPytestFixtureFn,
159+
git_remote_repo_single_commit_post_init
160+
)
161+
162+
def test_git_bare_repo_sync_and_commit(
163+
create_git_remote_bare_repo: CreateRepoPytestFixtureFn,
164+
tmp_path: pathlib.Path,
165+
projects_path: pathlib.Path,
166+
) -> None:
167+
git_server = create_git_remote_bare_repo()
168+
git_repo_checkout_dir = projects_path / "my_git_checkout"
169+
git_repo = GitSync(path=str(git_repo_checkout_dir), url=f"file://{git_server!s}")
170+
171+
git_repo.obtain()
172+
git_repo.update_repo()
173+
174+
assert git_repo.get_revision() == "initial"
175+
176+
assert git_repo_checkout_dir.exists()
177+
assert pathlib.Path(git_repo_checkout_dir / ".git").exists()
178+
179+
git_remote_repo_single_commit_post_init(
180+
remote_repo_path=git_repo_checkout_dir
181+
)
182+
183+
assert git_repo.get_revision() != "initial"
184+
""",
185+
),
186+
}
187+
first_test_key = next(iter(files.keys()))
188+
first_test_filename = str(tests_path / first_test_key)
189+
190+
tests_path.mkdir()
191+
for file_name, text in files.items():
192+
test_file = tests_path / file_name
193+
test_file.write_text(
194+
text,
195+
encoding="utf-8",
196+
)
197+
198+
# Test
199+
result = pytester.runpytest(str(first_test_filename))
200+
result.assert_outcomes(passed=1)
201+
202+
115203
def test_gitconfig(
116204
gitconfig: pathlib.Path,
117205
set_gitconfig: pathlib.Path,

0 commit comments

Comments
 (0)