test: de-flake volume-ratio test (real-clock dead zone, not plan 007)

compute_ratios bails when UTC now-16min precedes today's 08:00Z, i.e. nightly
~00:00-04:16 ET; the test's hardcoded 2026-07-06 bars made it KeyError at the
date rollover independent of any code change. Freeze the module clock to a
mid-session UTC time so the window is valid deterministically.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
momentum devandClaude Fable 5 committed 2026-07-14 00:36:00 -04:00
1 parent e2b3c1ceae
commit a12dc8a768
1 file changed
+20 -1
+20 -1
View File
@@ -32,7 +32,26 @@ class _Con:
return self
def test_compute_ratios_measures_and_skips_thin():
def test_compute_ratios_measures_and_skips_thin(monkeypatch):
# Freeze the clock inside the stub's bar-date window. compute_ratios bails
# (`end <= start`) when UTC now-16min is before today's 08:00Z — true nightly
# from ~00:00-04:16 ET — so with hardcoded 2026-07-06 bars this test flaked at
# the date rollover regardless of the stub data. Pin a mid-session UTC clock.
import research.ingestion.volume_ratio as vr
from datetime import date as _date, datetime as _dt, timezone
class _FrozenDT:
@staticmethod
def now(tz=None):
return _dt(2026, 7, 6, 18, 0, 0, tzinfo=tz or timezone.utc)
class _FrozenDate:
@staticmethod
def today():
return _date(2026, 7, 6)
monkeypatch.setattr(vr, "datetime", _FrozenDT)
monkeypatch.setattr(vr, "date", _FrozenDate)
r = compute_ratios(_Client(), ["GOOD", "DUST", "MISSING"])
assert r["GOOD"] == 25.0 # 12500 sip / 500 iex
assert "DUST" not in r # sip sample below floor -> untrusted