from datetime import datetime, timedelta, timezone from app.services.oee import calculate_oee_metrics def test_calculate_oee_metrics() -> None: metrics = calculate_oee_metrics( planned_time_sec=3600, downtime_sec=600, total_cycles=100, performance_time_sec=2500, theoretical_cycle_time_sec=25, total_produced_qty=200, scrap_qty=10, ) assert round(metrics.availability, 4) == 0.8333 assert round(metrics.performance, 4) == 0.8333 assert round(metrics.quality, 4) == 0.95 assert round(metrics.oee, 4) == 0.6597 def test_future_window_uses_current_time_bound(monkeypatch) -> None: from app.services import oee fixed_now = datetime(2026, 6, 14, 12, 0, tzinfo=timezone.utc) class FixedDateTime(datetime): @classmethod def now(cls, tz=None): return fixed_now if tz else fixed_now.replace(tzinfo=None) monkeypatch.setattr(oee, "datetime", FixedDateTime) start = datetime(2026, 6, 14, 0, 0, tzinfo=timezone.utc) end = datetime(2026, 6, 15, 0, 0, tzinfo=timezone.utc) assert oee.overlap_seconds(start, fixed_now, start, end) == timedelta(hours=12).total_seconds()