Repository navigation
test(cyclopts): cover the reported-error exit codes - #76
Merged
Merged
Conversation
The cyclopts CLI template started new projects at 85% coverage: nothing exercised the FileNotFoundError, PermissionError and ConnectionError branches of `main`, nor `_fail`. A parametrized test checks each exit code and the `error: ...` line, plus a ConnectionError subclass. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01GyMoD8tx4oz1bpJ1tEL845
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
New projects generated with the cyclopts CLI (the default, also used by the
docstest case) started at 85% coverage. The no-CLI and Typer variants were already at 100%.Cause
main()maps three errors to sysexits codes through_fail():FileNotFoundError→ 66,PermissionError→ 77,ConnectionError→ 69. No test covered those branches (cli.pylines 63-64, 84, 86, 88). The existing tests covered only usage errors (2) and the catch-all crash (70).Change
A parametrized
test_main_reported_error, in the same monkeypatch style astest_main_unhandled_error. It swapsappfor a function that raises each error, then checks the exit code and that stderr is exactlyerror: <message>. A fourth case,ConnectionRefusedError, checks that a subclass lands on its parent's code, as the comment incli.pypromises.The template still sets no
fail_under, so a coverage drop is visible but doesn't fail CI.Verification
TMPDIR=/tmp uv run ctt -t cli_c -t docs(the three cyclopts variants) passes lint, tests and release. Each runs 9 tests, and coverage is 100% in all three (cli_c_vcs34/34,cli_c_no_vcs33/33,docs33/33 statements), up from 85%.Patching
cli.appinstead of the registered command is deliberate: these tests checkmain()'s mapping, and keep working when a project replaces the placeholder command or moves to subcommands only. Patchingapp.default_commandwould also test that cyclopts lets command exceptions through (checked by hand:FileNotFoundError→ exit 66), but it would break once there is no default command.🤖 Generated with Claude Code
https://claude.ai/code/session_01GyMoD8tx4oz1bpJ1tEL845