File size: 3,629 Bytes
26b8deb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"""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