aboutsummaryrefslogtreecommitdiffziptar.gz
path: root/tests/test_viewer_fixtures.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_viewer_fixtures.py')
-rw-r--r--tests/test_viewer_fixtures.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/test_viewer_fixtures.py b/tests/test_viewer_fixtures.py
new file mode 100644
index 0000000..5c0b88b
--- /dev/null
+++ b/tests/test_viewer_fixtures.py
@@ -0,0 +1,23 @@
+import json
+import unittest
+from pathlib import Path
+
+import numpy as np
+
+from mapgen import projections as PJ
+
+FIX = Path(__file__).resolve().parents[1] / "viewer" / "tests" / "fixtures" / "projections.json"
+POINTS = [(0.0, 0.0), (30.0, 120.0), (-60.0, -170.0), (89.0, 45.0), (10.0, -179.0), (-45.5, 33.3)]
+
+
+class ViewerFixtureTest(unittest.TestCase):
+ def test_write_projection_fixture(self):
+ lat = np.array([p[0] for p in POINTS])
+ lon = np.array([p[1] for p in POINTS])
+ x, y = PJ.equal_earth_forward(lat, lon)
+ data = {"ee_xmax": float(PJ.EE_XMAX), "ee_ymax": float(PJ.EE_YMAX),
+ "equal_earth": [{"lat": float(a), "lon": float(b), "x": float(c), "y": float(d)}
+ for a, b, c, d in zip(lat, lon, x, y)]}
+ FIX.parent.mkdir(parents=True, exist_ok=True)
+ FIX.write_text(json.dumps(data, indent=1))
+ self.assertEqual(len(json.loads(FIX.read_text())["equal_earth"]), len(POINTS))