""" Tests for the Object Mapper — synonym normalization and fuzzy matching. """ import pytest from src.utils.object_mapper import ( normalize_label, find_best_match, SYNONYM_MAP, ) class TestNormalizeLabel: """Tests for normalize_label().""" def test_known_synonym(self): assert normalize_label("mug") == "cup" def test_known_synonym_case_insensitive(self): assert normalize_label("MUG") == "cup" def test_unknown_label_passthrough(self): assert normalize_label("bottle") == "bottle" def test_whitespace_stripped(self): assert normalize_label(" mug ") == "cup" def test_container_to_bottle(self): assert normalize_label("container") == "bottle" def test_smartphone_to_cell_phone(self): assert normalize_label("smartphone") == "cell phone" class TestFindBestMatch: """Tests for find_best_match().""" @pytest.fixture def detected_labels(self) -> list[str]: return ["bottle", "cup", "box", "person", "laptop"] def test_exact_match(self, detected_labels): result = find_best_match("bottle", detected_labels) assert result == "bottle" def test_synonym_match(self, detected_labels): """'mug' should resolve to 'cup' via synonym normalization.""" result = find_best_match("mug", detected_labels) assert result == "cup" def test_container_matches_bottle(self, detected_labels): result = find_best_match("container", detected_labels) assert result == "bottle" def test_substring_match(self, detected_labels): result = find_best_match("lap", detected_labels) assert result == "laptop" def test_no_match_returns_none(self, detected_labels): result = find_best_match("xyznonexistent", detected_labels) assert result is None def test_empty_query(self, detected_labels): result = find_best_match("", detected_labels) # Empty normalizes to empty, no match expected assert result is None or isinstance(result, str) def test_empty_detected_labels(self): result = find_best_match("bottle", []) assert result is None