You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.1 KiB
Python

"""Replay test: same fixture → same parser output (determinism)."""
import pytest
SAMPLE_TEXT = """
Item 2.02 Results of Operations
Apple today announced record quarterly revenue of $124.3 billion.
Guidance raised for Q2. Demand remains strong. Margin expansion driven by Services.
Customer additions in enterprise continue. Adjusted EPS excludes non-GAAP items.
"""
@pytest.mark.replay
def test_parser_determinism():
"""Running parser twice on same text yields identical output."""
from libs.parser.rule_parser import RuleBasedParser
p = RuleBasedParser()
metadata = {"filing_date": "2026-01-29", "accepted_at_utc": "2026-01-29T21:05:00Z"}
out1 = p.parse("DOC::test", "8-K", SAMPLE_TEXT, metadata)
out2 = p.parse("DOC::test", "8-K", SAMPLE_TEXT, metadata)
assert out1.event_type == out2.event_type
assert out1.event_direction == out2.event_direction
assert out1.guidance.status == out2.guidance.status
assert out1.confidence.overall == out2.confidence.overall
assert out1.filing_time_bucket == out2.filing_time_bucket
@pytest.mark.replay
def test_parser_determinism_negative_text():
"""Determinism holds for negative/mixed text too."""
from libs.parser.rule_parser import RuleBasedParser
negative_text = """
Item 2.02 Results of Operations
Revenue below expectations. Guidance lowered. Demand softness observed.
Convertible note offering announced. Margin compression continues.
"""
p = RuleBasedParser()
metadata = {"filing_date": "2026-02-01"}
out1 = p.parse("DOC::test2", "8-K", negative_text, metadata)
out2 = p.parse("DOC::test2", "8-K", negative_text, metadata)
assert out1.event_type == out2.event_type
assert out1.guidance.status == out2.guidance.status
@pytest.mark.replay
def test_feature_determinism(sample_parser_output):
"""Event features are deterministic for same parser output."""
from libs.features.event_features import compute_event_features
f1 = compute_event_features(sample_parser_output)
f2 = compute_event_features(sample_parser_output)
assert f1 == f2