49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
"""Unit tests for _extract_short_addr in app.services.estimator.
|
||
|
||
Covers real Ekaterinburg address formats: full admin chain, Россия/РФ prefix,
|
||
apartment stripped, prospect keyword, korpus stripped, non-street fallback, None passthrough.
|
||
"""
|
||
|
||
from app.services.estimator import _extract_short_addr
|
||
|
||
|
||
def test_full_admin_chain() -> None:
|
||
assert _extract_short_addr(
|
||
"Свердловская область, г. Екатеринбург, Склад, ул. Заводская, д. 44-а"
|
||
) == "ул. Заводская, д. 44-а"
|
||
|
||
|
||
def test_russia_prefix() -> None:
|
||
assert _extract_short_addr(
|
||
"Россия, Екатеринбург, ул. Малышева, 1"
|
||
) == "ул. Малышева, 1"
|
||
|
||
|
||
def test_apt_stripped() -> None:
|
||
out = _extract_short_addr("Екатеринбург, ул. Ленина, 5, кв. 12")
|
||
assert out is not None
|
||
assert "кв" not in out
|
||
assert out.startswith("ул. Ленина")
|
||
|
||
|
||
def test_prospekt_keyword() -> None:
|
||
out = _extract_short_addr("г. Екатеринбург, проспект Ленина, 50")
|
||
assert out is not None
|
||
assert out.startswith("проспект Ленина")
|
||
|
||
|
||
def test_korp_stripped() -> None:
|
||
out = _extract_short_addr("Екатеринбург, ул. Крауля, 48, корп. 2")
|
||
assert out is not None
|
||
assert "корп" not in out.lower()
|
||
|
||
|
||
def test_no_street_keyword_returns_fallback() -> None:
|
||
# Should not crash; either returns stripped str or None.
|
||
out = _extract_short_addr("Industrial zone X")
|
||
assert out is None or "Industrial" in out
|
||
|
||
|
||
def test_none_passthrough() -> None:
|
||
assert _extract_short_addr(None) is None
|
||
assert _extract_short_addr("") is None
|