Skip to content

Commit e9d85a5

Browse files
committed
cmd,sync/_async(fix): Enable async doctests to run
why: Doctests were commented out and never executed what: - cmd/_async/git.py: Use tmp_path and create_git_remote_repo fixtures - cmd/_async/hg.py: Use create_hg_remote_repo fixture - cmd/_async/svn.py: Use create_svn_remote_repo fixture - sync/_async/git.py: Use create_git_remote_repo fixture - sync/_async/hg.py: Use create_hg_remote_repo fixture - sync/_async/svn.py: Use create_svn_remote_repo fixture All doctests now actually run and test real functionality.
1 parent 6a8f22a commit e9d85a5

6 files changed

Lines changed: 49 additions & 43 deletions

File tree

src/libvcs/cmd/_async/git.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ class AsyncGit:
3636
3737
Examples
3838
--------
39-
>>> import asyncio
4039
>>> async def example():
41-
... git = AsyncGit(path="/path/to/repo")
40+
... git = AsyncGit(path=tmp_path)
41+
... await git.run(['init'])
4242
... status = await git.status()
43-
... return status
44-
>>> # asyncio.run(example())
43+
... return 'On branch' in status or 'No commits yet' in status
44+
>>> asyncio.run(example())
45+
True
4546
"""
4647

4748
progress_callback: AsyncProgressCallbackProtocol | None = None
@@ -128,11 +129,12 @@ async def run(
128129
129130
Examples
130131
--------
131-
>>> import asyncio
132132
>>> async def example():
133-
... git = AsyncGit(path="/path/to/repo")
134-
... return await git.run(["status"])
135-
>>> # asyncio.run(example())
133+
... git = AsyncGit(path=tmp_path)
134+
... await git.run(['init'])
135+
... return 'On branch' in await git.run(['status'])
136+
>>> asyncio.run(example())
137+
True
136138
"""
137139
cli_args: list[str]
138140
if isinstance(args, Sequence) and not isinstance(args, (str, bytes)):
@@ -223,11 +225,14 @@ async def clone(
223225
224226
Examples
225227
--------
226-
>>> import asyncio
227228
>>> async def example():
228-
... git = AsyncGit(path="/tmp/myrepo")
229-
... await git.clone(url="https://github.com/user/repo")
230-
>>> # asyncio.run(example())
229+
... repo_path = tmp_path / 'cloned_repo'
230+
... git = AsyncGit(path=repo_path)
231+
... url = f'file://{create_git_remote_repo()}'
232+
... await git.clone(url=url)
233+
... return (repo_path / '.git').exists()
234+
>>> asyncio.run(example())
235+
True
231236
"""
232237
if make_parents and not self.path.exists():
233238
self.path.mkdir(parents=True)

src/libvcs/cmd/_async/hg.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ class AsyncHg:
5656
5757
Examples
5858
--------
59-
>>> import asyncio
6059
>>> async def example():
61-
... hg = AsyncHg(path="/path/to/repo")
62-
... output = await hg.pull()
63-
... return output
64-
>>> # asyncio.run(example())
60+
... repo_path = tmp_path / 'hg_repo'
61+
... hg = AsyncHg(path=repo_path)
62+
... url = f'file://{create_hg_remote_repo()}'
63+
... await hg.clone(url=url)
64+
... return (repo_path / '.hg').exists()
65+
>>> asyncio.run(example())
66+
True
6567
"""
6668

6769
progress_callback: AsyncProgressCallbackProtocol | None = None

src/libvcs/cmd/_async/svn.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ class AsyncSvn:
3939
4040
Examples
4141
--------
42-
>>> import asyncio
4342
>>> async def example():
44-
... svn = AsyncSvn(path="/path/to/working-copy")
45-
... info = await svn.info()
46-
... return info
47-
>>> # asyncio.run(example())
43+
... repo_path = tmp_path / 'svn_wc'
44+
... svn = AsyncSvn(path=repo_path)
45+
... url = f'file://{create_svn_remote_repo()}'
46+
... await svn.checkout(url=url)
47+
... return (repo_path / '.svn').exists()
48+
>>> asyncio.run(example())
49+
True
4850
"""
4951

5052
progress_callback: AsyncProgressCallbackProtocol | None = None

src/libvcs/sync/_async/git.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,14 @@ class AsyncGitSync(AsyncBaseSync):
6262
6363
Examples
6464
--------
65-
>>> import asyncio
6665
>>> async def example():
67-
... repo = AsyncGitSync(
68-
... url="https://github.com/vcs-python/libvcs",
69-
... path="/tmp/libvcs",
70-
... )
66+
... url = f'file://{create_git_remote_repo()}'
67+
... repo_path = tmp_path / 'git_sync_repo'
68+
... repo = AsyncGitSync(url=url, path=repo_path)
7169
... await repo.obtain()
72-
... await repo.update_repo()
73-
>>> # asyncio.run(example())
70+
... return (repo_path / '.git').exists()
71+
>>> asyncio.run(example())
72+
True
7473
"""
7574

7675
bin_name = "git"

src/libvcs/sync/_async/hg.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@ class AsyncHgSync(AsyncBaseSync):
2525
2626
Examples
2727
--------
28-
>>> import asyncio
2928
>>> async def example():
30-
... repo = AsyncHgSync(
31-
... url="https://hg.example.com/repo",
32-
... path="/tmp/myrepo",
33-
... )
29+
... url = f'file://{create_hg_remote_repo()}'
30+
... repo_path = tmp_path / 'hg_sync_repo'
31+
... repo = AsyncHgSync(url=url, path=repo_path)
3432
... await repo.obtain()
35-
... await repo.update_repo()
36-
>>> # asyncio.run(example())
33+
... return (repo_path / '.hg').exists()
34+
>>> asyncio.run(example())
35+
True
3736
"""
3837

3938
bin_name = "hg"

src/libvcs/sync/_async/svn.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@ class AsyncSvnSync(AsyncBaseSync):
3131
3232
Examples
3333
--------
34-
>>> import asyncio
3534
>>> async def example():
36-
... repo = AsyncSvnSync(
37-
... url="svn://svn.example.com/repo",
38-
... path="/tmp/myrepo",
39-
... )
35+
... url = f'file://{create_svn_remote_repo()}'
36+
... repo_path = tmp_path / 'svn_sync_repo'
37+
... repo = AsyncSvnSync(url=url, path=repo_path)
4038
... await repo.obtain()
41-
... await repo.update_repo()
42-
>>> # asyncio.run(example())
39+
... return (repo_path / '.svn').exists()
40+
>>> asyncio.run(example())
41+
True
4342
"""
4443

4544
bin_name = "svn"

0 commit comments

Comments
 (0)