Skip to content

Add test infrastructure: pytest, pytest-asyncio, respx#154

Merged
agners merged 4 commits into
home-assistant-libs:mainfrom
heikkih:feat/test-infrastructure
Apr 27, 2026
Merged

Add test infrastructure: pytest, pytest-asyncio, respx#154
agners merged 4 commits into
home-assistant-libs:mainfrom
heikkih:feat/test-infrastructure

Conversation

@heikkih
Copy link
Copy Markdown
Contributor

@heikkih heikkih commented Apr 23, 2026

Summary

This PR establishes a proper test suite for pyprusalink, replacing the current lint-only CI with real unit tests. It is the first in a planned series of improvements to both this library and the Home Assistant prusalink integration.

What's included

  • requirements-test.txt: adds pytest, pytest-asyncio, and respx
  • pyproject.toml: adds [tool.pytest.ini_options] with asyncio_mode = "auto" and corrects the Python classifier versions (3.9/3.10 → 3.11/3.12 to match CI)
  • .github/workflows/test.yml: extends linting to the tests/ directory and adds a pytest tests/ step
  • tests/conftest.py: shared fixtures
  • tests/test_client.py: covers ApiClient error handling (InvalidAuth on 401, Conflict on 409, NotFound on 404) and DigestAuthWorkaround behaviour (omits algorithm without qop, delegates to parent when qop is present)
  • tests/test_prusalink.py: happy-path coverage for all existing PrusaLink public methods (get_version, get_info, get_status, get_job, get_legacy_printer, cancel_job, pause_job, resume_job, get_file), including the 204 no-job case

All 15 tests pass in ~0.1s.

Planned follow-up PRs

Once this lands, the next PRs in the series will:

  1. Remove DigestAuthWorkaround — both upstream issues are now resolved (httpx 0.27.0, Feb 2024; Prusa firmware 5.2.0, Feb 2024). The workaround can be dropped once firmware 5.2.0+ is the minimum supported version.
  2. Add continue_job() — the missing complement to pause_job/resume_job for timelapse workflows.
  3. Type the meta field in JobFilePrint with a proper PrintFileMetadata TypedDict, exposing filament type, material name, estimated usage, layer height, etc.
  4. Expose transfer, storage, and camera sub-objects already returned by GET /api/v1/status but currently ignored.
  5. New endpoints: get_storage(), get_transfer(), get_camera_snapshot(), get_update_info().

The goal is to give the Home Assistant integration richer, well-typed data to work with — enabling sensors for filament type, storage free space, upload progress, live camera snapshots, and firmware update availability.

Test plan

  • pytest tests/ -v — 15 passed
  • flake8 pyprusalink tests — no errors
  • black --check pyprusalink tests — no reformats needed
  • isort --check pyprusalink tests — no changes needed

🤖 Generated with Claude Code

Adds a proper test suite to replace the lint-only CI. The tests cover:
- ApiClient error handling (InvalidAuth on 401, Conflict on 409, NotFound on 404)
- DigestAuthWorkaround behaviour (omits algorithm without qop, delegates to
  parent when qop is present)
- Happy-path coverage for all PrusaLink public methods

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@heikkih
Copy link
Copy Markdown
Contributor Author

heikkih commented Apr 23, 2026

Quick note:

  • I've got more PR's in the pipeline, but waiting on initial feedback before I'll proceed :)

Copy link
Copy Markdown
Contributor

@agners agners left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this!

Comment thread tests/conftest.py Outdated
Comment thread tests/__init__.py Outdated
Comment thread tests/test_client.py Outdated
heikkih and others added 2 commits April 27, 2026 17:00
- Rename conftest fixture to `pl` and use it in both test files
  instead of duplicating inline client setup
- Remove tests/__init__.py (not needed for pytest discovery)
- Replace hacky __bases__ monkey-patch with patch.object(DigestAuth, ...)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread tests/conftest.py Outdated
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@heikkih heikkih requested a review from agners April 27, 2026 19:32
@agners agners merged commit 5c99948 into home-assistant-libs:main Apr 27, 2026
2 checks passed
@heikkih heikkih deleted the feat/test-infrastructure branch April 28, 2026 11:44
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.

2 participants