From a1887097fe1cb28f208a2a38b94a955ba01c6cba Mon Sep 17 00:00:00 2001 From: Nat Wilson Date: Thu, 2 Mar 2017 17:31:22 -0800 Subject: [PATCH] when shapely unavailable, skip geointerface tests --- tests/geointerface_tests.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/geointerface_tests.py b/tests/geointerface_tests.py index 097c031..2bb9cea 100644 --- a/tests/geointerface_tests.py +++ b/tests/geointerface_tests.py @@ -2,7 +2,12 @@ import unittest import numpy as np -import shapely.geometry + +try: + import shapely.geometry + HAS_SHAPELY = True +except ImportError: + HAS_SHAPELY = False import karta.vector as vector from karta.vector.geometry import Point, Multipoint, Line, Polygon @@ -42,6 +47,7 @@ def test_line(self): "coordinates": _as_nested_lists(zip(x[:5],y[:5]))}) + @unittest.skipIf(not HAS_SHAPELY, "shapely required") def test_point_output(self): p = Point((4, 2)) sp = shapely.geometry.shape(p.geomdict) @@ -49,6 +55,7 @@ def test_point_output(self): self.assertEqual(sp.y, p.y) return + @unittest.skipIf(not HAS_SHAPELY, "shapely required") def test_multipoint_output(self): p = Multipoint([(4, 2), (3, 5), (3, 2), (7, 3)]) sp = shapely.geometry.shape(p.geomdict) @@ -57,6 +64,7 @@ def test_multipoint_output(self): self.assertTrue(np.all(y == np.array([el.y for el in sp]))) return + @unittest.skipIf(not HAS_SHAPELY, "shapely required") def test_line_output(self): p = Line([(4, 2), (3, 5), (3, 2), (7, 3)]) sp = shapely.geometry.shape(p.geomdict) @@ -66,12 +74,14 @@ def test_line_output(self): self.assertTrue(np.all(y == np.array(sy))) return + @unittest.skipIf(not HAS_SHAPELY, "shapely required") def test_poly_output(self): p = Polygon([(4, 2), (3, 5), (3, 2), (7, 3)]) sp = shapely.geometry.shape(p.geomdict) self.assertEqual(p.bbox, sp.bounds) return + @unittest.skipIf(not HAS_SHAPELY, "shapely required") def test_point_input(self): sp = shapely.geometry.Point((3,4)) p = vector.read.from_shape(sp) @@ -79,6 +89,7 @@ def test_point_input(self): self.assertEqual(p.y, sp.y) return + @unittest.skipIf(not HAS_SHAPELY, "shapely required") def test_line_input(self): sp = shapely.geometry.LineString([(3,4), (6,2), (2,5)]) p = vector.read.from_shape(sp) @@ -88,12 +99,14 @@ def test_line_input(self): self.assertTrue(np.all(y == np.array(sy))) return + @unittest.skipIf(not HAS_SHAPELY, "shapely required") def test_poly_input(self): sp = shapely.geometry.Polygon([(4, 2), (3, 5), (3, 2), (7, 3)]) p = vector.read.from_shape(sp) self.assertEqual(p.bbox, sp.bounds) return + @unittest.skipIf(not HAS_SHAPELY, "shapely required") def test_multipoly_input(self): sp1 = shapely.geometry.Polygon([(4, 2), (3, 5), (3, 2), (7, 3)]) sp2 = shapely.geometry.Polygon([(7, 3), (9, 7), (2, 7), (2, 0)]) @@ -104,6 +117,7 @@ def test_multipoly_input(self): self.assertEqual(p2.bbox, sp2.bounds) return + @unittest.skipIf(not HAS_SHAPELY, "shapely required") def test_multiline_input(self): sp1 = shapely.geometry.LineString([(4, 2), (3, 5), (3, 2), (7, 3)]) sp2 = shapely.geometry.LineString([(7, 3), (9, 7), (2, 7), (2, 0)])