Skip to content

test: add Test classes for the seven response models (#65) - #77

Open
tschm wants to merge 1 commit into
alihaskar:masterfrom
tschm:fix/65-test-layout-parity
Open

test: add Test classes for the seven response models (#65)#77
tschm wants to merge 1 commit into
alihaskar:masterfrom
tschm:fix/65-test-layout-parity

Conversation

@tschm

@tschm tschm commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Rhiza's check_test_layout requires every source class A to have a mirrored TestA. Seven response models had none, failing the gate.

Source Models Kind
api/interface.py PlotResult, ServerStatus TypedDict
api/routes.py InitDataResponse, SessionInfo, SessionListResponse, DeleteSessionResponse, StatusResponse BaseModel

Why mirroring rather than the opt-out

The issue offered a documented [tool.check_test_layout] enforce = false opt-out as the lighter option. I went the other way after reading the checker: enforce is all-or-nothing — there is no per-class exemption, only enforce, reason and exempt_dirs. Disabling it would also stop catching a genuinely missing test_<module>.py later, which is the part of the gate that currently passes and is worth keeping.

So the gate stays fully enforced.

The tests earn their place

They aren't schema tautologies — they pin contracts that can silently drift:

  • PlotResult / ServerStatus key sets are asserted against what plot() and get_server_status() actually return, on both the success and validation-failure paths. A field added to one and not the other now fails.
  • PlotResult.__total__ is False vs ServerStatus.__total__ is True documents why one type covers both success and failure shapes.
  • SessionInfo and StatusResponse are validated against live /api/sessions and /api/status payloads.
  • The BaseModel tests cover construction, required-field validation, nested coercion and the empty-listing case.

Style follows the existing TestDataResponse / TestErrorResponse classes.

Verification

$ check_test_layout.py
Test layout OK: tests mirror sources 1:1     (exit 0)

$ make test
172 passed  (154 -> 172, +18)  — Total coverage: 100.00%

Tests-only change — no src/ or behaviour touched.

Closes #65

Rhiza's check_test_layout requires every source class to have a mirrored
Test<Name>. Seven response models had none:

  interface.py  PlotResult, ServerStatus                (TypedDict)
  routes.py     InitDataResponse, SessionInfo,
                SessionListResponse, DeleteSessionResponse,
                StatusResponse                          (BaseModel)

Chose real mirroring over the [tool.check_test_layout] enforce=false
opt-out: the opt-out is all-or-nothing, so it would also stop catching a
genuinely missing test_<module>.py in future. The new tests pin contracts
worth pinning — the TypedDict key sets are checked against what plot() and
get_server_status() actually return, and two models are validated against
live endpoint payloads.

Follows the existing TestDataResponse/TestErrorResponse style.

Closes alihaskar#65

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 28, 2026 09:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds missing mirrored Test* classes for seven API response models so Rhiza’s check_test_layout gate passes while also asserting key aspects of the models’ runtime contracts.

Changes:

  • Added TestInitDataResponse, TestSessionInfo, TestSessionListResponse, TestDeleteSessionResponse, and TestStatusResponse to cover BaseModel response schemas and validate against live endpoint payloads.
  • Added TestPlotResult and TestServerStatus to cover TypedDict response contracts and compare declared keys vs real function outputs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/pycharting/api/test_routes.py Adds mirrored tests for five BaseModel response models in api.routes, including endpoint-payload validation.
tests/pycharting/api/test_interface.py Adds mirrored tests for two TypedDict response models in api.interface, checking declared keys and real return shapes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +553 to +559
def test_every_key_is_optional(self):
"""``total=False`` means success and failure shapes share one type."""
from pycharting.api.interface import PlotResult

assert PlotResult.__total__ is False
assert PlotResult.__required_keys__ == frozenset()

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.

Resolve test-layout parity for the 7 Pydantic response models

2 participants