SPB Git forge

spb/home-ka

Public
10commits 1branches 0releases
793.0 KBsize
maindefault branch
20 days agolast push
Python 49.6% TypeScript 25.5% CSS 24.1%
3.3 KB · 76 lines python
Raw Blame History
1# Home-Ka — pipeline sanity tests (run: python3 -m pytest tests/ or python3 tests/test_pipeline.py)2from __future__ import annotations34import sys5import tempfile6import unittest7from pathlib import Path89sys.path.insert(0, str(Path(__file__).resolve().parent.parent))101112class PipelineTest(unittest.TestCase):13    @classmethod14    def setUpClass(cls):15        # isolated database16        from homeka import db17        cls._tmp = tempfile.TemporaryDirectory()18        db.DB_PATH = type(db.DB_PATH)(cls._tmp.name) / "test.db"19        db._SCHEMA_READY = False2021    def test_normalize(self):22        from homeka.normalize import (normalize_state, normalize_status,23                                      normalize_property_type, parse_price,24                                      parse_lot_sqft, normalize_zip)25        self.assertEqual(normalize_state("Texas"), "TX")26        self.assertEqual(normalize_state("tx."), "TX")27        self.assertEqual(normalize_zip("78701-1234"), "78701")28        self.assertEqual(parse_price("$1.25M"), 1_250_000)29        self.assertEqual(parse_price("$459,000"), 459_000)30        self.assertEqual(parse_lot_sqft("1.89 acres"), round(1.89 * 43_560))31        self.assertEqual(normalize_status("Active Under Contract"), "pending")32        self.assertEqual(normalize_property_type("SingleFamilyResidence"),33                         "Single Family")3435    def test_property_match_and_dedup(self):36        from homeka import db, quality37        from homeka.schema import Listing38        a = Listing(source="s1", external_id="A1", url="u1",39                    street_address="123 North Main Street", city="Austin",40                    state="TX", zip_code="78701", property_type="House",41                    list_price=500000, description="x" * 60,42                    images=["https://x/a.jpg"]).finalize()43        b = Listing(source="s2", external_id="B1", url="u2",44                    street_address="123 N Main St", city="Austin",45                    state="TX", zip_code="78701", property_type="House",46                    list_price=502000, description="y" * 60,47                    images=["https://x/b.jpg"]).finalize()48        con = db.connect()49        db.sync_source(con, "s1", [a])50        db.sync_source(con, "s2", [b])51        pids = [r["property_id"] for r in52                con.execute("SELECT property_id FROM listings")]53        self.assertEqual(pids[0], pids[1])          # same physical property54        self.assertEqual(db.refresh_dedup(con), 1)   # ±1% price → one hidden55        q = quality.refresh(con)56        self.assertEqual(q["published"], 2)57        con.close()5859    def test_reso_passthrough(self):60        from homeka.schema import Listing61        l = Listing(source="s", external_id="1", url="u", details={62            "ListPrice": 725000, "City": "Denver", "StateOrProvince": "CO",63            "PostalCode": "80202", "BedroomsTotal": 4, "BathroomsFull": 2,64            "BathroomsHalf": 1, "LivingArea": 2400, "YearBuilt": 2001,65            "StandardStatus": "Active", "ParcelNumber": "123-45",66        }).finalize()67        self.assertEqual(l.list_price, 725000)68        self.assertEqual(l.state, "CO")69        self.assertEqual(l.bathrooms, 2.5)70        self.assertEqual(l.year_built, 2001)71        self.assertEqual(l.apn, "123-45")727374if __name__ == "__main__":75    unittest.main()76