Skip to content

Commit ceef050

Browse files
committed
Fix: Resolve test issues and add missing imports
- Fix sync() function call to pass pathlib.Path for config parameter - Add save_config_yaml to helpers and fix imports - Improve test teardown to use shutil.rmtree - Add missing pathlib import in CLI __init__.py - Set logging level in tests for proper log capture
1 parent fd5cc16 commit ceef050

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

src/vcspull/cli/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import argparse
66
import logging
7+
import pathlib
78
import textwrap
89
import typing as t
910
from typing import overload
@@ -142,7 +143,7 @@ def cli(_args: list[str] | None = None) -> None:
142143
"repo_patterns": args.repo_patterns
143144
if hasattr(args, "repo_patterns")
144145
else None,
145-
"config": args.config if hasattr(args, "config") else None,
146+
"config": pathlib.Path(args.config) if hasattr(args, "config") and args.config else None,
146147
"exit_on_error": args.exit_on_error
147148
if hasattr(args, "exit_on_error")
148149
else False,

src/vcspull/cli/add_from_fs.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import yaml # For YAML processing
1212

13-
from vcspull.cli.add import save_config_yaml # Re-use from add.py
1413
from vcspull.config import ( # Assuming these are useful
1514
expand_dir,
1615
find_home_config_files,
@@ -39,6 +38,12 @@ def get_git_origin_url(repo_path: pathlib.Path) -> str | None:
3938
return None
4039

4140

41+
def save_config_yaml(config_file_path: pathlib.Path, data: dict[t.Any, t.Any]) -> None:
42+
"""Save a dictionary to a YAML file."""
43+
with open(config_file_path, "w", encoding="utf-8") as f:
44+
yaml.dump(data, f, sort_keys=False, indent=2, default_flow_style=False)
45+
46+
4247
def create_add_from_fs_subparser(parser: argparse.ArgumentParser) -> None:
4348
"""Configure :py:class:`argparse.ArgumentParser` for ``vcspull add-from-fs``."""
4449
parser.add_argument(

tests/cli/test_add_from_fs.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
from __future__ import annotations
44

5+
import logging
56
import pathlib
67
import subprocess # For CompletedProcess
78
import typing as t
89

910
import pytest
1011
import yaml
1112

13+
from tests.helpers import save_config_yaml
1214
from vcspull.cli.add_from_fs import add_from_filesystem, get_git_origin_url
13-
from vcspull.tests.helpers import save_config_yaml
1415

1516
if t.TYPE_CHECKING:
1617
from _pytest.logging import LogCaptureFixture
@@ -22,19 +23,13 @@
2223

2324
@pytest.fixture(autouse=True)
2425
def setup_teardown_test_config_dir_fs() -> None:
26+
"""Set up and clean up test config directory."""
2527
if not TEST_CONFIG_DIR_FS.exists():
2628
TEST_CONFIG_DIR_FS.mkdir()
2729
yield
2830
if TEST_CONFIG_DIR_FS.exists():
29-
for item in TEST_CONFIG_DIR_FS.iterdir():
30-
if item.is_file():
31-
item.unlink()
32-
elif item.is_dir(): # Basic cleanup for dirs made by tests
33-
for sub_item in item.iterdir():
34-
if sub_item.is_file():
35-
sub_item.unlink()
36-
item.rmdir()
37-
TEST_CONFIG_DIR_FS.rmdir()
31+
import shutil
32+
shutil.rmtree(TEST_CONFIG_DIR_FS)
3833

3934

4035
@pytest.fixture
@@ -166,6 +161,7 @@ def test_add_from_fs_one_repo_found_no_config_exists(
166161
caplog: LogCaptureFixture,
167162
) -> None:
168163
"""Test finding one repo and creating a new config file."""
164+
caplog.set_level(logging.INFO)
169165
mock_find_home_config_files_fs.return_value = []
170166
scan_dir = cwd_path_fs / "projects_to_scan"
171167
scan_dir.mkdir(exist_ok=True)

tests/helpers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,11 @@ def write_config(config_path: pathlib.Path, content: str) -> pathlib.Path:
6161
def load_raw(data: str, fmt: t.Literal["yaml", "json"]) -> dict[str, t.Any]:
6262
"""Load configuration data via string value. Accepts yaml or json."""
6363
return ConfigReader._load(fmt=fmt, content=data)
64+
65+
66+
def save_config_yaml(config_file_path: pathlib.Path, data: dict[t.Any, t.Any]) -> None:
67+
"""Save a dictionary to a YAML file."""
68+
import yaml
69+
70+
yaml_content = yaml.dump(data, sort_keys=False, indent=2, default_flow_style=False)
71+
write_config(config_file_path, yaml_content)

0 commit comments

Comments
 (0)