3
3
from __future__ import annotations
4
4
5
5
import logging
6
- import pathlib
7
6
import typing as t
8
7
9
8
import pytest
12
11
from vcspull .cli .fmt import format_config , format_config_file , normalize_repo_config
13
12
14
13
if t .TYPE_CHECKING :
14
+ import pathlib
15
+
15
16
from _pytest .logging import LogCaptureFixture
16
17
17
18
@@ -31,9 +32,9 @@ def reset_logging() -> t.Generator[None, None, None]:
31
32
logger = logging .getLogger (logger_name )
32
33
logger .handlers .clear ()
33
34
logger .propagate = True # Re-enable propagation so pytest can capture logs
34
-
35
+
35
36
yield
36
-
37
+
37
38
# Clear again after test
38
39
for logger_name in cli_loggers :
39
40
logger = logging .getLogger (logger_name )
@@ -107,7 +108,7 @@ def test_sort_repositories(self) -> None:
107
108
"zebra" : "url1" ,
108
109
"alpha" : "url2" ,
109
110
"beta" : "url3" ,
110
- }
111
+ },
111
112
}
112
113
formatted , changes = format_config (config )
113
114
assert list (formatted ["~/projects/" ].keys ()) == ["alpha" , "beta" , "zebra" ]
@@ -120,21 +121,21 @@ def test_compact_format_conversion(self) -> None:
120
121
"repo1" : "git+https://github.com/user/repo1.git" ,
121
122
"repo2" : {"url" : "git+https://github.com/user/repo2.git" },
122
123
"repo3" : {"repo" : "git+https://github.com/user/repo3.git" },
123
- }
124
+ },
124
125
}
125
126
formatted , changes = format_config (config )
126
127
127
128
# repo1 should be converted from compact to verbose
128
129
assert formatted ["~/projects/" ]["repo1" ] == {
129
- "repo" : "git+https://github.com/user/repo1.git"
130
+ "repo" : "git+https://github.com/user/repo1.git" ,
130
131
}
131
132
# repo2 should have url converted to repo
132
133
assert formatted ["~/projects/" ]["repo2" ] == {
133
- "repo" : "git+https://github.com/user/repo2.git"
134
+ "repo" : "git+https://github.com/user/repo2.git" ,
134
135
}
135
136
# repo3 should stay the same
136
137
assert formatted ["~/projects/" ]["repo3" ] == {
137
- "repo" : "git+https://github.com/user/repo3.git"
138
+ "repo" : "git+https://github.com/user/repo3.git" ,
138
139
}
139
140
assert changes == 2 # repo1 and repo2 changed
140
141
@@ -362,40 +363,42 @@ def test_format_all_configs(
362
363
# Create test config directory structure
363
364
config_dir = tmp_path / ".config" / "vcspull"
364
365
config_dir .mkdir (parents = True )
365
-
366
+
366
367
# Create home config (already formatted correctly)
367
368
home_config = tmp_path / ".vcspull.yaml"
368
369
home_config .write_text (
369
370
yaml .dump ({"~/projects/" : {"repo1" : {"repo" : "url1" }}}),
370
371
encoding = "utf-8" ,
371
372
)
372
-
373
+
373
374
# Create config in config directory (needs sorting)
374
375
config1 = config_dir / "work.yaml"
375
376
config1_content = """~/work/:
376
377
repo2: url2
377
378
repo1: url1
378
379
"""
379
380
config1 .write_text (config1_content , encoding = "utf-8" )
380
-
381
+
381
382
# Create local config
382
383
local_config = tmp_path / "project" / ".vcspull.yaml"
383
384
local_config .parent .mkdir ()
384
385
local_config .write_text (
385
386
yaml .dump ({"./" : {"repo3" : {"url" : "url3" }}}),
386
387
encoding = "utf-8" ,
387
388
)
388
-
389
+
389
390
# Mock find functions to return our test configs
390
391
def mock_find_config_files (include_home : bool = False ) -> list [pathlib .Path ]:
391
392
files = [config1 ]
392
393
if include_home :
393
394
files .insert (0 , home_config )
394
395
return files
395
-
396
- def mock_find_home_config_files (filetype : list [str ] | None = None ) -> list [pathlib .Path ]:
396
+
397
+ def mock_find_home_config_files (
398
+ filetype : list [str ] | None = None ,
399
+ ) -> list [pathlib .Path ]:
397
400
return [home_config ]
398
-
401
+
399
402
# Change to project directory
400
403
monkeypatch .chdir (local_config .parent )
401
404
monkeypatch .setattr (
@@ -406,19 +409,21 @@ def mock_find_home_config_files(filetype: list[str] | None = None) -> list[pathl
406
409
"vcspull.cli.fmt.find_home_config_files" ,
407
410
mock_find_home_config_files ,
408
411
)
409
-
412
+
410
413
with caplog .at_level (logging .INFO ):
411
414
format_config_file (None , write = False , format_all = True )
412
-
415
+
413
416
# Check that all configs were found
414
417
assert "Found 3 configuration files to format" in caplog .text
415
418
assert str (home_config ) in caplog .text
416
419
assert str (config1 ) in caplog .text
417
420
assert str (local_config ) in caplog .text
418
-
421
+
419
422
# Check processing messages
420
423
assert "already formatted correctly" in caplog .text # home_config
421
- assert "3 formatting issues" in caplog .text # config1 has 2 compact + needs sorting
424
+ assert (
425
+ "3 formatting issues" in caplog .text
426
+ ) # config1 has 2 compact + needs sorting
422
427
assert "2 repositories from compact to verbose format" in caplog .text # config1
423
428
assert "Repositories in ~/work/ will be sorted" in caplog .text # config1
424
429
assert "1 repository from 'url' to 'repo' key" in caplog .text # local_config
0 commit comments