38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
"""FRED observations and IRS SOI county income. No download."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from econ.fred import parse_observations
|
|
from econ.irs_soi import CountyIncome, parse_county_income
|
|
|
|
|
|
def test_fred_dot_value_is_missing():
|
|
rows = parse_observations({"observations": [{"date": "2024-01-01", "value": "."}]})
|
|
assert len(rows) == 1
|
|
assert rows[0].value is None
|
|
assert rows[0].year == 2024
|
|
assert rows[0].period == "2024-01-01"
|
|
|
|
|
|
def test_fred_missing_date_has_no_year():
|
|
rows = parse_observations({"observations": [{"date": "", "value": "1"}]})
|
|
assert rows[0].year is None
|
|
assert rows[0].value == 1.0
|
|
|
|
|
|
def test_county_income_keeps_the_fips_text():
|
|
rows = parse_county_income("fips,year,agi\n01001,2022,40000\n")
|
|
assert rows == (CountyIncome(fips="01001", year=2022, agi=40000),)
|
|
|
|
|
|
def test_blank_agi_is_none():
|
|
rows = parse_county_income("fips,year,agi\n01001,2022,\n")
|
|
assert rows[0].agi is None
|
|
|
|
|
|
def test_missing_column_raises():
|
|
with pytest.raises(ValueError):
|
|
parse_county_income("fips,year\n01001,2022\n")
|