site-intelligence-studio / tests /test_sample_data.py
Eishaan's picture
Support polygon-only analysis flow
338ebb6
Raw
History Blame Contribute Delete
3.84 kB
import unittest
from src.sample_data import apply_chorwad_sample_fallbacks, is_sample_site
class SampleDataTests(unittest.TestCase):
def test_sample_detection_is_narrow(self):
self.assertTrue(is_sample_site("Chorwad Coastal Thesis Sample", "", "sample drawn boundary"))
self.assertFalse(is_sample_site("Real thesis", "Chorwad site", "faculty CAD"))
self.assertFalse(is_sample_site("Sample", "Mumbai site", "manual pin"))
self.assertTrue(is_sample_site("", "", "", anchor_lat=21.00248, anchor_lon=70.24537))
self.assertFalse(is_sample_site("", "", "", anchor_lat=19.076, anchor_lon=72.8777))
def test_sample_fallback_fills_missing_layers_and_warns(self):
identity, climate, context, topo, soil, evidence, warnings = apply_chorwad_sample_fallbacks(
project_name="Chorwad Coastal Thesis Sample",
site_name="Chorwad site",
boundary_source="sample drawn boundary",
site_identity=None,
climate={"forecast": None, "recent_historical": None, "climate_normal": None},
osm_context={"counts": {}, "features": []},
topography={},
soil={},
)
self.assertEqual(identity["state"], "Gujarat")
self.assertIn("forecast", climate)
self.assertGreater(context["counts"]["water"], 0)
self.assertGreater(topo["mean_elevation_m"], 0)
self.assertIn("texture_signal", soil)
self.assertEqual(len(evidence), 1)
self.assertIn("demo/testing", warnings[0])
def test_sample_fallback_replaces_non_useful_identity(self):
identity, *_ = apply_chorwad_sample_fallbacks(
project_name="Chorwad Coastal Thesis Sample",
site_name="Chorwad site",
boundary_source="sample drawn boundary",
site_identity={"source_url": "https://nominatim.openstreetmap.org/"},
climate={"forecast": {"current_temperature_c": 30}},
osm_context={"counts": {"roads/access": 1}},
topography={"mean_elevation_m": 5},
soil={"texture_signal": "sample"},
)
self.assertEqual(identity["state"], "Gujarat")
def test_non_sample_does_not_modify_missing_layers(self):
identity, climate, context, topo, soil, evidence, warnings = apply_chorwad_sample_fallbacks(
project_name="Real Project",
site_name="Real site",
boundary_source="drawn boundary",
site_identity=None,
climate={},
osm_context={},
topography={},
soil={},
)
self.assertIsNone(identity)
self.assertEqual(climate, {})
self.assertEqual(context, {})
self.assertEqual(topo, {})
self.assertEqual(soil, {})
self.assertEqual(evidence, [])
self.assertEqual(warnings, [])
def test_coordinate_sample_fallback_supports_polygon_only_demo(self):
identity, climate, context, topo, soil, evidence, warnings = apply_chorwad_sample_fallbacks(
project_name="",
site_name="",
boundary_source="",
site_identity=None,
climate={"forecast": None, "recent_historical": None, "climate_normal": None},
osm_context={"counts": {}, "features": []},
topography={},
soil={},
anchor_lat=21.00248,
anchor_lon=70.24537,
)
self.assertEqual(identity["state"], "Gujarat")
self.assertIn("forecast", climate)
self.assertGreater(context["counts"]["water"], 0)
self.assertGreater(topo["mean_elevation_m"], 0)
self.assertIn("texture_signal", soil)
self.assertEqual(len(evidence), 1)
self.assertIn("demo/testing", warnings[0])
if __name__ == "__main__":
unittest.main()