"""Tests for the Refining/Energy (EIA) parser.""" from __future__ import annotations import unittest from app import refining_energy def _eia_html() -> str: return """

Wholesale Spot Petroleum Prices, 8/21/26 Close

ProductAreaPricePercentChange*
Crude Oil ($/barrel)WTI87.21-2.8
Brent96.92+3.1
Louisiana Light90.71-2.7
Gasoline (RBOB) ($/gallon)NY Harbor3.42+2.3
Gulf Coast3.52+1.3
3:2:1 Crack Spread ($/barrel)Gulf Coast (LLS)71.10+5.7
Low-Sulfur Diesel ($/gallon)NY Harbor4.47-2.1
""" class RefiningParseTest(unittest.TestCase): def test_parses_crack_spread_and_crudes(self) -> None: snap = refining_energy.parse_refining_html(_eia_html()) self.assertEqual(snap.crack_spread, 71.10) self.assertEqual(snap.crack_spread_change, 5.7) self.assertEqual(snap.wti_crude, 87.21) self.assertEqual(snap.brent_crude, 96.92) self.assertEqual(snap.gasoline_gulf, 3.52) def test_missing_table_raises(self) -> None: with self.assertRaises(refining_energy.RefiningError): refining_energy.parse_refining_html("no data") def test_negative_change_parses(self) -> None: html_text = """
3:2:1 Crack Spread ($/barrel)Gulf Coast (LLS)60.00-2.5
""" snap = refining_energy.parse_refining_html(html_text) self.assertEqual(snap.crack_spread, 60.00) self.assertEqual(snap.crack_spread_change, -2.5) def test_crack_spread_fallback_when_area_missing(self) -> None: # If the row lacks the "Gulf Coast" area cell, fall back to last two cells. html_text = """
3:2:1 Crack Spread ($/barrel)71.10+5.7
""" snap = refining_energy.parse_refining_html(html_text) self.assertEqual(snap.crack_spread, 71.10) self.assertEqual(snap.crack_spread_change, 5.7) if __name__ == "__main__": unittest.main()