Skip to content

Commit

Permalink
when shapely unavailable, skip geointerface tests
Browse files Browse the repository at this point in the history
  • Loading branch information
njwilson23 committed Mar 3, 2017
1 parent a56f5cf commit a188709
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion tests/geointerface_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -42,13 +47,15 @@ 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)
self.assertEqual(sp.x, p.x)
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)
Expand All @@ -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)
Expand All @@ -66,19 +74,22 @@ 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)
self.assertEqual(p.x, sp.x)
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)
Expand All @@ -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)])
Expand All @@ -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)])
Expand Down

0 comments on commit a188709

Please sign in to comment.