Skip to content

test: fix docstring/websocket gaps and mirror test layout - #51

Merged
alihaskar merged 1 commit into
alihaskar:masterfrom
tschm:fix-quality-findings
Jul 20, 2026
Merged

alihaskar merged 1 commit into
alihaskar:masterfrom
tschm:fix-quality-findings

Conversation

@tschm

@tschm tschm commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Addresses three test-quality findings (tracked on the tschm/pycharting fork as tschm#19, tschm#20, tschm#21):

#21 details

The layout checker enforces Test<SourceClass> parity in both directions, so the organizational grouping classes had to be dissolved:

  • Moved all test files into tests/pycharting/<subpkg>/test_<module>.py.
  • Flattened organizational grouping classes (TestHealthCheck, TestValidateInput, …) into module-level test functions.
  • Kept/added the Test<SourceClass> classes the checker requires: TestChartServer, TestDataManager, TestNoCacheStaticFiles, and new TestDataResponse, TestErrorResponse, TestDataValidationError.
  • Merged test_data_slicing.py → test_ingestion.py; folded test_import.py → test_interface.py.
  • Normalized a stray from src.pycharting... import to from pycharting....

Gates

Gate Result
make fmt ✅ PASS
make docs-coverage ✅ 100%
make test ✅ 148 passed, coverage 100%
check_test_layout.py ✅ exits 0

Net: +5 tests (new model/exception tests), same 100% source coverage.

🤖 Generated with Claude Code

)

- #19: add missing docstring to cleanup_globals._reset (docs-coverage 100%)
- #20: guard websocket route introspection against FastAPI _IncludedRouter
- #21: restructure tests/ to mirror src/pycharting/ so check_test_layout.py
  passes — flatten organizational grouping classes into module-level test
  functions, keep/add Test<SourceClass> classes (TestChartServer,
  TestDataManager, TestNoCacheStaticFiles, TestDataResponse, TestErrorResponse,
  TestDataValidationError), merge test_data_slicing into test_ingestion, fold
  test_import into test_interface.

Gates: fmt PASS, docs-coverage 100%, 148 tests PASS (coverage 100%), test-layout OK.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
from unittest.mock import MagicMock, patch

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(("", 0))

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

This PR improves test quality and maintainability by updating the test suite to (1) satisfy a test-layout parity checker that mirrors src/pycharting/, and (2) address test robustness/coverage gaps (docstring coverage and FastAPI route-list compatibility).

Changes:

  • Restructured tests/ into tests/pycharting/... to mirror the package layout; flattened several organizational Test* grouping classes into module-level tests while keeping required Test<SourceClass> parity classes.
  • Updated lifecycle tests to be compatible with newer FastAPI/Starlette route objects by reading route.path defensively.
  • Consolidated/relocated tests (e.g., folded import smoke tests into interface tests, merged slicing tests into ingestion-related coverage).

Reviewed changes

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

Show a summary per file
File Description
tests/test_server.py Removed legacy server tests file (moved under tests/pycharting/core/).
tests/test_interface.py Removed legacy interface tests file (moved under tests/pycharting/api/).
tests/test_import.py Removed standalone import smoke tests (folded into tests/pycharting/api/test_interface.py).
tests/test_data_slicing.py Removed legacy slicing tests file (coverage migrated under new layout).
tests/test_data_ingestion.py Removed legacy ingestion/validation tests file (coverage migrated under new layout).
tests/test_api_routes.py Removed legacy API routes tests file (moved under tests/pycharting/api/).
tests/pycharting/init.py Added test package root to mirror pycharting layout.
tests/pycharting/core/init.py Added core test package marker.
tests/pycharting/api/init.py Added api test package marker.
tests/pycharting/core/test_server.py Re-homed FastAPI server tests under mirrored layout and flattened most tests to module-level functions.
tests/pycharting/core/test_lifecycle.py Fixed imports (pycharting...), made websocket route enumeration defensive, and flattened several tests to module-level.
tests/pycharting/api/test_routes.py Re-homed API route tests under mirrored layout and added model-construction tests for response models.
tests/pycharting/api/test_interface.py Re-homed interface tests under mirrored layout, added missing _reset docstring, and folded in import smoke tests.
Comments suppressed due to low confidence (1)

tests/pycharting/core/test_lifecycle.py:159

  • This test starts/stops a real ChartServer but doesn't guarantee cleanup if an assertion fails mid-loop (e.g., server starts but the test errors before stop_server runs). That can leak background threads/ports and cascade failures in later tests in the same session.

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

"""DataResponse builds from the required index/range fields."""
from pycharting.api.routes import DataResponse

resp = DataResponse(index=[0, 1, 2], start_index=0, end_index=2, total_length=3)
@alihaskar
alihaskar merged commit ba1b49a into alihaskar:master Jul 20, 2026
26 checks passed
@tschm
tschm deleted the fix-quality-findings branch July 20, 2026 07:07
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.

4 participants