test: add narrative/solar-arc tests and CI workflow#1
Open
kochj23 wants to merge 1 commit into
Open
Conversation
Adds the project's first test suite plus a GitHub Actions CI workflow. tests/test_sunlog.py drives DayTracker with synthetic readings (no network, no real Powerwall) to cover the daily-narrative / solar-arc logic: solar online/peak/fade times, battery delta, grid import/export estimation, CSV round-trip on restart, and the English one-line summary selection. .github/workflows/ci.yml runs pytest on Python 3.9-3.13. Test categories: Security, Performance, Retry (N/A placeholder), Unit, Integration, Functional, Frame. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sunlog had no tests and no CI. This PR adds both:
tests/test_sunlog.py— exercises the daily-narrative / solar-arc logic directly by feeding synthetic readings intoDayTracker. No network and no real Powerwall are needed; onlyurllibis mocked, and that only for the twofetch()resilience tests. Coverage includes:parse()typed CSV parsing (and coercion of hostile/malformed remote values)_kwh()sign-filtered energy estimation and_pct_solar()fractionnarrative()output: online/peak/fade times, battery delta ("up/down N% from …"), grid import/export lines, and one-line story selection.github/workflows/ci.yml— runspyteston Python 3.9–3.13.The suite is stdlib + pytest only, matching the project's dependency-light style.
Test categories covered
fetch()swallows network errors and returnsNone(a failed poll never crashes the daemon);parse()coerces injected/non-numeric CSV field values to0.0instead of raising.save_raw_csv()appends only new readings; a call with nothing new neither rewrites nor duplicates on-disk rows.fetch()makes a single request and returnsNoneon failure; recovery is the next scheduled poll, not in-call retry/backoff. Marked with an explanatory@pytest.mark.skipplaceholder rather than omitted.parse()typing,_pct_solar()fraction,_kwh()sign filtering, andingest()arc/battery-full tracking.save_raw_csv()reloads viaload_from_csv()into a fresh tracker that reproduces the same arc and identical narrative;save_narrative()writes the summary file._kwh()returning 0.0 with fewer than two samples.Verification
pytest tests/→ 14 passed, 1 skipped (the Retry N/A placeholder).🤖 Generated with Claude Code