Skip to content

Commit

Permalink
Convert tests in #852 to pytest, update change log and version
Browse files Browse the repository at this point in the history
  • Loading branch information
sgillies committed Mar 1, 2020
1 parent e5bd9ec commit 990df80
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 46 deletions.
7 changes: 7 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changes
=======

1.7.1 (TBD)
-----------

- Improved documentation of STRtree usage (#857).
- Improved handling for empty list or list of lists in GeoJSON coordinates
(#852).

1.7.0 (2020-01-28)
------------------

Expand Down
2 changes: 1 addition & 1 deletion shapely/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.7.0"
__version__ = "1.7.1dev"
73 changes: 28 additions & 45 deletions tests/test_shape.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,30 @@
from . import unittest
import pytest

from shapely.geometry import shape, Polygon

# numpy is an optional dependency
try:
import numpy as np
except ImportError:
_has_numpy = False
else:
_has_numpy = True


class ShapeTestCase(unittest.TestCase):

def test_polygon_no_coords(self):
# using None
d = {"type": "Polygon", "coordinates": None}
p = shape(d)
self.assertEqual(p, Polygon())

# using empty list
d = {"type": "Polygon", "coordinates": []}
p = shape(d)
self.assertEqual(p, Polygon())

# using empty array
d = {"type": "Polygon", "coordinates": np.array([])}
p = shape(d)
self.assertEqual(p, Polygon())

def test_polygon_with_coords_list(self):
# list
d = {"type": "Polygon", "coordinates": [[[5, 10], [10, 10], [10, 5]]]}
p = shape(d)
self.assertEqual(p, Polygon([(5, 10), (10, 10), (10, 5)]))

# numpy array
if _has_numpy:
d = {"type": "Polygon", "coordinates": np.array([[[5, 10],
[10, 10],
[10, 5]]])}
p = shape(d)
self.assertEqual(p, Polygon([(5, 10), (10, 10), (10, 5)]))


def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(ShapeTestCase)

@pytest.mark.parametrize(
"geom",
[{"type": "Polygon", "coordinates": None}, {"type": "Polygon", "coordinates": []}],
)
def test_polygon_no_coords(geom):
assert shape(geom) == Polygon()


def test_polygon_empty_np_array():
np = pytest.importorskip("numpy")
geom = {"type": "Polygon", "coordinates": np.array([])}
assert shape(geom) == Polygon()


def test_polygon_with_coords_list():
geom = {"type": "Polygon", "coordinates": [[[5, 10], [10, 10], [10, 5]]]}
obj = shape(geom)
assert obj == Polygon([(5, 10), (10, 10), (10, 5)])


def test_polygon_not_empty_np_array():
np = pytest.importorskip("numpy")
geom = {"type": "Polygon", "coordinates": np.array([[[5, 10], [10, 10], [10, 5]]])}
obj = shape(geom)
assert obj == Polygon([(5, 10), (10, 10), (10, 5)])

0 comments on commit 990df80

Please sign in to comment.