face-intel / tests /unit /test_location_core.py
Marwan
Restructure + add reverse face search (PimEyes-style)
f5eeb1c
Raw
History Blame Contribute Delete
4.86 kB
"""Unit tests for cores.location — geography, language, plates."""
from __future__ import annotations
from cores.location import (
coords_to_country, coordinate_to_country, coords_to_city_estimate,
detect_script, script_to_regions, text_to_country_hints,
plate_format_to_country,
LocationEvidenceCollector, LocationEstimator,
)
class TestGeography:
def test_usa_coordinates(self):
# New York
assert coords_to_country(40.7, -74.0) == "United States"
def test_france_coordinates(self):
# Paris
assert coords_to_country(48.85, 2.35) == "France"
def test_japan_coordinates(self):
# Tokyo
assert coords_to_country(35.68, 139.76) == "Japan"
def test_ocean_coordinates_returns_none(self):
# Middle of the Pacific
assert coords_to_country(0.0, -160.0) is None
def test_coordinate_to_country_confidence(self):
# Center of France — high confidence
result = coordinate_to_country(47.0, 2.0)
assert result["country"] == "France"
assert result["confidence"] > 0.5
def test_city_estimate_near_major_city(self):
result = coords_to_city_estimate(40.7, -74.0) # near NYC
assert result is not None
assert result["city"] == "New York"
def test_city_estimate_far_from_cities(self):
# Middle of ocean
result = coords_to_city_estimate(0.0, -160.0)
assert result is None
class TestLanguageDetection:
def test_latin_script(self):
assert detect_script("Hello World") == "latin"
def test_cyrillic_script(self):
assert detect_script("Привет мир") == "cyrillic"
def test_arabic_script(self):
assert detect_script("مرحبا") == "arabic"
def test_cjk_script(self):
assert detect_script("你好世界") == "cjk"
def test_hangul_script(self):
assert detect_script("안녕하세요") == "hangul"
def test_thai_script(self):
assert detect_script("สวัสดี") == "thai"
def test_empty_text(self):
assert detect_script("") == "unknown"
def test_script_to_regions_cyrillic(self):
regions = script_to_regions("cyrillic")
countries = [r["country"] for r in regions]
assert "Russia" in countries
def test_text_to_country_hints_keyword(self):
hints = text_to_country_hints("I visited London last summer")
countries = [h["country"] for h in hints]
assert "United Kingdom" in countries
class TestPlateFormats:
def test_french_plate(self):
result = plate_format_to_country("AB123CD")
assert result is not None
assert result["country"] == "France"
def test_uk_plate(self):
result = plate_format_to_country("AB12CDE")
assert result is not None
assert result["country"] == "United Kingdom"
def test_spanish_plate(self):
result = plate_format_to_country("1234ABC")
assert result is not None
assert result["country"] == "Spain"
def test_russian_plate(self):
result = plate_format_to_country("A123BC77")
assert result is not None
assert result["country"] == "Russia"
def test_empty_plate(self):
assert plate_format_to_country("") is None
class TestLocationEstimator:
def test_gps_only(self):
collector = LocationEvidenceCollector()
collector.add_gps(48.85, 2.35) # Paris
estimator = LocationEstimator()
result = estimator.estimate(collector.evidence, gps={"lat": 48.85, "lon": 2.35})
assert len(result.candidate_countries) > 0
assert result.candidate_countries[0]["country"] == "France"
assert result.candidate_countries[0]["confidence"] > 0.5
def test_ocr_text_evidence(self):
collector = LocationEvidenceCollector()
collector.add_ocr_text("Привет мир") # Russian
estimator = LocationEstimator()
result = estimator.estimate(collector.evidence)
countries = [c["country"] for c in result.candidate_countries]
assert "Russia" in countries
def test_no_evidence(self):
collector = LocationEvidenceCollector()
estimator = LocationEstimator()
result = estimator.estimate(collector.evidence)
assert result.candidate_countries == []
assert result.overall_confidence == 0.0
def test_conflicting_evidence(self):
collector = LocationEvidenceCollector()
# GPS says France
collector.add_gps(48.85, 2.35)
# OCR says Russia (conflict)
collector.add_ocr_text("Привет мир")
estimator = LocationEstimator()
result = estimator.estimate(collector.evidence, gps={"lat": 48.85, "lon": 2.35})
# GPS should win but conflict is noted
assert len(result.candidate_countries) > 0