Files
ai-trade/signal_v2/tests/test_scheduler.py
gahusb 6cb5085118 test(signal_v2): add scheduler boundary tests at exact transitions
Code review noted missing boundary tests at:
- 09:00:00 (pre-market → market) → 60
- 15:30:00 (market → post-market) → 300
- 20:00:00 (post-market → overnight skip)

3 new tests, total 8 scheduler / 14 signal_v2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 03:45:55 +09:00

62 lines
1.9 KiB
Python

"""Tests for scheduler interval logic."""
from datetime import datetime
import pytest
from signal_v2.scheduler import _next_interval, _is_market_day, KST
def _kst(year, month, day, hour, minute=0):
return datetime(year, month, day, hour, minute, tzinfo=KST)
def test_next_interval_pre_market_5min():
now = _kst(2026, 5, 18, 8, 30) # Monday 08:30
assert _next_interval(now) == 300
def test_next_interval_market_open_1min():
now = _kst(2026, 5, 18, 10, 0) # Monday 10:00
assert _next_interval(now) == 60
def test_next_interval_post_market_5min():
now = _kst(2026, 5, 18, 17, 0) # Monday 17:00
assert _next_interval(now) == 300
def test_next_interval_overnight_skip_to_next_morning():
now = _kst(2026, 5, 18, 22, 0) # Monday 22:00
interval = _next_interval(now)
# Next polling: Tuesday 07:00 (9 hours away)
assert 9 * 3600 - 60 < interval < 9 * 3600 + 60
def test_next_interval_holiday_skip():
# 2026-05-05 어린이날 (Tuesday holiday)
now = _kst(2026, 5, 5, 10, 0)
assert _is_market_day(now) is False
interval = _next_interval(now)
# Next: 2026-05-06 (Wed) 07:00, ~21h away
assert 20 * 3600 < interval < 22 * 3600
def test_next_interval_at_market_open_boundary():
"""09:00:00 정확 second → 60초 (market 구간 진입)."""
now = _kst(2026, 5, 18, 9, 0) # Monday 09:00:00
assert _next_interval(now) == 60
def test_next_interval_at_market_close_boundary():
"""15:30:00 정확 second → 300초 (post-market 구간 진입)."""
now = _kst(2026, 5, 18, 15, 30) # Monday 15:30:00
assert _next_interval(now) == 300
def test_next_interval_at_polling_window_end_boundary():
"""20:00:00 정확 second → overnight skip (다음 영업일 07:00 까지)."""
now = _kst(2026, 5, 18, 20, 0) # Monday 20:00:00
interval = _next_interval(now)
# Next: Tuesday 07:00 — 11h away
assert 11 * 3600 - 60 < interval < 11 * 3600 + 60