Add scaffold parent selection: --dir defaults to cwd

This commit is contained in:
jay
2026-11-09 13:30:42 -05:00
parent 29306b0f25
commit a57075dc2d
2 changed files with 28 additions and 1 deletions
+19 -1
View File
@@ -4,7 +4,7 @@ from pathlib import Path
import pytest
from new_python.scaffold import ScaffoldError, target_dir, validate_name
from new_python.scaffold import ScaffoldError, parent_dir, target_dir, validate_name
@pytest.mark.parametrize(
@@ -46,3 +46,21 @@ def test_target_dir_refuses_existing_directory(tmp_path):
def test_target_dir_resolves_parent_slash_name(tmp_path: Path):
"""A fresh target resolves to parent/name."""
assert target_dir("demo-project", tmp_path) == tmp_path / "demo-project"
def test_parent_dir_defaults_to_cwd(monkeypatch, tmp_path: Path):
"""Without --dir the parent is the current directory."""
monkeypatch.chdir(tmp_path)
assert parent_dir(None) == tmp_path
def test_parent_dir_uses_the_explicit_path(tmp_path: Path):
"""An explicit --dir selects the parent directory."""
assert parent_dir(tmp_path) == tmp_path
def test_parent_dir_refuses_missing_directory(tmp_path: Path):
"""A --dir that is not an existing directory refuses loudly."""
with pytest.raises(ScaffoldError) as exc:
parent_dir(tmp_path / "nope")
assert "--dir" in str(exc.value)