scripts: pl_calc, vision_schema, calendar_parse + tests (67 passing)
This commit is contained in:
88
tests/test_calendar_yaml.py
Normal file
88
tests/test_calendar_yaml.py
Normal file
@@ -0,0 +1,88 @@
|
||||
"""Tests for the YAML loader and news-window logic in calendar_parse."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import textwrap
|
||||
from datetime import date, time
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
from scripts.calendar_parse import ( # noqa: E402
|
||||
is_in_news_window,
|
||||
load_calendar,
|
||||
)
|
||||
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
CALENDAR_PATH = REPO_ROOT / "calendar_evenimente.yaml"
|
||||
|
||||
|
||||
def test_load_calendar() -> None:
|
||||
events = load_calendar(CALENDAR_PATH)
|
||||
assert isinstance(events, list)
|
||||
assert len(events) > 0
|
||||
required = {"name", "cadence", "time_ro", "severity", "window_before_min", "window_after_min"}
|
||||
for ev in events:
|
||||
missing = required - set(ev.keys())
|
||||
assert not missing, f"event {ev.get('name')!r} missing fields: {missing}"
|
||||
|
||||
|
||||
def test_load_calendar_bad_version(tmp_path: Path) -> None:
|
||||
bad = tmp_path / "bad.yaml"
|
||||
bad.write_text(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
schema_version: 99
|
||||
events: []
|
||||
"""
|
||||
).strip()
|
||||
+ "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
with pytest.raises(ValueError):
|
||||
load_calendar(bad)
|
||||
|
||||
|
||||
def _scheduled(date_str: str, time_str: str, before: int, after: int, severity: str = "extrem") -> dict:
|
||||
return {
|
||||
"name": "Test",
|
||||
"cadence": "scheduled",
|
||||
"date": date_str,
|
||||
"time_ro": time_str,
|
||||
"severity": severity,
|
||||
"window_before_min": before,
|
||||
"window_after_min": after,
|
||||
}
|
||||
|
||||
|
||||
class TestWindowBoundaries:
|
||||
def setup_method(self) -> None:
|
||||
self.cal = [_scheduled("2026-05-06", "15:30", 15, 15)]
|
||||
self.d = date(2026, 5, 6)
|
||||
|
||||
def test_window_inside_boundary(self) -> None:
|
||||
assert is_in_news_window(self.d, time(15, 14), self.cal) is False # 1 min before lower bound
|
||||
assert is_in_news_window(self.d, time(15, 15), self.cal) is True # lower bound inclusive
|
||||
assert is_in_news_window(self.d, time(15, 45), self.cal) is True # upper bound inclusive
|
||||
|
||||
def test_window_outside(self) -> None:
|
||||
assert is_in_news_window(self.d, time(15, 14), self.cal) is False
|
||||
assert is_in_news_window(self.d, time(15, 46), self.cal) is False
|
||||
|
||||
|
||||
def test_severity_filter_mediu_excluded() -> None:
|
||||
# JOLTS-like event with severity 'mediu' at 17:00 — even smack on time, no Set C trigger.
|
||||
cal = [_scheduled("2026-05-06", "17:00", 10, 10, severity="mediu")]
|
||||
assert is_in_news_window(date(2026, 5, 6), time(17, 0), cal) is False
|
||||
assert is_in_news_window(date(2026, 5, 6), time(17, 5), cal) is False
|
||||
|
||||
|
||||
def test_fomc_powell_window() -> None:
|
||||
"""Real FOMC Powell Press Apr from calendar_evenimente.yaml (2026-04-29 21:30 RO, 0/45)."""
|
||||
cal = load_calendar(CALENDAR_PATH)
|
||||
assert is_in_news_window(date(2026, 4, 29), time(21, 35), cal) is True
|
||||
assert is_in_news_window(date(2026, 4, 29), time(22, 16), cal) is False
|
||||
Reference in New Issue
Block a user