Skip to content

Commit a73a780

Browse files
committed
!squash tests/config(test[loader]): Add property-based
1 parent a1dd3cc commit a73a780

File tree

1 file changed

+23
-40
lines changed

1 file changed

+23
-40
lines changed

tests/integration/test_config_system.py

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,13 @@
66

77
from __future__ import annotations
88

9-
import tempfile
10-
from collections.abc import Generator
11-
from pathlib import Path
12-
13-
import pytest
9+
import pathlib
1410

1511
from vcspull.config.loader import load_config, resolve_includes, save_config
1612
from vcspull.config.models import Repository, Settings, VCSPullConfig
1713

1814

19-
@pytest.fixture
20-
def temp_config_dir() -> Generator[Path, None, None]:
21-
"""Create a temporary directory for config files.
22-
23-
Returns
24-
-------
25-
Generator[Path, None, None]
26-
Temporary directory path
27-
"""
28-
with tempfile.TemporaryDirectory() as temp_dir:
29-
yield Path(temp_dir)
30-
31-
32-
def test_complete_config_workflow(temp_config_dir: Path) -> None:
15+
def test_complete_config_workflow(tmp_path: pathlib.Path) -> None:
3316
"""Test the complete configuration workflow from creation to resolution."""
3417
# 1. Create a multi-level configuration setup
3518

@@ -49,13 +32,13 @@ def test_complete_config_workflow(temp_config_dir: Path) -> None:
4932
Repository(
5033
name="repo1",
5134
url="https://github.com/example/repo1.git",
52-
path=str(temp_config_dir / "repos/repo1"),
35+
path=str(tmp_path / "repos/repo1"),
5336
vcs="git",
5437
),
5538
Repository(
5639
name="repo2",
5740
url="https://github.com/example/repo2.git",
58-
path=str(temp_config_dir / "repos/repo2"),
41+
path=str(tmp_path / "repos/repo2"),
5942
vcs="git",
6043
),
6144
],
@@ -68,7 +51,7 @@ def test_complete_config_workflow(temp_config_dir: Path) -> None:
6851
Repository(
6952
name="hg-repo1",
7053
url="https://hg.example.org/repo1",
71-
path=str(temp_config_dir / "repos/hg-repo1"),
54+
path=str(tmp_path / "repos/hg-repo1"),
7255
vcs="hg",
7356
),
7457
],
@@ -80,13 +63,13 @@ def test_complete_config_workflow(temp_config_dir: Path) -> None:
8063
Repository(
8164
name="nested-repo",
8265
url="https://github.com/example/nested-repo.git",
83-
path=str(temp_config_dir / "repos/nested-repo"),
66+
path=str(tmp_path / "repos/nested-repo"),
8467
vcs="git",
8568
),
8669
Repository(
8770
name="svn-repo",
8871
url="svn://svn.example.org/repo",
89-
path=str(temp_config_dir / "repos/svn-repo"),
72+
path=str(tmp_path / "repos/svn-repo"),
9073
vcs="svn",
9174
),
9275
],
@@ -95,13 +78,13 @@ def test_complete_config_workflow(temp_config_dir: Path) -> None:
9578
# 2. Save all config files
9679

9780
# Create nested directory
98-
nested_dir = temp_config_dir / "nested"
81+
nested_dir = tmp_path / "nested"
9982
nested_dir.mkdir(exist_ok=True)
10083

10184
# Save all configs
102-
base_path = temp_config_dir / "vcspull.yaml"
103-
repos1_path = temp_config_dir / "repos1.yaml"
104-
repos2_path = temp_config_dir / "repos2.yaml"
85+
base_path = tmp_path / "vcspull.yaml"
86+
repos1_path = tmp_path / "repos1.yaml"
87+
repos2_path = tmp_path / "repos2.yaml"
10588
nested_path = nested_dir / "more-repos.yaml"
10689

