From 33e92ca54022af45548119d023ce69ba89c53e28 Mon Sep 17 00:00:00 2001 From: Jack McCarthy Date: Tue, 6 Oct 2026 02:14:12 -0400 Subject: [PATCH 1/2] Use _refused in the last three refusal tests These tests repeated _refused's checks by hand. Its unchanged-parent assertion also covers the absent target and the empty stage glob they asserted. --- tests/test_project_create.py | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/tests/test_project_create.py b/tests/test_project_create.py index 6ab210d9..1a992cc9 100644 --- a/tests/test_project_create.py +++ b/tests/test_project_create.py @@ -424,11 +424,7 @@ def test_open_parent_descriptor_rechecks_the_generated_module_filename_limit( def test_rejects_unknown_release_before_writing(tmp_path: Path) -> None: - target = tmp_path / "project" - with pytest.raises(ProjectCreateError) as raised: - create_project(target, package="Project", release_id="unknown") - assert raised.value.code == "project-release-unknown" - assert not target.exists() + _refused(tmp_path / "project", "project-release-unknown", release_id="unknown") def test_omitted_release_uses_the_recommended_release(tmp_path: Path) -> None: @@ -840,12 +836,7 @@ def corrupt(*args, **kwargs): monkeypatch.setattr(create_module, "_build_project_plan", corrupt) - with pytest.raises(ProjectCreateError) as raised: - create_project(target, package="Project", release_id=_RELEASE) - - assert raised.value.code == "project-create-validation-failed" - assert not target.exists() - assert not list(tmp_path.glob(".autoform-new-*")) + _refused(target, "project-create-validation-failed") @pytest.mark.parametrize("corruption", ["container", "relative", "content", "mode"]) @@ -1719,12 +1710,7 @@ def test_group_writable_parent_is_refused_with_a_remedy(tmp_path: Path) -> None: parent.mkdir(mode=0o700) parent.chmod(0o775) - with pytest.raises(ProjectCreateError) as raised: - create_project(parent / "Project", package="Project", release_id=_RELEASE) - - assert raised.value.code == "project-parent-unsafe" - assert "chmod g-w,o-w" in raised.value.message - assert not list(parent.iterdir()) + assert "chmod g-w,o-w" in _refused(parent / "Project", "project-parent-unsafe").message _NEEDS_PERMISSIONS = pytest.mark.skipif( From 553d79c2d3e99a317a08983bcac3f27b1aa89338 Mon Sep 17 00:00:00 2001 From: Jack McCarthy Date: Tue, 6 Oct 2026 02:14:13 -0400 Subject: [PATCH 2/2] Drop the unreachable hash-length branch in _git_blob_id Its only caller passes the length of an object ID that _committed_scaffold_entries has already matched against 40 or 64 hex digits. The hashlib.new ValueError fallback stays; test_plugin_pin_is_empty_when_git_digests_are_unavailable pins it. --- autoform_cli/scaffold.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/autoform_cli/scaffold.py b/autoform_cli/scaffold.py index 0bd85682..2244f193 100644 --- a/autoform_cli/scaffold.py +++ b/autoform_cli/scaffold.py @@ -355,9 +355,7 @@ def _committed_scaffold_entries( def _git_blob_id(content: bytes, length: int) -> str | None: - algorithm = {40: "sha1", 64: "sha256"}.get(length) - if algorithm is None: - return None + algorithm = {40: "sha1", 64: "sha256"}[length] try: digest = hashlib.new(algorithm, usedforsecurity=False) except ValueError: