Skip to content

Commit 3e3654b

Browse files
committed
1 parent 10c8061 commit 3e3654b

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

.cursor/rules/vcspull-pytest.mdc

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
description:
3+
globs: tests/**/test_*.py
4+
alwaysApply: true
5+
---
6+
7+
# VCSPull Pytest Integration with libvcs
8+
9+
When writing tests for vcspull, leverage libvcs's pytest plugin to efficiently create and manage VCS repositories during testing.
10+
11+
## Available Fixtures from libvcs
12+
13+
libvcs provides a complete set of fixtures that automatically handle the creation and cleanup of VCS repositories:
14+
15+
### Core Repository Creation Fixtures
16+
17+
- `create_git_remote_repo`: Factory fixture that creates a local Git repository
18+
- `create_svn_remote_repo`: Factory fixture that creates a local SVN repository
19+
- `create_hg_remote_repo`: Factory fixture that creates a local Mercurial repository
20+
21+
### Pre-configured Repository Fixtures
22+
23+
- `git_repo`: Pre-made Git repository clone (GitSync instance)
24+
- `svn_repo`: Pre-made SVN repository checkout (SvnSync instance)
25+
- `hg_repo`: Pre-made Mercurial repository clone (HgSync instance)
26+
27+
### Environment & Configuration Fixtures
28+
29+
- `set_home`: Sets a temporary home directory
30+
- `gitconfig`: Git configuration for test repositories
31+
- `hgconfig`: Mercurial configuration for test repositories
32+
- `git_commit_envvars`: Environment variables for Git commits
33+
34+
## Usage Examples
35+
36+
### Basic Repository Creation
37+
38+
```python
39+
def test_vcspull_with_git(create_git_remote_repo):
40+
# Create a test git repository on-the-fly
41+
repo_path = create_git_remote_repo()
42+
43+
# repo_path is now a pathlib.Path pointing to a clean git repo
44+
# Use this repository in your vcspull tests
45+
```
46+
47+
### Using Pre-configured Repositories
48+
49+
```python
50+
def test_vcspull_sync(git_repo):
51+
# git_repo is already a GitSync instance with a clean repository
52+
# Use it directly in your tests
53+
54+
# The repository will be automatically cleaned up after the test
55+
```
56+
57+
### Custom Repository Setup
58+
59+
```python
60+
def test_custom_repo_state(
61+
create_git_remote_repo,
62+
git_commit_envvars
63+
):
64+
# Create a repo with custom initialization
65+
repo_path = create_git_remote_repo()
66+
67+
# Modify the repository as needed with the correct environment
68+
import subprocess
69+
subprocess.run(
70+
["git", "commit", "--allow-empty", "-m", "Custom commit"],
71+
cwd=repo_path,
72+
env=git_commit_envvars
73+
)
74+
```
75+
76+
## Benefits
77+
78+
- **Fast tests**: Repositories are created efficiently and cached appropriately
79+
- **Clean environment**: Each test gets fresh repositories without interference
80+
- **Reduced boilerplate**: No need to manually create/clean up repositories
81+
- **Realistic testing**: Test against actual VCS operations
82+
- **Compatible with pytest-xdist**: Works correctly with parallel test execution
83+
84+
For detailed documentation on all available fixtures, visit:
85+
- https://libvcs.git-pull.com/pytest-plugin.html
86+
- https://github.com/vcs-python/libvcs/blob/master/src/libvcs/pytest_plugin.py

.windsurfrules

+26
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,29 @@
134134
- Reduces potential naming conflicts
135135
- Makes import statements more maintainable
136136
</import_guidelines>
137+
138+
<repository_testing_guidelines>
139+
- Use libvcs pytest fixtures for all repository-related tests in vcspull:
140+
- Create temporary repositories efficiently with factory fixtures
141+
- Benefit from automatic cleanup when tests finish
142+
- Utilize proper environment variables and configurations
143+
- Test against real VCS operations without mocking
144+
145+
- Basic repository testing pattern:
146+
```python
147+
def test_repository_operation(create_git_remote_repo):
148+
# Create a test repository
149+
repo_path = create_git_remote_repo()
150+
151+
# Test vcspull functionality with the repository
152+
# ...
153+
```
154+
155+
- For more complex scenarios, use the pre-configured repository instances:
156+
```python
157+
def test_sync_operations(git_repo):
158+
# git_repo is already a GitSync instance
159+
# Test vcspull sync operations
160+
# ...
161+
```
162+
</repository_testing_guidelines>

0 commit comments

Comments
 (0)