- macro_thai.py scrapes bot.or.th/en/thai-economy.html (server-rendered, no auth) - private consumption +4.9%, private investment +18.1%, mfg -3.1%, headline inflation 1.95%, core 1.34%, unemployment 0.93%, tourists YTD 16.2mn - 3 tests; live verified; macro backdrop layer (req #6)
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
"""Tests for the Thai macro backdrop collector."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import unittest
|
|
|
|
from app import macro_thai
|
|
|
|
|
|
def _page_html() -> str:
|
|
return """
|
|
<html><body>
|
|
<div>Private Consumption Index (%YoY) 4.9% Jun 2026</div>
|
|
<div>Private Investment Index (%YoY) 18.1% Jun 2026</div>
|
|
<div>Manufacturing Production Index (%YoY) -3.1% Jun 2026</div>
|
|
<div>Headline Inflation (%YoY) 1.95% July 2026</div>
|
|
<div>Core Inflation (%YoY) 1.34% July 2026</div>
|
|
<div>Unemployment (%share to Labor force) 0.93% Q1/2026</div>
|
|
<div>No. of tourists year-to-date (million) 16.2 Jun 2026</div>
|
|
</body></html>
|
|
"""
|
|
|
|
|
|
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("<html>nothing here</html>")
|
|
|
|
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()
|