"""Test de fumée du graphique MA7D_DROP (nécessite plotly : .venv/bin/python).""" import importlib.util import io import sys import tempfile import unittest from contextlib import redirect_stdout from datetime import datetime, timezone from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "src")) import energy_check as ec # noqa: E402 HAS_PLOTLY = importlib.util.find_spec("plotly") is not None if HAS_PLOTLY: import energy_plot as ep VERMONT = ROOT / "vermont" def at(*args): return datetime(*args, tzinfo=timezone.utc) @unittest.skipUnless(HAS_PLOTLY, "plotly absent : lancer avec .venv/bin/python") class Plot(unittest.TestCase): @classmethod def setUpClass(cls): cls.series = ec.load_stations([str(VERMONT)])["VERMONT"] cls.result = ec.run(cls.series) def test_gaps_include_first_vermont_cut(self): self.assertIn((at(2026, 9, 27, 1), at(2026, 9, 27, 7)), ep.gaps(self.series["BusVoltage"])) def test_figure_has_all_series(self): fig = ep.figure("VERMONT", self.series, self.result, ec.periods(self.result["points"])) names = {t.name for t in fig.data} self.assertLessEqual({"BusVoltage", "moyenne 7 j", "référence (max 30 j)", "seuil", "écart"}, names) self.assertLessEqual(set(self.series) - {"BusVoltage"}, names) def test_cli_writes_html(self): with tempfile.TemporaryDirectory() as d, redirect_stdout(io.StringIO()): ep.main([str(VERMONT), "--out", d]) self.assertGreater((Path(d) / "VERMONT_energy.html").stat().st_size, 0) if __name__ == "__main__": unittest.main()