Download tests/test_normalization.py from Zayeemk/DocuPurse: direct link, hf CLI and curl.
- Browser
- Download file 3.63 kB
-
https://huggingface.co/spaces/Zayeemk/DocuPurse/resolve/main/tests/test_normalization.py
- Command line
-
hf download hf://spaces/Zayeemk/DocuPurse/tests/test_normalization.py
-
curl -L -o test_normalization.py https://huggingface.co/spaces/Zayeemk/DocuPurse/resolve/main/tests/test_normalization.py
3.63 kB
| """Tests for the normalizer module - no LLM calls required.""" | |
| import pytest | |
| from decimal import Decimal | |
| from src.normalizer import normalise_money, normalise_date, normalise_quantity, detect_currency_from_string | |
| class TestNormaliseMoney: | |
| def test_simple_integer(self): | |
| assert normalise_money("1250") == Decimal("1250") | |
| def test_with_commas(self): | |
| assert normalise_money("1,250.00") == Decimal("1250.00") | |
| def test_indian_format(self): | |
| assert normalise_money("1,25,000.50") == Decimal("125000.50") | |
| def test_rupee_symbol(self): | |
| assert normalise_money("Rs. 1,500") == Decimal("1500") | |
| def test_rupee_unicode(self): | |
| result = normalise_money("\u20b91,250") | |
| assert result == Decimal("1250") | |
| def test_dollar_symbol(self): | |
| assert normalise_money("$2,500.99") == Decimal("2500.99") | |
| def test_euro_symbol(self): | |
| assert normalise_money("\u20ac500.00") == Decimal("500.00") | |
| def test_european_format(self): | |
| # 1.250,50 -> 1250.50 | |
| assert normalise_money("1.250,50") == Decimal("1250.50") | |
| def test_negative_parentheses(self): | |
| assert normalise_money("(500.00)") == Decimal("-500.00") | |
| def test_none_input(self): | |
| assert normalise_money(None) is None | |
| def test_invalid_string(self): | |
| assert normalise_money("not a number") is None | |
| def test_inr_currency_code(self): | |
| assert normalise_money("INR 1500") == Decimal("1500") | |
| def test_zero(self): | |
| assert normalise_money("0") == Decimal("0") | |
| def test_decimal_precision(self): | |
| assert normalise_money("2070.00") == Decimal("2070.00") | |
| class TestNormaliseDate: | |
| def test_iso_format(self): | |
| assert normalise_date("2026-08-18") == "2026-08-18" | |
| def test_ddmmyyyy_slash(self): | |
| assert normalise_date("18/08/2026") == "2026-08-18" | |
| def test_ddmmyyyy_dash(self): | |
| assert normalise_date("18-08-2026") == "2026-08-18" | |
| def test_textual_long(self): | |
| assert normalise_date("18 August 2026") == "2026-08-18" | |
| def test_textual_short(self): | |
| assert normalise_date("Aug 18, 2026") == "2026-08-18" | |
| def test_none_input(self): | |
| assert normalise_date(None) is None | |
| def test_empty_string(self): | |
| assert normalise_date("") is None | |
| def test_invalid_date(self): | |
| result = normalise_date("not a date") | |
| assert result is None | |
| def test_invalid_year(self): | |
| # Year 1800 is outside our acceptable range | |
| result = normalise_date("1800-01-01") | |
| assert result is None | |
| def test_already_normalised(self): | |
| assert normalise_date("2026-09-17") == "2026-09-17" | |
| class TestNormaliseQuantity: | |
| def test_integer(self): | |
| assert normalise_quantity("2") == Decimal("2") | |
| def test_with_decimal(self): | |
| assert normalise_quantity("2.5") == Decimal("2.5") | |
| def test_with_commas(self): | |
| assert normalise_quantity("1,000") == Decimal("1000") | |
| def test_none(self): | |
| assert normalise_quantity(None) is None | |
| def test_invalid(self): | |
| assert normalise_quantity("abc") is None | |
| class TestDetectCurrency: | |
| def test_rupee_symbol(self): | |
| assert detect_currency_from_string("\u20b91500") == "INR" | |
| def test_dollar(self): | |
| assert detect_currency_from_string("$500") == "USD" | |
| def test_euro(self): | |
| assert detect_currency_from_string("\u20ac250.00") == "EUR" | |
| def test_inr_code(self): | |
| assert detect_currency_from_string("INR 1500") == "INR" | |
| def test_no_currency(self): | |
| assert detect_currency_from_string("1500") is None | |