| 
 | 1 | +import pytest  | 
 | 2 | + | 
 | 3 | +from ingredient_parser.en import PreProcessor  | 
 | 4 | + | 
 | 5 | +@pytest.fixture  | 
 | 6 | +def p():  | 
 | 7 | +    """Define an empty PreProcessor object to use for testing the PreProcessor class methods."""  | 
 | 8 | +    return PreProcessor("")  | 
 | 9 | + | 
 | 10 | +class TestPreProcessor_remove_price_annotations:  | 
 | 11 | +    def test_remove_dollar_price(self, p):  | 
 | 12 | +        input_sentence = "1 cup flour ($0.20)"  | 
 | 13 | +        assert p._remove_price_annotations(input_sentence) == "1 cup flour "  | 
 | 14 | + | 
 | 15 | +    def test_remove_pound_price(self, p):  | 
 | 16 | +        input_sentence = "2 eggs (£1.50)"  | 
 | 17 | +        assert p._remove_price_annotations(input_sentence) == "2 eggs "  | 
 | 18 | + | 
 | 19 | +    def test_remove_euro_price(self, p):  | 
 | 20 | +        input_sentence = "3 tomatoes (€2.00)"  | 
 | 21 | +        assert p._remove_price_annotations(input_sentence) == "3 tomatoes "  | 
 | 22 | + | 
 | 23 | +    def test_remove_yen_price(self, p):  | 
 | 24 | +        input_sentence = "1 onion (¥100)"  | 
 | 25 | +        assert p._remove_price_annotations(input_sentence) == "1 onion "  | 
 | 26 | + | 
 | 27 | +    def test_remove_rupee_price(self, p):  | 
 | 28 | +        input_sentence = "1 potato (₹10.50)"  | 
 | 29 | +        assert p._remove_price_annotations(input_sentence) == "1 potato "  | 
 | 30 | + | 
 | 31 | +    def test_multiple_prices(self, p):  | 
 | 32 | +        input_sentence = "1 apple ($0.50) and 1 orange (£0.30)"  | 
 | 33 | +        assert p._remove_price_annotations(input_sentence) == "1 apple  and 1 orange "  | 
 | 34 | + | 
 | 35 | +    def test_no_price_annotation(self, p):  | 
 | 36 | +        input_sentence = "1 cup sugar"  | 
 | 37 | +        assert p._remove_price_annotations(input_sentence) == "1 cup sugar"  | 
 | 38 | + | 
 | 39 | +    def test_malformed_price_annotation(self, p):  | 
 | 40 | +        input_sentence = "1 cup flour ($0.20"  | 
 | 41 | +        assert p._remove_price_annotations(input_sentence) == "1 cup flour ($0.20"  | 
 | 42 | + | 
 | 43 | +    def test_price_with_comma(self, p):  | 
 | 44 | +        input_sentence = "1 steak (€1,200.00)"  | 
 | 45 | +        assert p._remove_price_annotations(input_sentence) == "1 steak "  | 
 | 46 | + | 
 | 47 | +    def test_price_with_multiple_decimals(self, p):  | 
 | 48 | +        input_sentence = "1 cheese ($1.99) and 1 bread ($2.49)"  | 
 | 49 | +        assert p._remove_price_annotations(input_sentence) == "1 cheese  and 1 bread "  | 
 | 50 | + | 
 | 51 | +    def test_price_annotation_at_start(self, p):  | 
 | 52 | +        input_sentence = "($0.20) 1 cup flour"  | 
 | 53 | +        assert p._remove_price_annotations(input_sentence) == " 1 cup flour"  | 
 | 54 | + | 
 | 55 | +    def test_price_annotation_in_middle(self, p):  | 
 | 56 | +        input_sentence = "1 cup ($0.20) flour"  | 
 | 57 | +        assert p._remove_price_annotations(input_sentence) == "1 cup  flour"  | 
 | 58 | + | 
 | 59 | +    def test_price_annotation_at_end(self, p):  | 
 | 60 | +        input_sentence = "1 cup flour ($0.20)"  | 
 | 61 | +        assert p._remove_price_annotations(input_sentence) == "1 cup flour "  | 
 | 62 | + | 
 | 63 | +    def test_price_annotation_with_leading_space(self, p):  | 
 | 64 | +        input_sentence = "1 cup flour ( $0.20)"  | 
 | 65 | +        assert p._remove_price_annotations(input_sentence) == "1 cup flour "  | 
 | 66 | + | 
 | 67 | +    def test_price_annotation_with_inner_spaces(self, p):  | 
 | 68 | +        input_sentence = "1 cup flour ( $ 0.20 )"  | 
 | 69 | +        assert p._remove_price_annotations(input_sentence) == "1 cup flour "  | 
 | 70 | + | 
 | 71 | +    def test_price_annotation_with_multiple_spaces(self, p):  | 
 | 72 | +        input_sentence = "1 cup flour (  $  0.20  )"  | 
 | 73 | +        assert p._remove_price_annotations(input_sentence) == "1 cup flour "  | 
 | 74 | + | 
 | 75 | +    def test_price_annotation_with_tab_spaces(self, p):  | 
 | 76 | +        input_sentence = "1 cup flour (\t$0.20\t)"  | 
 | 77 | +        assert p._remove_price_annotations(input_sentence) == "1 cup flour "  | 
 | 78 | + | 
 | 79 | +    def test_price_annotation_with_mixed_whitespace(self, p):  | 
 | 80 | +        input_sentence = "1 cup flour ( \t $ 0.20  )"  | 
 | 81 | +        assert p._remove_price_annotations(input_sentence) == "1 cup flour "  | 
 | 82 | + | 
 | 83 | +    def test_non_price_parenthetical_remains(self, p):  | 
 | 84 | +        input_sentence = "1 cup flour (organic)"  | 
 | 85 | +        assert p._remove_price_annotations(input_sentence) == "1 cup flour (organic)"  | 
 | 86 | + | 
 | 87 | +    def test_multiple_non_price_parentheticals(self, p):  | 
 | 88 | +        input_sentence = "2 eggs (free-range) (large)"  | 
 | 89 | +        assert p._remove_price_annotations(input_sentence) == "2 eggs (free-range) (large)"  | 
 | 90 | + | 
 | 91 | +    def test_mixed_price_and_non_price_parentheticals(self, p):  | 
 | 92 | +        input_sentence = "1 cup flour ($0.20) (organic)"  | 
 | 93 | +        assert p._remove_price_annotations(input_sentence) == "1 cup flour  (organic)"  | 
 | 94 | + | 
 | 95 | +    def test_non_price_parenthetical_with_spaces(self, p):  | 
 | 96 | +        input_sentence = "1 cup flour ( see note )"  | 
 | 97 | +        assert p._remove_price_annotations(input_sentence) == "1 cup flour ( see note )"  | 
 | 98 | + | 
 | 99 | +    def test_non_price_parenthetical_with_numbers(self, p):  | 
 | 100 | +        input_sentence = "1 cup flour (2nd batch)"  | 
 | 101 | +        assert p._remove_price_annotations(input_sentence) == "1 cup flour (2nd batch)"  | 
0 commit comments