"""Date-range resolver tests — bounds parsing + dispatch on column type.""" import pytest from api.composer.dates import _bounds, resolve_date_range from api.composer.types import PickValidationError from api.recon.types import Column def test_bounds_year(): assert _bounds("1996") == ("1996-01-01", "1996-12-31") def test_bounds_quarter_q1(): assert _bounds("1996-Q1") == ("1996-01-01", "1996-03-31") def test_bounds_quarter_q3(): assert _bounds("1996-Q3") == ("1996-07-01", "1996-09-30") def test_bounds_unsupported_raises(): with pytest.raises(PickValidationError, match="unsupported"): _bounds("Q3-1996") def test_resolve_real_date_column(): col = Column(name="date", sql_type="DATE", nullable=False) out = resolve_date_range("1996", col, '"l"."date"') assert out == "\"l\".\"date\" BETWEEN '1996-01-01' AND '1996-12-31'" def test_resolve_timestamp_column(): col = Column(name="created_at", sql_type="TIMESTAMP WITHOUT TIME ZONE", nullable=True) out = resolve_date_range("1996-Q2", col, '"x"."created_at"') assert out == "\"x\".\"created_at\" BETWEEN '1996-04-01' AND '1996-06-30'" def test_resolve_yymmdd_semantic_type(): col = Column(name="date", sql_type="INTEGER", nullable=False, semantic_type="date_yymmdd") out = resolve_date_range("1996", col, '"l"."date"') assert "TO_DATE(LPAD(" in out assert "BETWEEN '1996-01-01' AND '1996-12-31'" in out def test_resolve_unsupported_column_type_raises(): col = Column(name="x", sql_type="TEXT", nullable=True) with pytest.raises(PickValidationError, match="not supported"): resolve_date_range("1996", col, '"x"."x"')