Skip to content

Commit 316e3c1

Browse files
committed
tests(async_hg): Add AsyncHgSync sync tests
why: Verify AsyncHgSync functionality. what: - Test obtain, get_revision, update_repo methods - 6 test cases
1 parent 1d87670 commit 316e3c1

1 file changed

Lines changed: 126 additions & 0 deletions

File tree

tests/sync/_async/test_hg.py

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
"""Tests for libvcs.sync._async.hg."""
2+
3+
from __future__ import annotations
4+
5+
from pathlib import Path
6+
7+
import pytest
8+
9+
from libvcs.pytest_plugin import CreateRepoPytestFixtureFn
10+
from libvcs.sync._async.hg import AsyncHgSync
11+
12+
13+
class TestAsyncHgSync:
14+
"""Tests for AsyncHgSync class."""
15+
16+
def test_init(self, tmp_path: Path) -> None:
17+
"""Test AsyncHgSync initialization."""
18+
repo = AsyncHgSync(
19+
url="https://hg.example.com/repo",
20+
path=tmp_path / "repo",
21+
)
22+
assert repo.url == "https://hg.example.com/repo"
23+
assert repo.path == tmp_path / "repo"
24+
25+
def test_repr(self, tmp_path: Path) -> None:
26+
"""Test AsyncHgSync repr."""
27+
repo = AsyncHgSync(
28+
url="https://hg.example.com/repo",
29+
path=tmp_path / "myrepo",
30+
)
31+
assert "AsyncHgSync" in repr(repo)
32+
assert "myrepo" in repr(repo)
33+
34+
35+
class TestAsyncHgSyncObtain:
36+
"""Tests for AsyncHgSync.obtain()."""
37+
38+
@pytest.mark.asyncio
39+
async def test_obtain_basic(
40+
self,
41+
tmp_path: Path,
42+
create_hg_remote_repo: CreateRepoPytestFixtureFn,
43+
) -> None:
44+
"""Test basic obtain operation."""
45+
remote_repo = create_hg_remote_repo()
46+
repo_path = tmp_path / "obtained_repo"
47+
48+
repo = AsyncHgSync(
49+
url=f"file://{remote_repo}",
50+
path=repo_path,
51+
)
52+
await repo.obtain()
53+
54+
assert repo_path.exists()
55+
assert (repo_path / ".hg").exists()
56+
57+
58+
class TestAsyncHgSyncUpdateRepo:
59+
"""Tests for AsyncHgSync.update_repo()."""
60+
61+
@pytest.mark.asyncio
62+
async def test_update_repo_basic(
63+
self,
64+
tmp_path: Path,
65+
create_hg_remote_repo: CreateRepoPytestFixtureFn,
66+
) -> None:
67+
"""Test basic update_repo operation."""
68+
remote_repo = create_hg_remote_repo()
69+
repo_path = tmp_path / "update_repo"
70+
71+
repo = AsyncHgSync(
72+
url=f"file://{remote_repo}",
73+
path=repo_path,
74+
)
75+
# First obtain
76+
await repo.obtain()
77+
78+
# Then update
79+
await repo.update_repo()
80+
81+
assert repo_path.exists()
82+
83+
@pytest.mark.asyncio
84+
async def test_update_repo_obtains_if_missing(
85+
self,
86+
tmp_path: Path,
87+
create_hg_remote_repo: CreateRepoPytestFixtureFn,
88+
) -> None:
89+
"""Test update_repo clones if repo doesn't exist."""
90+
remote_repo = create_hg_remote_repo()
91+
repo_path = tmp_path / "new_repo"
92+
93+
repo = AsyncHgSync(
94+
url=f"file://{remote_repo}",
95+
path=repo_path,
96+
)
97+
# Just update_repo without obtain first
98+
await repo.update_repo()
99+
100+
# Should have cloned
101+
assert repo_path.exists()
102+
assert (repo_path / ".hg").exists()
103+
104+
105+
class TestAsyncHgSyncGetRevision:
106+
"""Tests for AsyncHgSync.get_revision()."""
107+
108+
@pytest.mark.asyncio
109+
async def test_get_revision(
110+
self,
111+
tmp_path: Path,
112+
create_hg_remote_repo: CreateRepoPytestFixtureFn,
113+
) -> None:
114+
"""Test get_revision returns current revision."""
115+
remote_repo = create_hg_remote_repo()
116+
repo_path = tmp_path / "rev_repo"
117+
118+
repo = AsyncHgSync(
119+
url=f"file://{remote_repo}",
120+
path=repo_path,
121+
)
122+
await repo.obtain()
123+
124+
revision = await repo.get_revision()
125+
# Mercurial revisions are numeric (0, 1, 2, ...)
126+
assert revision.strip().isdigit() or revision.strip() == ""

0 commit comments

Comments
 (0)