-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert tests in #852 to pytest, update change log and version
- Loading branch information
Showing
3 changed files
with
36 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "1.7.0" | ||
__version__ = "1.7.1dev" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)]) |