Skip to content

Commit 1d87670

Browse files
committed
tests(async_hg): Add AsyncHg command tests
why: Verify AsyncHg functionality. what: - Test run, clone, update, pull methods - 10 test cases
1 parent ac6ffb5 commit 1d87670

1 file changed

Lines changed: 179 additions & 0 deletions

File tree

tests/cmd/_async/test_hg.py

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
"""Tests for libvcs.cmd._async.hg."""
2+
3+
from __future__ import annotations
4+
5+
import typing as t
6+
from pathlib import Path
7+
8+
import pytest
9+
10+
from libvcs.cmd._async.hg import AsyncHg
11+
from libvcs.pytest_plugin import CreateRepoPytestFixtureFn
12+
13+
14+
class RunFixture(t.NamedTuple):
15+
"""Test fixture for AsyncHg.run()."""
16+
17+
test_id: str
18+
args: list[str]
19+
kwargs: dict[str, t.Any]
20+
expected_in_output: str | None
21+
22+
23+
RUN_FIXTURES = [
24+
RunFixture(
25+
test_id="version",
26+
args=["version"],
27+
kwargs={},
28+
expected_in_output="Mercurial",
29+
),
30+
RunFixture(
31+
test_id="help_short",
32+
args=["--help"],
33+
kwargs={},
34+
expected_in_output="Mercurial",
35+
),
36+
]
37+
38+
39+
class TestAsyncHg:
40+
"""Tests for AsyncHg class."""
41+
42+
def test_init(self, tmp_path: Path) -> None:
43+
"""Test AsyncHg initialization."""
44+
hg = AsyncHg(path=tmp_path)
45+
assert hg.path == tmp_path
46+
assert hg.progress_callback is None
47+
48+
def test_repr(self, tmp_path: Path) -> None:
49+
"""Test AsyncHg repr."""
50+
hg = AsyncHg(path=tmp_path)
51+
assert "AsyncHg" in repr(hg)
52+
assert str(tmp_path) in repr(hg)
53+
54+
@pytest.mark.parametrize(
55+
list(RunFixture._fields),
56+
RUN_FIXTURES,
57+
ids=[f.test_id for f in RUN_FIXTURES],
58+
)
59+
@pytest.mark.asyncio
60+
async def test_run(
61+
self,
62+
test_id: str,
63+
args: list[str],
64+
kwargs: dict[str, t.Any],
65+
expected_in_output: str | None,
66+
tmp_path: Path,
67+
) -> None:
68+
"""Test AsyncHg.run() with various commands."""
69+
hg = AsyncHg(path=tmp_path)
70+
output = await hg.run(args, **kwargs)
71+
if expected_in_output is not None:
72+
assert expected_in_output in output
73+
74+
75+
class TestAsyncHgClone:
76+
"""Tests for AsyncHg.clone()."""
77+
78+
@pytest.mark.asyncio
79+
async def test_clone_basic(
80+
self,
81+
tmp_path: Path,
82+
create_hg_remote_repo: CreateRepoPytestFixtureFn,
83+
) -> None:
84+
"""Test basic clone operation."""
85+
remote_repo = create_hg_remote_repo()
86+
repo_path = tmp_path / "cloned_repo"
87+
88+
hg = AsyncHg(path=repo_path)
89+
await hg.clone(url=f"file://{remote_repo}")
90+
91+
assert repo_path.exists()
92+
assert (repo_path / ".hg").exists()
93+
94+
@pytest.mark.asyncio
95+
async def test_clone_quiet(
96+
self,
97+
tmp_path: Path,
98+
create_hg_remote_repo: CreateRepoPytestFixtureFn,
99+
) -> None:
100+
"""Test clone with quiet flag."""
101+
remote_repo = create_hg_remote_repo()
102+
repo_path = tmp_path / "quiet_repo"
103+
104+
hg = AsyncHg(path=repo_path)
105+
await hg.clone(url=f"file://{remote_repo}", quiet=True)
106+
107+
assert repo_path.exists()
108+
109+
@pytest.mark.asyncio
110+
async def test_clone_no_update(
111+
self,
112+
tmp_path: Path,
113+
create_hg_remote_repo: CreateRepoPytestFixtureFn,
114+
) -> None:
115+
"""Test clone with no_update flag."""
116+
remote_repo = create_hg_remote_repo()
117+
repo_path = tmp_path / "noupdate_repo"
118+
119+
hg = AsyncHg(path=repo_path)
120+
await hg.clone(url=f"file://{remote_repo}", no_update=True)
121+
122+
assert repo_path.exists()
123+
assert (repo_path / ".hg").exists()
124+
125+
126+
class TestAsyncHgUpdate:
127+
"""Tests for AsyncHg.update()."""
128+
129+
@pytest.mark.asyncio
130+
async def test_update_basic(
131+
self,
132+
tmp_path: Path,
133+
create_hg_remote_repo: CreateRepoPytestFixtureFn,
134+
) -> None:
135+
"""Test basic update operation."""
136+
remote_repo = create_hg_remote_repo()
137+
repo_path = tmp_path / "update_repo"
138+
139+
hg = AsyncHg(path=repo_path)
140+
await hg.clone(url=f"file://{remote_repo}")
141+
output = await hg.update()
142+
143+
assert "files" in output or "0 files" in output
144+
145+
146+
class TestAsyncHgPull:
147+
"""Tests for AsyncHg.pull()."""
148+
149+
@pytest.mark.asyncio
150+
async def test_pull_basic(
151+
self,
152+
tmp_path: Path,
153+
create_hg_remote_repo: CreateRepoPytestFixtureFn,
154+
) -> None:
155+
"""Test basic pull operation."""
156+
remote_repo = create_hg_remote_repo()
157+
repo_path = tmp_path / "pull_repo"
158+
159+
hg = AsyncHg(path=repo_path)
160+
await hg.clone(url=f"file://{remote_repo}")
161+
output = await hg.pull()
162+
163+
assert "no changes found" in output or "pulling from" in output
164+
165+
@pytest.mark.asyncio
166+
async def test_pull_with_update(
167+
self,
168+
tmp_path: Path,
169+
create_hg_remote_repo: CreateRepoPytestFixtureFn,
170+
) -> None:
171+
"""Test pull with update flag."""
172+
remote_repo = create_hg_remote_repo()
173+
repo_path = tmp_path / "pull_update_repo"
174+
175+
hg = AsyncHg(path=repo_path)
176+
await hg.clone(url=f"file://{remote_repo}")
177+
output = await hg.pull(update=True)
178+
179+
assert output is not None

0 commit comments

Comments
 (0)