From 8f0b8477e655d29926211d0faceec64e2edf0462 Mon Sep 17 00:00:00 2001 From: glenn schrooyen Date: Mon, 9 Nov 2026 07:15:14 +0100 Subject: [PATCH] MAINT-21 review: two source scans read the split files too test_safety118's "size rule is gone" and test_validate's "no numeric maintenance_* fallback" read app/main.py only; the code they guard can now sit in app/ctl_*.py, where a regression passed unseen. Both read main_files.source() for main.py now. Tests only; no app change. Co-Authored-By: Claude Opus 5.5 --- goodwe_controller/test_safety118.py | 4 ++-- goodwe_controller/test_validate.py | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/goodwe_controller/test_safety118.py b/goodwe_controller/test_safety118.py index f6fe602..e9cb1a9 100644 --- a/goodwe_controller/test_safety118.py +++ b/goodwe_controller/test_safety118.py @@ -17,7 +17,6 @@ Mutating a module this file grades? Read MUTATION.md first (purge __pycache__). import asyncio import logging -from pathlib import Path import os # noqa: E402 import sys # noqa: E402 @@ -371,7 +370,8 @@ check("pv.unit_fault: None for a good unit and for a missing reading (has_readin pv.unit_fault(st(1, "kW")) is None and pv.unit_fault(None) is None and pv.unit_fault(st("unavailable")) is None and pv.unit_fault(st(1)) == "" and pv.unit_fault(st(1, "kWh")) == "kWh") -src = (Path(__file__).parent / "app" / "main.py").read_text(encoding="utf-8") +# MAINT-21: main.py and the files split from it (the forecast read is in ctl_inputs). +src = main_files.source() check("the size rule is gone from main.py", "abs(raw) < 50" not in src) print() diff --git a/goodwe_controller/test_validate.py b/goodwe_controller/test_validate.py index ea9c5df..6cfff7c 100644 --- a/goodwe_controller/test_validate.py +++ b/goodwe_controller/test_validate.py @@ -1028,6 +1028,11 @@ check("...and the drain SET is not clamped either, so the twin key the card " _srcs = {name: open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "app", name), encoding="utf-8").read() for name in ("main.py", "validate.py", "maintenance.py")} +# MAINT-21: main.py stands for itself and the files split from it. +sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), + "tools")) +import main_files # noqa: E402 +_srcs["main.py"] = main_files.source() _literals = {name: re.findall( r'"(maintenance_[a-z_]+)"\s*,\s*(-?\d+(?:\.\d+)?)\s*[,)]', src) for name, src in _srcs.items()}