import pandas as pd from src.matching.match_products import name_key, size_bucket, brand_key, num_tokens, MULTI_RE from src.cleaning.units import parse_size, size_residual, strip_accents def test_keys(): assert brand_key("Häagen-Dazs") == "haagendazs" assert name_key("Beurre végétal salé 454 g", "Becel") != name_key("Beurre végétal non salé 454 g", "Becel") assert num_tokens(name_key("Lait 2 %", "")) != num_tokens(name_key("Lait 3,25 %", "")) a, b = parse_size("12 x 355 ml"), parse_size("6 x 710 ml") assert a.qty == b.qty and size_bucket(a.qty, a.base, a.pack) != size_bucket(b.qty, b.base, b.pack) assert size_residual("340 g, calibre 21-25") == "21-25 calibre".replace("-", " ") or "calibre" in size_residual("340 g, calibre 21-25") assert "cons" not in size_residual("12x355 mL, Cons. 1,20 $/emb.") and size_residual("6x710.0 ml, 0,15 $/100ml") == "" assert MULTI_RE.search(strip_accents("BISCUITS DARE WHIPPET OU ULTIME")) and not MULTI_RE.search("Yogourt grec vanille")