from isora_hf.config import DATAFLOWS from isora_hf.structures import annotations, indicator_row, normalize_indicator_type def test_normalize_indicator_type_handles_case_and_trailing_space(): assert normalize_indicator_type("Currency ") == "currency" assert normalize_indicator_type("Counting") == "count" assert normalize_indicator_type("") == "unspecified" assert normalize_indicator_type(None) == "unspecified" assert normalize_indicator_type("NA") == "unspecified" def test_annotations_flatten_and_drop_empties(): code = { "annotations": [ {"title": "A", "text": " x "}, {"title": "B", "text": ""}, {"title": "C", "value": "v"}, ] } assert annotations(code) == {"A": "x", "C": "v"} def test_indicator_row_detects_derived_currency_and_thousands(): code = { "id": "337_059", "name": "Active taxpayers (in thousands in local currency)", "annotations": [ {"title": "DissemScale", "text": "Currency"}, {"title": "DissemCurrency", "text": "NC"}, {"title": "OriginalFormula", "text": "+95860_38/+398_004"}, {"title": "Suppress", "text": "Yes"}, ], } row = indicator_row(DATAFLOWS[2], "6.0.6", code) assert row["is_derived"] is True assert row["is_local_currency"] is True assert row["label_mentions_thousands"] is True assert row["indicator_type"] == "currency" assert row["suppressed_in_source_tables"] is True assert row["questionnaire_generation"] == "ISORA 2020+" def test_declared_monetary_codes_excludes_mistyped_counts(): import pandas as pd from isora_hf.structures import declared_monetary_codes frame = pd.DataFrame( [ { "indicator_code": "A", "label": "Total revenue collections - Net", "indicator_type": "currency", }, { "indicator_code": "B", "label": "Number of complaints for the fiscal year", "indicator_type": "currency", }, { "indicator_code": "C", "label": "Opening stock of tax debt cases", "indicator_type": "currency", }, { "indicator_code": "D", "label": "Cases under litigation - Value of cases resolved", "indicator_type": "currency", }, {"indicator_code": "E", "label": "Staff total", "indicator_type": "count"}, ] ) assert declared_monetary_codes(frame) == {"A", "D"}