"""Tests for the QCEW Open Data CSV module. Offline tests parse a committed fixture (no network). The live test (opt-in via `-m live`) hits the real CSV service, which needs no API key and no quota. """ import os import pytest from bls_client import qcew FIXTURE = os.path.join(os.path.dirname(__file__), "fixtures", "qcew_dc_sample.csv") @pytest.fixture(scope="module") def dc_rows(): with open(FIXTURE) as f: return qcew.parse_csv(f.read()) def test_parse_returns_dict_rows(dc_rows): assert dc_rows and isinstance(dc_rows[0], dict) # core QCEW columns present for col in ("area_fips", "own_code", "industry_code", "annual_avg_emplvl", "annual_avg_wkly_wage"): assert col in dc_rows[0] def test_all_rows_are_dc_all_industries(dc_rows): assert all(r["area_fips"] == "11000" for r in dc_rows) assert all(r["industry_code"] == "10" for r in dc_rows) def test_filter_by_ownership(dc_rows): # ownership name resolves to its code, and total (own_code 0) exists total = qcew.filter_rows(dc_rows, own_code="total") assert len(total) == 1 assert int(total[0]["annual_avg_emplvl"]) > 0 def test_ownership_name_mapping(): assert qcew.OWNERSHIP["private"] == "5" assert qcew.OWNERSHIP["federal"] == "1" @pytest.mark.live def test_live_area_fetch(): rows = qcew.area("11000", 2024, "a") # DC annual, no key / no quota assert len(rows) > 100 private_total = qcew.filter_rows(rows, own_code="private", industry_code="10", agglvl_code="51") assert len(private_total) == 1 assert int(private_total[0]["annual_avg_emplvl"]) > 100_000 # DC private ~525k