gendesign/tradein-mvp/backend/tests/test_extract_short_addr.py
lekss361 a0d50bd282
All checks were successful
Deploy Trade-In / changes (push) Successful in 5s
Deploy Trade-In / build-frontend (push) Has been skipped
Deploy Trade-In / deploy (push) Successful in 32s
Deploy Trade-In / build-backend (push) Successful in 38s
feat(tradein-estimator): tiered house-match S→H→W (#507)
2026-05-24 12:41:12 +00:00

49 lines
1.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""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