import unittest from unittest.mock import patch from src.geometry import selection_from_lat_lon from src.topography import fetch_topography class TopographyTests(unittest.TestCase): def test_fetch_topography_summarizes_elevation_samples(self): selection = selection_from_lat_lon(21.002, 70.245, radius_m=250) fake_response = { "results": [ {"elevation": 12.0}, {"elevation": 14.5}, {"elevation": 13.0}, {"elevation": 16.0}, ] } with patch("src.topography.get_json", return_value=fake_response): topo, evidence = fetch_topography(selection) self.assertEqual(topo["sample_count"], 4) self.assertEqual(topo["min_elevation_m"], 12.0) self.assertEqual(topo["max_elevation_m"], 16.0) self.assertGreaterEqual(topo["relief_m"], 4.0) self.assertEqual(evidence[0].category, "Topography") self.assertIn("not a site survey", evidence[0].limitation) def test_fetch_topography_failure_returns_safe_evidence(self): selection = selection_from_lat_lon(21.002, 70.245, radius_m=250) with patch("src.topography.get_json", side_effect=TimeoutError("slow")): topo, evidence = fetch_topography(selection) self.assertEqual(topo, {}) self.assertEqual(evidence[0].confidence, "low") self.assertIn("Do not infer slope", evidence[0].design_implication) if __name__ == "__main__": unittest.main()