Skip to content

test(cli): add CLI unit tests and enforce cli.py coverage#8

Merged
hampsterx merged 1 commit into
masterfrom
test/cli-coverage
Jun 19, 2026
Merged

test(cli): add CLI unit tests and enforce cli.py coverage#8
hampsterx merged 1 commit into
masterfrom
test/cli-coverage

Conversation

@hampsterx

@hampsterx hampsterx commented Jun 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • cli.py was excluded from the coverage gate (only the skipped-by-default smoke suite exercised it), so a CLI regression could land without failing CI.
  • Add tests/test_cli.py covering the documented exit-code contract: query happy path (JSON on stdout), SnowflakeError -> exit 1 + stderr, no subcommand -> exit 2 + help, --version, and the _json_default serializer for Decimal/datetime/date/time/bytes plus its TypeError branch.
  • Stub the network by monkeypatching SnowflakeClient.from_env to a FakeSnowflake-backed client, so the tests need no real account.
  • Drop cli.py from [tool.coverage.run] omit and mark the unreachable defensive return in main() with pragma: no cover (argparse only yields None or query).

Review

Internal: clean. External (Codex agentic, Kimi-agentic): both clean, no findings. Claude reviewer skipped (same harness).

Changes

  • tests/test_cli.py (new, +143)
  • pyproject.toml (coverage omit list)
  • snowflake_sql_api/cli.py (1-line pragma)

Test plan

  • coverage run -m pytest && coverage report: 189 passed, 5 skipped; cli.py 100%, total 94% (>= 89% gate)
  • pre-commit run --all-files clean (ruff, black, mypy, yaml/toml, private-key)

Summary by CodeRabbit

Release Notes

  • Tests

    • Added comprehensive test suite for the CLI covering version output, query execution, error handling, and JSON serialization for various data types.
  • Chores

    • Updated coverage configuration to include CLI module in tracking.

- cli.py was excluded from the coverage gate (only the skipped-by-default
  smoke suite exercised it), so a CLI regression could land without failing CI.
- Add tests/test_cli.py covering the documented exit-code contract: query
  happy path (JSON on stdout), SnowflakeError -> exit 1 + stderr, no subcommand
  -> exit 2 + help, --version, and the _json_default serializer for
  Decimal/datetime/date/time/bytes plus its TypeError branch.
- Stub the network by monkeypatching SnowflakeClient.from_env to a
  FakeSnowflake-backed client, so the tests need no real account.
- Drop cli.py from [tool.coverage.run] omit and mark the unreachable defensive
  return in main() with pragma: no cover (argparse only yields None or query).
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 95d1e962-1279-4320-8690-e719207012b2

📥 Commits

Reviewing files that changed from the base of the PR and between 9137d4e and feb1c17.

📒 Files selected for processing (3)
  • pyproject.toml
  • snowflake_sql_api/cli.py
  • tests/test_cli.py

📝 Walkthrough

Walkthrough

Adds a new tests/test_cli.py module with 143 lines covering argument parsing, --version, empty-argv help, query JSON output, non-native type serialization, error handling, and direct _json_default unit tests. pyproject.toml removes cli.py from the coverage omit list, and the unreachable argparse fallback in main gains # pragma: no cover.

Changes

CLI Test Coverage

Layer / File(s) Summary
Coverage config and pragma annotation
pyproject.toml, snowflake_sql_api/cli.py
pyproject.toml drops cli.py from the coverage omit array; the unreachable argparse fallback return 0 in main is marked # pragma: no cover.
CLI test suite
tests/test_cli.py
Introduces stub_from_env fixture monkeypatching SnowflakeClient.from_env with a FakeSnowflake; adds tests for build_parser(), --version exit, empty-argv help/exit-2, query JSON stdout, non-JSON-native type serialization (Decimal, datetime, date, time, bytes), query error path (exit 1, stderr), and parametrized _json_default unit tests including the TypeError branch.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop, hop, the CLI gets its test!
No branch left uncovered, no path unexpressed.
A stubby fake client stands in with a grin,
While pragma: no cover hides what can't be seen.
JSON defaults for Decimal and date—
Every assertion confirms our fate! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding CLI unit tests and enforcing coverage for cli.py through configuration updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/cli-coverage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@hampsterx hampsterx merged commit e4add3a into master Jun 19, 2026
7 checks passed
@hampsterx hampsterx deleted the test/cli-coverage branch June 19, 2026 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant