Skip to content

test: add narrative/solar-arc tests and CI workflow#1

Open
kochj23 wants to merge 1 commit into
jasonacox-sam:mainfrom
kochj23:tests-and-ci
Open

test: add narrative/solar-arc tests and CI workflow#1
kochj23 wants to merge 1 commit into
jasonacox-sam:mainfrom
kochj23:tests-and-ci

Conversation

@kochj23

@kochj23 kochj23 commented Jul 1, 2026

Copy link
Copy Markdown

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 into DayTracker. No network and no real Powerwall are needed; only urllib is mocked, and that only for the two fetch() resilience tests. Coverage includes:
    • parse() typed CSV parsing (and coercion of hostile/malformed remote values)
    • solar-arc tracking: online / peak / fade timestamps and battery-full detection
    • _kwh() sign-filtered energy estimation and _pct_solar() fraction
    • the CSV round-trip that lets sunlog survive a mid-day restart
    • the English narrative() output: online/peak/fade times, battery delta ("up/down N% from …"), grid import/export lines, and one-line story selection
  • .github/workflows/ci.yml — runs pytest on Python 3.9–3.13.

The suite is stdlib + pytest only, matching the project's dependency-light style.

Test categories covered

  1. Securityfetch() swallows network errors and returns None (a failed poll never crashes the daemon); parse() coerces injected/non-numeric CSV field values to 0.0 instead of raising.
  2. Performancesave_raw_csv() appends only new readings; a call with nothing new neither rewrites nor duplicates on-disk rows.
  3. Retry — N/A: fetch() makes a single request and returns None on failure; recovery is the next scheduled poll, not in-call retry/backoff. Marked with an explanatory @pytest.mark.skip placeholder rather than omitted.
  4. Unitparse() typing, _pct_solar() fraction, _kwh() sign filtering, and ingest() arc/battery-full tracking.
  5. Integration — CSV written by save_raw_csv() reloads via load_from_csv() into a fresh tracker that reproduces the same arc and identical narrative; save_narrative() writes the summary file.
  6. Functional — a full sunny day yields a narrative naming the online/peak/fade times, battery delta and export; a 100%-solar day selects the "nearly perfect solar day" story.
  7. Frame — boundary cases: no data at all, a no-sun day (falling battery reads "down", "No sun today" story), and _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

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>
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.

1 participant