6
6
7
7
from __future__ import annotations
8
8
9
- import tempfile
10
- from collections .abc import Generator
11
- from pathlib import Path
12
-
13
- import pytest
9
+ import pathlib
14
10
15
11
from vcspull .config .loader import load_config , resolve_includes , save_config
16
12
from vcspull .config .models import Repository , Settings , VCSPullConfig
17
13
18
14
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 :
33
16
"""Test the complete configuration workflow from creation to resolution."""
34
17
# 1. Create a multi-level configuration setup
35
18
@@ -49,13 +32,13 @@ def test_complete_config_workflow(temp_config_dir: Path) -> None:
49
32
Repository (
50
33
name = "repo1" ,
51
34
url = "https://github.com/example/repo1.git" ,
52
- path = str (temp_config_dir / "repos/repo1" ),
35
+ path = str (tmp_path / "repos/repo1" ),
53
36
vcs = "git" ,
54
37
),
55
38
Repository (
56
39
name = "repo2" ,
57
40
url = "https://github.com/example/repo2.git" ,
58
- path = str (temp_config_dir / "repos/repo2" ),
41
+ path = str (tmp_path / "repos/repo2" ),
59
42
vcs = "git" ,
60
43
),
61
44
],
@@ -68,7 +51,7 @@ def test_complete_config_workflow(temp_config_dir: Path) -> None:
68
51
Repository (
69
52
name = "hg-repo1" ,
70
53
url = "https://hg.example.org/repo1" ,
71
- path = str (temp_config_dir / "repos/hg-repo1" ),
54
+ path = str (tmp_path / "repos/hg-repo1" ),
72
55
vcs = "hg" ,
73
56
),
74
57
],
@@ -80,13 +63,13 @@ def test_complete_config_workflow(temp_config_dir: Path) -> None:
80
63
Repository (
81
64
name = "nested-repo" ,
82
65
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" ),
84
67
vcs = "git" ,
85
68
),
86
69
Repository (
87
70
name = "svn-repo" ,
88
71
url = "svn://svn.example.org/repo" ,
89
- path = str (temp_config_dir / "repos/svn-repo" ),
72
+ path = str (tmp_path / "repos/svn-repo" ),
90
73
vcs = "svn" ,
91
74
),
92
75
],
@@ -95,13 +78,13 @@ def test_complete_config_workflow(temp_config_dir: Path) -> None:
95
78
# 2. Save all config files
96
79
97
80
# Create nested directory
98
- nested_dir = temp_config_dir / "nested"
81
+ nested_dir = tmp_path / "nested"
99
82
nested_dir .mkdir (exist_ok = True )
100
83
101
84
# 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"
105
88
nested_path = nested_dir / "more-repos.yaml"
106
89
107
90
save_config (base_config , base_path )
@@ -134,11 +117,11 @@ def test_complete_config_workflow(temp_config_dir: Path) -> None:
134
117
135
118
# Verify all paths are absolute
136
119
for repo in resolved_config .repositories :
137
- assert Path (repo .path ).is_absolute ()
120
+ assert pathlib . Path (repo .path ).is_absolute ()
138
121
139
122
# 5. Test saving the resolved config
140
123
141
- resolved_path = temp_config_dir / "resolved.yaml"
124
+ resolved_path = tmp_path / "resolved.yaml"
142
125
save_config (resolved_config , resolved_path )
143
126
144
127
# 6. Load the saved resolved config and verify
@@ -152,7 +135,7 @@ def test_complete_config_workflow(temp_config_dir: Path) -> None:
152
135
assert len (final_config .repositories ) == 5
153
136
154
137
155
- def test_missing_include_handling (temp_config_dir : Path ) -> None :
138
+ def test_missing_include_handling (tmp_path : pathlib . Path ) -> None :
156
139
"""Test that missing includes are handled gracefully."""
157
140
# Create a config with a non-existent include
158
141
config = VCSPullConfig (
@@ -161,19 +144,19 @@ def test_missing_include_handling(temp_config_dir: Path) -> None:
161
144
Repository (
162
145
name = "repo1" ,
163
146
url = "https://github.com/example/repo1.git" ,
164
- path = str (temp_config_dir / "repos/repo1" ),
147
+ path = str (tmp_path / "repos/repo1" ),
165
148
),
166
149
],
167
150
includes = ["missing.yaml" ],
168
151
)
169
152
170
153
# Save the config
171
- config_path = temp_config_dir / "config.yaml"
154
+ config_path = tmp_path / "config.yaml"
172
155
save_config (config , config_path )
173
156
174
157
# Load and resolve includes
175
158
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 )
177
160
178
161
# The config should still contain the original repository
179
162
assert len (resolved_config .repositories ) == 1
@@ -183,15 +166,15 @@ def test_missing_include_handling(temp_config_dir: Path) -> None:
183
166
assert len (resolved_config .includes ) == 0
184
167
185
168
186
- def test_circular_include_prevention (temp_config_dir : Path ) -> None :
169
+ def test_circular_include_prevention (tmp_path : pathlib . Path ) -> None :
187
170
"""Test that circular includes don't cause infinite recursion."""
188
171
# Create configs that include each other
189
172
config1 = VCSPullConfig (
190
173
repositories = [
191
174
Repository (
192
175
name = "repo1" ,
193
176
url = "https://github.com/example/repo1.git" ,
194
- path = str (temp_config_dir / "repos/repo1" ),
177
+ path = str (tmp_path / "repos/repo1" ),
195
178
),
196
179
],
197
180
includes = ["config2.yaml" ],
@@ -202,21 +185,21 @@ def test_circular_include_prevention(temp_config_dir: Path) -> None:
202
185
Repository (
203
186
name = "repo2" ,
204
187
url = "https://github.com/example/repo2.git" ,
205
- path = str (temp_config_dir / "repos/repo2" ),
188
+ path = str (tmp_path / "repos/repo2" ),
206
189
),
207
190
],
208
191
includes = ["config1.yaml" ], # Creates a circular reference
209
192
)
210
193
211
194
# 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"
214
197
save_config (config1 , config1_path )
215
198
save_config (config2 , config2_path )
216
199
217
200
# Load and resolve includes for the first config
218
201
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 )
220
203
221
204
# The repositories might contain duplicates due to circular references
222
205
# Get the unique URLs to check if both repos are included
0 commit comments