33from __future__ import annotations
44
55import logging
6- import pathlib
76import typing as t
87
98import pytest
1211from vcspull .cli .fmt import format_config , format_config_file , normalize_repo_config
1312
1413if t .TYPE_CHECKING :
14+ import pathlib
15+
1516 from _pytest .logging import LogCaptureFixture
1617
1718
@@ -31,9 +32,9 @@ def reset_logging() -> t.Generator[None, None, None]:
3132 logger = logging .getLogger (logger_name )
3233 logger .handlers .clear ()
3334 logger .propagate = True # Re-enable propagation so pytest can capture logs
34-
35+
3536 yield
36-
37+
3738 # Clear again after test
3839 for logger_name in cli_loggers :
3940 logger = logging .getLogger (logger_name )
@@ -107,7 +108,7 @@ def test_sort_repositories(self) -> None:
107108 "zebra" : "url1" ,
108109 "alpha" : "url2" ,
109110 "beta" : "url3" ,
110- }
111+ },
111112 }
112113 formatted , changes = format_config (config )
113114 assert list (formatted ["~/projects/" ].keys ()) == ["alpha" , "beta" , "zebra" ]
@@ -120,21 +121,21 @@ def test_compact_format_conversion(self) -> None:
120121 "repo1" : "git+https://github.com/user/repo1.git" ,
121122 "repo2" : {"url" : "git+https://github.com/user/repo2.git" },
122123 "repo3" : {"repo" : "git+https://github.com/user/repo3.git" },
123- }
124+ },
124125 }
125126 formatted , changes = format_config (config )
126127
127128 # repo1 should be converted from compact to verbose
128129 assert formatted ["~/projects/" ]["repo1" ] == {
129- "repo" : "git+https://github.com/user/repo1.git"
130+ "repo" : "git+https://github.com/user/repo1.git" ,
130131 }
131132 # repo2 should have url converted to repo
132133 assert formatted ["~/projects/" ]["repo2" ] == {
133- "repo" : "git+https://github.com/user/repo2.git"
134+ "repo" : "git+https://github.com/user/repo2.git" ,
134135 }
135136 # repo3 should stay the same
136137 assert formatted ["~/projects/" ]["repo3" ] == {
137- "repo" : "git+https://github.com/user/repo3.git"
138+ "repo" : "git+https://github.com/user/repo3.git" ,
138139 }
139140 assert changes == 2 # repo1 and repo2 changed
140141
@@ -362,40 +363,42 @@ def test_format_all_configs(
362363 # Create test config directory structure
363364 config_dir = tmp_path / ".config" / "vcspull"
364365 config_dir .mkdir (parents = True )
365-
366+
366367 # Create home config (already formatted correctly)
367368 home_config = tmp_path / ".vcspull.yaml"
368369 home_config .write_text (
369370 yaml .dump ({"~/projects/" : {"repo1" : {"repo" : "url1" }}}),
370371 encoding = "utf-8" ,
371372 )
372-
373+
373374 # Create config in config directory (needs sorting)
374375 config1 = config_dir / "work.yaml"
375376 config1_content = """~/work/:
376377 repo2: url2
377378 repo1: url1
378379"""
379380 config1 .write_text (config1_content , encoding = "utf-8" )
380-
381+
381382 # Create local config
382383 local_config = tmp_path / "project" / ".vcspull.yaml"
383384 local_config .parent .mkdir ()
384385 local_config .write_text (
385386 yaml .dump ({"./" : {"repo3" : {"url" : "url3" }}}),
386387 encoding = "utf-8" ,
387388 )
388-
389+
389390 # Mock find functions to return our test configs
390391 def mock_find_config_files (include_home : bool = False ) -> list [pathlib .Path ]:
391392 files = [config1 ]
392393 if include_home :
393394 files .insert (0 , home_config )
394395 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 ]:
397400 return [home_config ]
398-
401+
399402 # Change to project directory
400403 monkeypatch .chdir (local_config .parent )
401404 monkeypatch .setattr (
@@ -406,19 +409,21 @@ def mock_find_home_config_files(filetype: list[str] | None = None) -> list[pathl
406409 "vcspull.cli.fmt.find_home_config_files" ,
407410 mock_find_home_config_files ,
408411 )
409-
412+
410413 with caplog .at_level (logging .INFO ):
411414 format_config_file (None , write = False , format_all = True )
412-
415+
413416 # Check that all configs were found
414417 assert "Found 3 configuration files to format" in caplog .text
415418 assert str (home_config ) in caplog .text
416419 assert str (config1 ) in caplog .text
417420 assert str (local_config ) in caplog .text
418-
421+
419422 # Check processing messages
420423 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
422427 assert "2 repositories from compact to verbose format" in caplog .text # config1
423428 assert "Repositories in ~/work/ will be sorted" in caplog .text # config1
424429 assert "1 repository from 'url' to 'repo' key" in caplog .text # local_config
0 commit comments