"""Tests for scaffold input validation.""" from pathlib import Path import pytest from new_python.scaffold import ScaffoldError, target_dir, validate_name @pytest.mark.parametrize( "bad", [ "Demo-Project", "demo_project", "-demo", "demo-", "demo--project", "demo project", "demo1", "demo.project", "", ], ) def test_validate_name_refuses_invalid_names_with_the_rule(bad): """Names outside lowercase-words-with-hyphens refuse, stating the rule.""" with pytest.raises(ScaffoldError) as exc: validate_name(bad) assert "lowercase" in str(exc.value) def test_validate_name_accepts_dashed_and_single_words(): """Valid forms pass through unchanged.""" assert validate_name("demo-project") == "demo-project" assert validate_name("demo") == "demo" def test_target_dir_refuses_existing_directory(tmp_path): """An existing target directory refuses loudly with the path.""" (tmp_path / "demo-project").mkdir() with pytest.raises(ScaffoldError) as exc: target_dir("demo-project", tmp_path) assert "exists" in str(exc.value) assert "demo-project" in str(exc.value) 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"