# tests/test_utils.py (Enhanced version of your existing file) import pytest from utils.data_processing import GTINProcessor, PriceProcessor class TestGTINProcessor: def setup_method(self): self.processor = GTINProcessor() def test_normalize_valid_gtin(self): """Test GTIN normalization with valid inputs""" # Test EAN-13 assert self.processor.normalize("1234567890123") == "1234567890123" # Test UPC-A (12 digits) assert self.processor.normalize("123456789012") == "123456789012" # Test with decimal point assert self.processor.normalize("123456789012.0") == "123456789012" # Test EAN-8 assert self.processor.normalize("12345678") == "12345678" def test_normalize_invalid_gtin(self): """Test GTIN normalization with invalid inputs""" assert self.processor.normalize("") is None assert self.processor.normalize(None) is None assert self.processor.normalize("abc") is None # Test short number (gets padded) assert self.processor.normalize("123") == "000000000123" def test_normalize_gtin_with_formatting(self): """Test GTIN normalization with various formatting""" # Test with spaces assert self.processor.normalize("123 456 789 012") == "123456789012" # Test with dashes assert self.processor.normalize("123-456-789-012") == "123456789012" # Test with mixed formatting assert self.processor.normalize("123 456-789 012") == "123456789012" def test_validate_gtin(self): """Test GTIN validation""" assert self.processor.validate("1234567890123") is True assert self.processor.validate("123456789012") is True assert self.processor.validate("12345678") is True assert self.processor.validate("123") is False assert self.processor.validate("") is False assert self.processor.validate(None) is False def test_gtin_checksum_validation(self): """Test GTIN checksum validation if implemented""" # This test would verify checksum calculation if your GTINProcessor implements it # For now, we'll test the structure validation assert self.processor.validate("1234567890123") is True assert self.processor.validate("12345678901234") is True # 14 digits assert self.processor.validate("123456789012345") is False # 15 digits class TestPriceProcessor: def setup_method(self): self.processor = PriceProcessor() def test_parse_price_currency_eur(self): """Test EUR price parsing""" price, currency = self.processor.parse_price_currency("8.26 EUR") assert price == "8.26" assert currency == "EUR" # Test with euro symbol price, currency = self.processor.parse_price_currency("8.26 €") assert price == "8.26" assert currency == "EUR" def test_parse_price_currency_usd(self): """Test USD price parsing""" price, currency = self.processor.parse_price_currency("$12.50") assert price == "12.50" assert currency == "USD" price, currency = self.processor.parse_price_currency("12.50 USD") assert price == "12.50" assert currency == "USD" def test_parse_price_currency_comma_decimal(self): """Test price parsing with comma as decimal separator""" price, currency = self.processor.parse_price_currency("8,26 EUR") assert price == "8.26" assert currency == "EUR" def test_parse_invalid_price(self): """Test invalid price parsing""" price, currency = self.processor.parse_price_currency("") assert price is None assert currency is None price, currency = self.processor.parse_price_currency(None) assert price is None assert currency is None def test_parse_price_edge_cases(self): """Test edge cases in price parsing""" # Test price without currency price, currency = self.processor.parse_price_currency("15.99") assert price == "15.99" # currency might be None or default value # Test currency before price price, currency = self.processor.parse_price_currency("EUR 25.50") assert price == "25.50" assert currency == "EUR" # Test with multiple decimal places price, currency = self.processor.parse_price_currency("12.999 USD") assert price == "12.999" assert currency == "USD"