Skip to content

Commit 990df80

Browse files
committed
Convert tests in #852 to pytest, update change log and version
1 parent e5bd9ec commit 990df80

3 files changed

Lines changed: 36 additions & 46 deletions

File tree

CHANGES.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changes
22
=======
33

4+
1.7.1 (TBD)
5+
-----------
6+
7+
- Improved documentation of STRtree usage (#857).
8+
- Improved handling for empty list or list of lists in GeoJSON coordinates
9+
(#852).
10+
411
1.7.0 (2020-01-28)
512
------------------
613

shapely/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.7.0"
1+
__version__ = "1.7.1dev"

tests/test_shape.py

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,30 @@
1-
from . import unittest
1+
import pytest
2+
23
from shapely.geometry import shape, Polygon
34

4-
# numpy is an optional dependency
5-
try:
6-
import numpy as np
7-
except ImportError:
8-
_has_numpy = False
9-
else:
10-
_has_numpy = True
11-
12-
13-
class ShapeTestCase(unittest.TestCase):
14-
15-
def test_polygon_no_coords(self):
16-
# using None
17-
d = {"type": "Polygon", "coordinates": None}
18-
p = shape(d)
19-
self.assertEqual(p, Polygon())
20-
21-
# using empty list
22-
d = {"type": "Polygon", "coordinates": []}
23-
p = shape(d)
24-
self.assertEqual(p, Polygon())
25-
26-
# using empty array
27-
d = {"type": "Polygon", "coordinates": np.array([])}
28-
p = shape(d)
29-
self.assertEqual(p, Polygon())
30-
31-
def test_polygon_with_coords_list(self):
32-
# list
33-
d = {"type": "Polygon", "coordinates": [[[5, 10], [10, 10], [10, 5]]]}
34-
p = shape(d)
35-
self.assertEqual(p, Polygon([(5, 10), (10, 10), (10, 5)]))
36-
37-
# numpy array
38-
if _has_numpy:
39-
d = {"type": "Polygon", "coordinates": np.array([[[5, 10],
40-
[10, 10],
41-
[10, 5]]])}
42-
p = shape(d)
43-
self.assertEqual(p, Polygon([(5, 10), (10, 10), (10, 5)]))
44-
45-
46-
def test_suite():
47-
return unittest.TestLoader().loadTestsFromTestCase(ShapeTestCase)
5+
6+
@pytest.mark.parametrize(
7+
"geom",
8+
[{"type": "Polygon", "coordinates": None}, {"type": "Polygon", "coordinates": []}],
9+
)
10+
def test_polygon_no_coords(geom):
11+
assert shape(geom) == Polygon()
12+
13+
14+
def test_polygon_empty_np_array():
15+
np = pytest.importorskip("numpy")
16+
geom = {"type": "Polygon", "coordinates": np.array([])}
17+
assert shape(geom) == Polygon()
18+
19+
20+
def test_polygon_with_coords_list():
21+
geom = {"type": "Polygon", "coordinates": [[[5, 10], [10, 10], [10, 5]]]}
22+
obj = shape(geom)
23+
assert obj == Polygon([(5, 10), (10, 10), (10, 5)])
24+
25+
26+
def test_polygon_not_empty_np_array():
27+
np = pytest.importorskip("numpy")
28+
geom = {"type": "Polygon", "coordinates": np.array([[[5, 10], [10, 10], [10, 5]]])}
29+
obj = shape(geom)
30+
assert obj == Polygon([(5, 10), (10, 10), (10, 5)])

0 commit comments

Comments
 (0)