| import unittest |
|
|
| from src.earth_reference import build_earth_reference |
| from src.models import SiteSelection |
| from src.safety import find_forbidden_phrases |
|
|
|
|
| class EarthReferenceTests(unittest.TestCase): |
| def test_earth_reference_generates_external_links_and_safe_evidence(self): |
| selection = SiteSelection( |
| id="S1", |
| selection_type="drawn_polygon", |
| coordinate_mode="wgs84", |
| geometry_geojson=None, |
| local_geometry=None, |
| anchor_lat=21.00245, |
| anchor_lon=70.24550, |
| radius_m=None, |
| area_sqm=1000, |
| perimeter_m=150, |
| centroid=(21.00245, 70.24550), |
| bbox=None, |
| unit_source="WGS84", |
| accuracy_label="user-drawn approximate boundary", |
| limitations=["Drawn boundaries are approximate."], |
| ) |
|
|
| reference, evidence = build_earth_reference(selection, "Visible trees along the west edge.") |
|
|
| self.assertIn("Google Maps reference", reference["links"]) |
| self.assertIn("Google Earth reference", reference["links"]) |
| self.assertIn("visual-reference workflow", reference["markdown"]) |
| self.assertIn("Visible trees", reference["markdown"]) |
| self.assertGreaterEqual(len(evidence), 2) |
| self.assertEqual(find_forbidden_phrases(reference["markdown"]), []) |
|
|
| def test_earth_reference_without_anchor_is_explicitly_limited(self): |
| selection = SiteSelection( |
| id="S2", |
| selection_type="dxf_boundary", |
| coordinate_mode="local_cad", |
| geometry_geojson=None, |
| local_geometry=[(0, 0), (10, 0), (10, 10)], |
| anchor_lat=None, |
| anchor_lon=None, |
| radius_m=None, |
| area_sqm=100, |
| perimeter_m=40, |
| centroid=(5, 5), |
| bbox=(0, 0, 10, 10), |
| unit_source="DXF meters", |
| accuracy_label="cad local without anchor", |
| limitations=["CAD needs anchor."], |
| ) |
|
|
| reference, evidence = build_earth_reference(selection, "") |
|
|
| self.assertEqual(reference["links"], {}) |
| self.assertIn("no anchor coordinate", reference["markdown"]) |
| self.assertEqual(evidence, []) |
|
|
|
|
| if __name__ == "__main__": |
| unittest.main() |
|
|