|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import csv |
3 | 4 | from pathlib import Path |
4 | 5 |
|
5 | 6 | import pytest |
@@ -30,6 +31,94 @@ def test_import_official_events_normalizes_to_event_schema(tmp_path: Path) -> No |
30 | 31 | assert rows[-1]["confidence"] == "low" |
31 | 32 |
|
32 | 33 |
|
| 34 | +def test_legacy_input_defaults_entity_schema_fields_and_serializes_stably(tmp_path: Path) -> None: |
| 35 | + output = tmp_path / "events.csv" |
| 36 | + |
| 37 | + rows = import_official_events(ROOT / "examples/official_records.example.csv", output) |
| 38 | + |
| 39 | + assert all(row["entity_match_type"] == "unverified" for row in rows) |
| 40 | + assert all(row["match_evidence"] == "" for row in rows) |
| 41 | + assert all(row["relationship_type"] == "" for row in rows) |
| 42 | + with output.open(newline="", encoding="utf-8") as handle: |
| 43 | + assert next(csv.reader(handle)) == [ |
| 44 | + "event_id", |
| 45 | + "event_date", |
| 46 | + "symbol", |
| 47 | + "event_type", |
| 48 | + "direction", |
| 49 | + "confidence", |
| 50 | + "source_url", |
| 51 | + "notes", |
| 52 | + "entity_match_type", |
| 53 | + "match_evidence", |
| 54 | + "relationship_type", |
| 55 | + ] |
| 56 | + |
| 57 | + |
| 58 | +def test_entity_schema_fields_are_imported_and_normalized() -> None: |
| 59 | + record = OfficialRecord( |
| 60 | + record_id="entity-record", |
| 61 | + record_date="2026-01-10", |
| 62 | + symbol="EVT", |
| 63 | + source_type="government_filing", |
| 64 | + event_type="disclosure_buy", |
| 65 | + direction="bullish", |
| 66 | + source_url="https://www.sec.gov/example/entity-record", |
| 67 | + summary="Entity evidence.", |
| 68 | + entity_match_type="direct_beneficiary", |
| 69 | + match_evidence="Named beneficiary in filing.", |
| 70 | + relationship_type="supplier", |
| 71 | + ) |
| 72 | + |
| 73 | + assert normalize_records([record])[0] == { |
| 74 | + "event_id": "official-government-filing-entity-record", |
| 75 | + "event_date": "2026-01-10", |
| 76 | + "symbol": "EVT", |
| 77 | + "event_type": "disclosure_buy", |
| 78 | + "direction": "bullish", |
| 79 | + "confidence": "high", |
| 80 | + "source_url": "https://www.sec.gov/example/entity-record", |
| 81 | + "notes": "Entity evidence.", |
| 82 | + "entity_match_type": "direct_beneficiary", |
| 83 | + "match_evidence": "Named beneficiary in filing.", |
| 84 | + "relationship_type": "supplier", |
| 85 | + } |
| 86 | + |
| 87 | + |
| 88 | +@pytest.mark.parametrize("entity_match_type", ["issuer", "direct_beneficiary", "industry_context", "unverified"]) |
| 89 | +def test_entity_match_type_accepts_only_contract_values(entity_match_type: str) -> None: |
| 90 | + record = OfficialRecord( |
| 91 | + record_id="entity-record", |
| 92 | + record_date="2026-01-10", |
| 93 | + symbol="EVT", |
| 94 | + source_type="government_filing", |
| 95 | + event_type="disclosure_buy", |
| 96 | + direction="bullish", |
| 97 | + source_url="https://www.sec.gov/example/entity-record", |
| 98 | + summary="Entity evidence.", |
| 99 | + entity_match_type=entity_match_type, |
| 100 | + ) |
| 101 | + |
| 102 | + normalize_records([record]) |
| 103 | + |
| 104 | + |
| 105 | +def test_entity_match_type_rejects_unknown_values() -> None: |
| 106 | + record = OfficialRecord( |
| 107 | + record_id="entity-record", |
| 108 | + record_date="2026-01-10", |
| 109 | + symbol="EVT", |
| 110 | + source_type="government_filing", |
| 111 | + event_type="disclosure_buy", |
| 112 | + direction="bullish", |
| 113 | + source_url="https://www.sec.gov/example/entity-record", |
| 114 | + summary="Entity evidence.", |
| 115 | + entity_match_type="inferred", |
| 116 | + ) |
| 117 | + |
| 118 | + with pytest.raises(ValueError, match="unsupported entity_match_type"): |
| 119 | + normalize_records([record]) |
| 120 | + |
| 121 | + |
33 | 122 | def test_government_records_reject_non_gov_urls() -> None: |
34 | 123 | record = OfficialRecord( |
35 | 124 | record_id="bad-media-record", |
|
0 commit comments