scripts: pl_calc, vision_schema, calendar_parse + tests (67 passing)
This commit is contained in:
88
tests/test_set_calc.py
Normal file
88
tests/test_set_calc.py
Normal file
@@ -0,0 +1,88 @@
|
||||
"""Tests for calc_set + utc_to_ro in calendar_parse."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from datetime import date, time
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
from scripts.calendar_parse import ( # noqa: E402
|
||||
calc_set,
|
||||
load_calendar,
|
||||
utc_to_ro,
|
||||
)
|
||||
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
CALENDAR_PATH = REPO_ROOT / "calendar_evenimente.yaml"
|
||||
|
||||
|
||||
def _cal():
|
||||
return load_calendar(CALENDAR_PATH)
|
||||
|
||||
|
||||
# Reference weekdays used below (verified via datetime):
|
||||
# 2026-05-13 Wed 2026-05-12 Tue 2026-05-14 Thu
|
||||
# 2026-05-11 Mon 2026-05-15 Fri
|
||||
# 2026-04-29 Wed (FOMC Powell Press Apr — Set C trigger)
|
||||
|
||||
|
||||
def test_a1_mid() -> None:
|
||||
assert calc_set(date(2026, 5, 13), time(16, 50), "Wed", _cal()) == "A1"
|
||||
|
||||
|
||||
def test_a1_boundary_low() -> None:
|
||||
assert calc_set(date(2026, 5, 12), time(16, 35), "Tue", _cal()) == "A1"
|
||||
|
||||
|
||||
def test_a1_boundary_high() -> None:
|
||||
assert calc_set(date(2026, 5, 14), time(16, 59), "Thu", _cal()) == "A1"
|
||||
|
||||
|
||||
def test_a2_sweet_spot() -> None:
|
||||
assert calc_set(date(2026, 5, 13), time(17, 30), "Wed", _cal()) == "A2"
|
||||
|
||||
|
||||
def test_a3() -> None:
|
||||
assert calc_set(date(2026, 5, 12), time(18, 30), "Tue", _cal()) == "A3"
|
||||
|
||||
|
||||
def test_b() -> None:
|
||||
assert calc_set(date(2026, 5, 14), time(22, 15), "Thu", _cal()) == "B"
|
||||
|
||||
|
||||
def test_c_fomc() -> None:
|
||||
# 2026-04-29 is Wed; would otherwise hit a time band — but FOMC Powell Press window dominates.
|
||||
assert calc_set(date(2026, 4, 29), time(21, 35), "Wed", _cal()) == "C"
|
||||
|
||||
|
||||
def test_d_mon() -> None:
|
||||
assert calc_set(date(2026, 5, 11), time(17, 0), "Mon", _cal()) == "D"
|
||||
|
||||
|
||||
def test_d_fri() -> None:
|
||||
assert calc_set(date(2026, 5, 15), time(17, 0), "Fri", _cal()) == "D"
|
||||
|
||||
|
||||
def test_other() -> None:
|
||||
# Tue 13:00 — not Mon/Fri, no news, before any A-band.
|
||||
assert calc_set(date(2026, 5, 12), time(13, 0), "Tue", _cal()) == "Other"
|
||||
|
||||
|
||||
def test_dst_boundary_oct_2026() -> None:
|
||||
"""DST ends on Sun 2026-10-25 at 04:00 RO (clocks go back to 03:00).
|
||||
|
||||
Just before the shift, 00:30 UTC = 03:30 RO (EEST, UTC+3). The conversion must
|
||||
pick the pre-shift offset and yield 03:30 — not 02:30 (which would be an
|
||||
off-by-one-hour bug from naive +2h).
|
||||
"""
|
||||
d_ro, t_ro, dow = utc_to_ro("2026-10-25", "00:30")
|
||||
assert d_ro == date(2026, 10, 25)
|
||||
assert t_ro == time(3, 30)
|
||||
assert dow == "Sun"
|
||||
|
||||
# After the shift, 01:30 UTC also maps to 03:30 RO (EET, UTC+2) — sanity check.
|
||||
d_ro2, t_ro2, _ = utc_to_ro("2026-10-25", "01:30")
|
||||
assert (d_ro2, t_ro2) == (date(2026, 10, 25), time(3, 30))
|
||||
Reference in New Issue
Block a user