10790
save_config(base_config, base_path)
@@ -134,11 +117,11 @@ def test_complete_config_workflow(temp_config_dir: Path) -> None:
134117

135118
# Verify all paths are absolute
136119
for repo in resolved_config.repositories:
137-
assert Path(repo.path).is_absolute()
120+
assert pathlib.Path(repo.path).is_absolute()
138121

139122
# 5. Test saving the resolved config
140123

141-
resolved_path = temp_config_dir / "resolved.yaml"
124+
resolved_path = tmp_path / "resolved.yaml"
142125
save_config(resolved_config, resolved_path)
143126

144127
# 6. Load the saved resolved config and verify
@@ -152,7 +135,7 @@ def test_complete_config_workflow(temp_config_dir: Path) -> None:
152135
assert len(final_config.repositories) == 5
153136

154137

155-
def test_missing_include_handling(temp_config_dir: Path) -> None:
138+
def test_missing_include_handling(tmp_path: pathlib.Path) -> None:
156139
"""Test that missing includes are handled gracefully."""
157140
# Create a config with a non-existent include
158141
config = VCSPullConfig(
@@ -161,19 +144,19 @@ def test_missing_include_handling(temp_config_dir: Path) -> None:
161144
Repository(
162145
name="repo1",
163146
url="https://github.com/example/repo1.git",
164-
path=str(temp_config_dir / "repos/repo1"),
147+
path=str(tmp_path / "repos/repo1"),
165148
),
166149
],
167150
includes=["missing.yaml"],
168151
)
169152

170153
# Save the config
171-
config_path = temp_config_dir / "config.yaml"
154+
config_path = tmp_path / "config.yaml"
172155
save_config(config, config_path)
173156

174157
# Load and resolve includes
175158
loaded_config = load_config(config_path)
176-
resolved_config = resolve_includes(loaded_config, temp_config_dir)
159+
resolved_config = resolve_includes(loaded_config, tmp_path)
177160

178161
# The config should still contain the original repository
179162
assert len(resolved_config.repositories) == 1
@@ -183,15 +166,15 @@ def test_missing_include_handling(temp_config_dir: Path) -> None:
183166
assert len(resolved_config.includes) == 0
184167

185168

186-
def test_circular_include_prevention(temp_config_dir: Path) -> None:
169+
def test_circular_include_prevention(tmp_path: pathlib.Path) -> None:
187170
"""Test that circular includes don't cause infinite recursion."""
188171
# Create configs that include each other
189172
config1 = VCSPullConfig(
190173
repositories=[
191174
Repository(
192175
name="repo1",
193176
url="https://github.com/example/repo1.git",
194-
path=str(temp_config_dir / "repos/repo1"),
177+
path=str(tmp_path / "repos/repo1"),
195178
),
196179
],
197180
includes=["config2.yaml"],
@@ -202,21 +185,21 @@ def test_circular_include_prevention(temp_config_dir: Path) -> None:
202185
Repository(
203186
name="repo2",
204187
url="https://github.com/example/repo2.git",
205-
path=str(temp_config_dir / "repos/repo2"),
188+
path=str(tmp_path / "repos/repo2"),
206189
),
207190
],
208191
includes=["config1.yaml"], # Creates a circular reference
209192
)
210193

211194
# Save both configs
212-
config1_path = temp_config_dir / "config1.yaml"
213-
config2_path = temp_config_dir / "config2.yaml"
195+
config1_path = tmp_path / "config1.yaml"
196+
config2_path = tmp_path / "config2.yaml"
214197
save_config(config1, config1_path)
215198
save_config(config2, config2_path)
216199

217200
# Load and resolve includes for the first config
218201
loaded_config = load_config(config1_path)
219-
resolved_config = resolve_includes(loaded_config, temp_config_dir)
202+
resolved_config = resolve_includes(loaded_config, tmp_path)
220203

221204
# The repositories might contain duplicates due to circular references
222205
# Get the unique URLs to check if both repos are included

0 commit comments

Comments
 (0)