Skip to content

Cover login, cancel, exceptions and image run wrapper with tests - #517

Merged
wRAR merged 2 commits into
scrapinghub:masterfrom
hammadqureshi-web:cover-login-cancel-exceptions-wrapper
Nov 12, 2026
Merged

wRAR merged 2 commits into
scrapinghub:masterfrom
hammadqureshi-web:cover-login-cancel-exceptions-wrapper

Conversation

@hammadqureshi-web

Copy link
Copy Markdown
Contributor

Summary

Brings shub/login.py, shub/cancel.py and shub/image/run/wrapper.py to 100% line and branch coverage, and adds direct tests for shub/exceptions.py.

  • login: retrying after an invalid API key, and _is_valid_apikey itself (status code handling and the URL built from the endpoint), which the existing tests always mocked.
  • cancel: --force skipping the confirmation prompt, and an unexpected error from parse_job_key becoming a SubcommandException.
  • image/run/wrapper: main(), and running the module as a script (same runpy approach as tests/test_main.py).
  • exceptions: already fully covered through other tests; added direct tests for exit codes, default and custom messages, and print_warning.

Notes

  • The wrapper tests patch os.mkfifo with create=True, since it does not exist on Windows.
  • The new login test uses tmp_path instead of isolated_filesystem, which Click deprecates.
  • Tests only, no changes to shub/.

Test plan

  • pytest --cov=shub --cov-branch shub tests: 399 passed, 3 skipped; the four files at 100%.
  • Touched test files on Python 3.10 (with python-dotenv==1.0.0) and 3.14: all pass.
  • Wrapper tests pass with os.mkfifo removed, to mimic Windows.
  • Mutation check: breaking each newly covered line makes a new test fail (12 of 12).
  • pre-commit run --all-files: passes.

🤖 Generated with Claude Code

Add tests for the lines and branches that were still uncovered:

- login: retrying after an invalid API key, and _is_valid_apikey itself
  (status code handling and the URL built from the endpoint), which the
  existing tests always mocked.
- cancel: --force skipping the confirmation prompt, and an unexpected
  error from parse_job_key becoming a SubcommandException.
- image/run/wrapper: main() and running the module as a script.
- exceptions: was already fully covered through other tests; add direct
  tests for exit codes, default and custom messages, and print_warning.

The wrapper tests patch os.mkfifo with create=True because it does not
exist on Windows, where CI also runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.61%. Comparing base (2194e29) to head (fbda1eb).
⚠️ Report is 15 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #517      +/-   ##
==========================================
+ Coverage   93.10%   94.61%   +1.51%     
==========================================
  Files          38       38              
  Lines        2567     3269     +702     
==========================================
+ Hits         2390     3093     +703     
+ Misses        177      176       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AdrianAtZyte

Copy link
Copy Markdown
Member

Thanks! I am not sure tests/test_exceptions.py is worth it: the exit code checks just repeat the values from shub/exceptions.py, and the file adds no coverage. Please, drop it, or keep only test_print_warning.

@AdrianAtZyte
AdrianAtZyte requested a review from wRAR October 27, 2026 09:11
The exit code checks repeated the values from shub/exceptions.py, and
shub/exceptions.py stays at 100% coverage without them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hammadqureshi-web

Copy link
Copy Markdown
Contributor Author

Please, drop it, or keep only test_print_warning.

Done in fbda1eb: kept only test_print_warning. shub/exceptions.py stays at 100% coverage.

@wRAR wRAR closed this Nov 12, 2026
@wRAR wRAR reopened this Nov 12, 2026
@wRAR
wRAR merged commit 9a9236f into scrapinghub:master Nov 12, 2026
54 checks passed
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.

3 participants