File size: 3,838 Bytes
c590d67
 
 
 
 
 
 
 
 
 
338ebb6
 
c590d67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
338ebb6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c590d67
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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()