"""Tests for the Siamchart dividend-history parser (real ex-date/DPS).""" from __future__ import annotations import unittest from app.siamchart import parse_dividend_history _DIV_TABLE = """
ประวัติการปันผล
วันที่ปันผล
2002-04-042.5
2024-02-291.2
2025-03-061.3
2025-10-010.9
""" class ParseDividendHistoryTest(unittest.TestCase): def test_extracts_chronological_dated_dps(self): rows = parse_dividend_history(_DIV_TABLE) self.assertEqual( rows, [("2002-04-04", 2.5), ("2024-02-29", 1.2), ("2025-03-06", 1.3), ("2025-10-01", 0.9)], ) def test_returns_empty_when_no_table(self): self.assertEqual(parse_dividend_history("no dividend table"), []) def test_deduplicates_identical_rows(self): html = _DIV_TABLE + '2025-03-061.3' rows = parse_dividend_history(html) self.assertEqual(len([r for r in rows if r == ("2025-03-06", 1.3)]), 1) def test_skips_non_date_rows(self): html = """
ประวัติการปันผล
N/A2.0
2020-01-011.0
""" rows = parse_dividend_history(html) self.assertEqual(rows, [("2020-01-01", 1.0)]) if __name__ == "__main__": unittest.main()