Skip to content

Commit

Permalink
Index error empty multilinestring (#949)
Browse files Browse the repository at this point in the history
* add test cases for empty multilinestring.

* add tests for "_is_coordinates_empty"

* whitespace

* don't use pathlib so py2.7 tests pass

* try using Popen / communicate for py2.7 support

* remove print call

* account for python2/3 semantics
  • Loading branch information
tomplex committed Jul 28, 2020
1 parent d54e9ec commit e214bc0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
23 changes: 22 additions & 1 deletion tests/test_shape.py
@@ -1,6 +1,7 @@
import pytest

from shapely.geometry import shape, Polygon
from shapely.geometry import shape, Polygon, MultiLineString
from shapely.geometry.geo import _is_coordinates_empty


@pytest.mark.parametrize(
Expand Down Expand Up @@ -28,3 +29,23 @@ def test_polygon_not_empty_np_array():
geom = {"type": "Polygon", "coordinates": np.array([[[5, 10], [10, 10], [10, 5]]])}
obj = shape(geom)
assert obj == Polygon([(5, 10), (10, 10), (10, 5)])


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


@pytest.mark.parametrize("coords", [
[],
[[]],
[[], []],
None,
[[[]]]
])
def test_is_coordinates_empty(coords):
assert _is_coordinates_empty(coords)
13 changes: 7 additions & 6 deletions tests/test_strtree.py
@@ -1,8 +1,8 @@
import gc
import os
import pickle
import subprocess
import sys
from pathlib import Path

from shapely.strtree import STRtree
from shapely.geometry import Point, Polygon
Expand Down Expand Up @@ -92,10 +92,11 @@ def test_pickle_persistence():
"""
tree = STRtree([Point(i, i).buffer(0.1) for i in range(3)])
pickled_strtree = pickle.dumps(tree)
print("pickled strtree:", repr(pickled_strtree))
unpickle_script_file_path = Path(__file__).parent / "unpickle-strtree.py"
subprocess.run(
unpickle_script_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "unpickle-strtree.py")
proc = subprocess.Popen(
[sys.executable, str(unpickle_script_file_path)],
input=pickled_strtree,
check=True
stdin=subprocess.PIPE,
)
proc.communicate(input=pickled_strtree)
proc.wait()
assert proc.returncode == 0
7 changes: 6 additions & 1 deletion tests/unpickle-strtree.py
Expand Up @@ -10,7 +10,12 @@


if __name__ == "__main__":
pickled_strtree = sys.stdin.buffer.read()
try:
pickled_strtree = sys.stdin.buffer.read()
except AttributeError:
# Python 2.7
pickled_strtree = sys.stdin.read()

print("received pickled strtree:", repr(pickled_strtree))
strtree = pickle.loads(pickled_strtree)
# Exercise API.
Expand Down

0 comments on commit e214bc0

Please sign in to comment.