# Home-Ka — pipeline sanity tests (run: python3 -m pytest tests/ or python3 tests/test_pipeline.py) from __future__ import annotations import sys import tempfile import unittest from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) class PipelineTest(unittest.TestCase): @classmethod def setUpClass(cls): # isolated database from homeka import db cls._tmp = tempfile.TemporaryDirectory() db.DB_PATH = type(db.DB_PATH)(cls._tmp.name) / "test.db" db._SCHEMA_READY = False def test_normalize(self): from homeka.normalize import (normalize_state, normalize_status, normalize_property_type, parse_price, parse_lot_sqft, normalize_zip) self.assertEqual(normalize_state("Texas"), "TX") self.assertEqual(normalize_state("tx."), "TX") self.assertEqual(normalize_zip("78701-1234"), "78701") self.assertEqual(parse_price("$1.25M"), 1_250_000) self.assertEqual(parse_price("$459,000"), 459_000) self.assertEqual(parse_lot_sqft("1.89 acres"), round(1.89 * 43_560)) self.assertEqual(normalize_status("Active Under Contract"), "pending") self.assertEqual(normalize_property_type("SingleFamilyResidence"), "Single Family") def test_property_match_and_dedup(self): from homeka import db, quality from homeka.schema import Listing a = Listing(source="s1", external_id="A1", url="u1", street_address="123 North Main Street", city="Austin", state="TX", zip_code="78701", property_type="House", list_price=500000, description="x" * 60, images=["https://x/a.jpg"]).finalize() b = Listing(source="s2", external_id="B1", url="u2", street_address="123 N Main St", city="Austin", state="TX", zip_code="78701", property_type="House", list_price=502000, description="y" * 60, images=["https://x/b.jpg"]).finalize() con = db.connect() db.sync_source(con, "s1", [a]) db.sync_source(con, "s2", [b]) pids = [r["property_id"] for r in con.execute("SELECT property_id FROM listings")] self.assertEqual(pids[0], pids[1]) # same physical property self.assertEqual(db.refresh_dedup(con), 1) # ±1% price → one hidden q = quality.refresh(con) self.assertEqual(q["published"], 2) con.close() def test_reso_passthrough(self): from homeka.schema import Listing l = Listing(source="s", external_id="1", url="u", details={ "ListPrice": 725000, "City": "Denver", "StateOrProvince": "CO", "PostalCode": "80202", "BedroomsTotal": 4, "BathroomsFull": 2, "BathroomsHalf": 1, "LivingArea": 2400, "YearBuilt": 2001, "StandardStatus": "Active", "ParcelNumber": "123-45", }).finalize() self.assertEqual(l.list_price, 725000) self.assertEqual(l.state, "CO") self.assertEqual(l.bathrooms, 2.5) self.assertEqual(l.year_built, 2001) self.assertEqual(l.apn, "123-45") if __name__ == "__main__": unittest.main()