"""Tests for the Thai macro backdrop collector.""" from __future__ import annotations import unittest from app import macro_thai def _page_html() -> str: return """
Private Consumption Index (%YoY) 4.9% Jun 2026
Private Investment Index (%YoY) 18.1% Jun 2026
Manufacturing Production Index (%YoY) -3.1% Jun 2026
Headline Inflation (%YoY) 1.95% July 2026
Core Inflation (%YoY) 1.34% July 2026
Unemployment (%share to Labor force) 0.93% Q1/2026
No. of tourists year-to-date (million) 16.2 Jun 2026
""" class MacroThaiParseTest(unittest.TestCase): def test_parses_all_indicators(self) -> None: snap = macro_thai.parse_macro_thai_html(_page_html()) self.assertEqual(snap.private_consumption_yoy, 4.9) self.assertEqual(snap.private_investment_yoy, 18.1) self.assertEqual(snap.manufacturing_yoy, -3.1) self.assertEqual(snap.headline_inflation_yoy, 1.95) self.assertEqual(snap.unemployment_pct, 0.93) self.assertEqual(snap.tourists_ytd_mn, 16.2) def test_no_data_raises(self) -> None: with self.assertRaises(macro_thai.MacroThaiError): macro_thai.parse_macro_thai_html("nothing here") def test_to_dict_full(self) -> None: d = macro_thai.parse_macro_thai_html(_page_html()).to_dict() self.assertEqual(d["source"], "bot.thai-economy") self.assertIn("periods", d) if __name__ == "__main__": unittest.main()