chore: bootstrap housing research platform
This commit is contained in:
36
tests/test_indicators.py
Normal file
36
tests/test_indicators.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from shanghai_housing.db import connect, load_sample_data
|
||||
from shanghai_housing.indicators import compute_area_scores, previous_month
|
||||
|
||||
|
||||
class IndicatorTests(unittest.TestCase):
|
||||
def test_previous_month_handles_year_boundary(self) -> None:
|
||||
self.assertEqual(previous_month("2026-01"), "2025-12")
|
||||
self.assertEqual(previous_month("2026-05"), "2026-04")
|
||||
|
||||
def test_area_scores_are_bounded_and_sorted(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
db_path = Path(tmpdir) / "test.sqlite"
|
||||
load_sample_data(db_path)
|
||||
with connect(db_path) as conn:
|
||||
scores = compute_area_scores(conn, "2026-05")
|
||||
|
||||
self.assertEqual(len(scores), 5)
|
||||
self.assertEqual(
|
||||
[score.investment_score for score in scores],
|
||||
sorted([score.investment_score for score in scores], reverse=True),
|
||||
)
|
||||
for score in scores:
|
||||
self.assertGreaterEqual(score.investment_score, 0)
|
||||
self.assertLessEqual(score.investment_score, 100)
|
||||
self.assertGreaterEqual(score.supply_risk_score, 0)
|
||||
self.assertLessEqual(score.supply_risk_score, 100)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user