Skip to content

Commit a2f6281

Browse files
committed
docs(quickstart,pytest-plugin): Add async examples
why: New users need to see async option in getting started docs what: - quickstart.md: Add "Async Usage" section with AsyncGit, AsyncGitSync - pytest-plugin.md: Add "Async Fixtures" section documenting async_git_repo, pytest-asyncio configuration, usage examples
1 parent b878cd6 commit a2f6281

2 files changed

Lines changed: 96 additions & 0 deletions

File tree

docs/pytest-plugin.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,64 @@ def setup(set_hgconfig: None):
131131
pass
132132
```
133133

134+
## Async Fixtures
135+
136+
For async testing with [pytest-asyncio], libvcs provides async fixture variants:
137+
138+
[pytest-asyncio]: https://pytest-asyncio.readthedocs.io/
139+
140+
### Configuration
141+
142+
Add pytest-asyncio to your test dependencies and configure strict mode:
143+
144+
```toml
145+
# pyproject.toml
146+
[tool.pytest.ini_options]
147+
asyncio_mode = "strict"
148+
asyncio_default_fixture_loop_scope = "function"
149+
```
150+
151+
### Available Async Fixtures
152+
153+
- {func}`async_git_repo` - An {class}`~libvcs.sync._async.git.AsyncGitSync` instance ready for testing
154+
- `async_create_git_remote_repo` - Factory to create temporary git repositories
155+
156+
### Usage Example
157+
158+
```python
159+
import pytest
160+
161+
@pytest.mark.asyncio
162+
async def test_async_repo_operations(async_git_repo):
163+
"""Test async repository operations."""
164+
# async_git_repo is an AsyncGitSync instance
165+
status = await async_git_repo.cmd.status()
166+
assert 'On branch' in status
167+
168+
# Update the repo
169+
await async_git_repo.update_repo()
170+
```
171+
172+
### Creating Repositories in Async Tests
173+
174+
```python
175+
import pytest
176+
from libvcs.sync._async.git import AsyncGitSync
177+
178+
@pytest.mark.asyncio
179+
async def test_clone_repo(tmp_path, create_git_remote_repo):
180+
"""Test cloning a repository asynchronously."""
181+
remote = create_git_remote_repo()
182+
repo = AsyncGitSync(
183+
url=f'file://{remote}',
184+
path=tmp_path / 'clone',
185+
)
186+
await repo.obtain()
187+
assert (tmp_path / 'clone' / '.git').exists()
188+
```
189+
190+
See {doc}`/topics/asyncio` for more async patterns.
191+
134192
## Examples
135193

136194
For usage examples, refer to libvcs's own [tests/](https://github.com/vcs-python/libvcs/tree/master/tests).

docs/quickstart.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,41 @@ origin.prune()
9898
```
9999

100100
See {doc}`/cmd/git/index` for the full API reference.
101+
102+
### Async Usage
103+
104+
All APIs have async equivalents for non-blocking operations:
105+
106+
```python
107+
import asyncio
108+
from libvcs.cmd._async.git import AsyncGit
109+
110+
async def main():
111+
git = AsyncGit(path='/path/to/repo')
112+
113+
# Non-blocking git operations
114+
await git.run(['init'])
115+
status = await git.status()
116+
print(status)
117+
118+
asyncio.run(main())
119+
```
120+
121+
For repository synchronization:
122+
123+
```python
124+
import asyncio
125+
from libvcs.sync._async.git import AsyncGitSync
126+
127+
async def main():
128+
repo = AsyncGitSync(
129+
url='https://github.com/vcs-python/libvcs',
130+
path='/tmp/libvcs',
131+
)
132+
await repo.obtain() # Clone
133+
await repo.update_repo() # Update
134+
135+
asyncio.run(main())
136+
```
137+
138+
See {doc}`/topics/asyncio` for the complete async guide.

0 commit comments

Comments
 (0)