-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from tilezen/zerebubuth/basic-unit-tests
Fix unicode handling for property keys, layer names.
- Loading branch information
Showing
4 changed files
with
254 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
version: 2 | ||
jobs: | ||
build: | ||
docker: | ||
- image: circleci/python:2.7.15-stretch | ||
steps: | ||
- checkout | ||
- run: | ||
name: Checkout submodules | ||
command: git submodule update --init --recursive | ||
- run: | ||
name: Install C++ dependencies | ||
command: sudo apt install build-essential libgeos-dev libboost-python-dev | ||
- run: | ||
name: Install Python dependencies | ||
command: sudo pip install shapely | ||
- run: | ||
name: Build library | ||
command: python setup.py build | ||
- run: | ||
name: Unit tests | ||
command: python setup.py test |
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
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,60 +1,189 @@ | ||
import coanacatl | ||
from shapely.geometry import Point | ||
from shapely.geometry import LineString | ||
from shapely.geometry import Polygon | ||
from shapely.geometry import MultiPoint | ||
from shapely.geometry import MultiLineString | ||
from shapely.geometry import MultiPolygon | ||
|
||
|
||
features = [ | ||
dict( | ||
geometry=Point(0, 0), | ||
properties={ | ||
'string': 'string_value', | ||
'long': 4294967297L, | ||
'int': 1, | ||
'float': 1.0, | ||
'bool': True, | ||
}, | ||
id=1 | ||
), | ||
dict( | ||
geometry=LineString([(0, 0), (1, 1)]), | ||
properties={'baz': 'bat'}, | ||
id=None | ||
), | ||
dict( | ||
geometry=Point(0, 0).buffer(1), | ||
properties={'blah': 'blah', 'id': 123}, | ||
id=3 | ||
), | ||
dict( | ||
geometry=MultiPoint([(0, 0), (1, 1)]), | ||
properties={'foo': 'bar', 'boolean': False}, | ||
id=None | ||
), | ||
dict( | ||
geometry=MultiLineString([[(0, 0), (1, 0)], [(0, 1), (1, 1)]]), | ||
properties={'foo': 'bar'}, | ||
id=None | ||
), | ||
dict( | ||
geometry=Point(0, 0).buffer(0.4).union(Point(1, 1).buffer(0.4)), | ||
properties={'blah': 'blah'}, | ||
id=4 | ||
), | ||
] | ||
|
||
layers = [dict( | ||
name='layer', | ||
features=features, | ||
)] | ||
|
||
bounds = (0, 0, 1, 1) | ||
extents = 4096 | ||
|
||
tile_data = coanacatl.encode(layers, bounds, extents) | ||
print repr(tile_data) | ||
with open('foo.mvt', 'w') as fh: | ||
fh.write(tile_data) | ||
from unittest import TestCase | ||
|
||
|
||
class GeometryTest(TestCase): | ||
|
||
def _generate_tile(self, features): | ||
import coanacatl | ||
|
||
layers = [dict( | ||
name='layer', | ||
features=features, | ||
)] | ||
|
||
bounds = (0, 0, 1, 1) | ||
extents = 4096 | ||
|
||
tile_data = coanacatl.encode(layers, bounds, extents) | ||
self.assertTrue(tile_data) | ||
return tile_data | ||
|
||
def test_point(self): | ||
from shapely.geometry import Point | ||
|
||
features = [ | ||
dict( | ||
geometry=Point(0, 0), | ||
properties={}, | ||
id=1 | ||
), | ||
] | ||
|
||
self._generate_tile(features) | ||
|
||
def test_linestring(self): | ||
from shapely.geometry import LineString | ||
|
||
features = [ | ||
dict( | ||
geometry=LineString([(0, 0), (1, 1)]), | ||
properties={}, | ||
id=None | ||
), | ||
] | ||
|
||
self._generate_tile(features) | ||
|
||
def test_polygon(self): | ||
from shapely.geometry import Point | ||
|
||
features = [ | ||
dict( | ||
geometry=Point(0, 0).buffer(1), | ||
properties={}, | ||
id=3 | ||
), | ||
] | ||
|
||
self._generate_tile(features) | ||
|
||
def test_multipoint(self): | ||
from shapely.geometry import MultiPoint | ||
|
||
features = [ | ||
dict( | ||
geometry=MultiPoint([(0, 0), (1, 1)]), | ||
properties={}, | ||
id=None | ||
), | ||
] | ||
|
||
self._generate_tile(features) | ||
|
||
def test_multilinestring(self): | ||
from shapely.geometry import MultiLineString | ||
|
||
features = [ | ||
dict( | ||
geometry=MultiLineString([[(0, 0), (1, 0)], [(0, 1), (1, 1)]]), | ||
properties={}, | ||
id=None | ||
), | ||
] | ||
|
||
self._generate_tile(features) | ||
|
||
def test_multipolygon(self): | ||
from shapely.geometry import Point | ||
|
||
features = [ | ||
dict( | ||
geometry=Point(0, 0).buffer(0.4).union( | ||
Point(1, 1).buffer(0.4)), | ||
properties={}, | ||
id=4 | ||
), | ||
] | ||
|
||
self._generate_tile(features) | ||
|
||
|
||
class PropertyTest(TestCase): | ||
|
||
def _generate_tile(self, features): | ||
import coanacatl | ||
|
||
layers = [dict( | ||
name='layer', | ||
features=features, | ||
)] | ||
|
||
bounds = (0, 0, 1, 1) | ||
extents = 4096 | ||
|
||
tile_data = coanacatl.encode(layers, bounds, extents) | ||
self.assertTrue(tile_data) | ||
return tile_data | ||
|
||
def test_property_types(self): | ||
from shapely.geometry import Point | ||
|
||
features = [ | ||
dict( | ||
geometry=Point(0, 0), | ||
properties={ | ||
'string': 'string_value', | ||
'long': 4294967297L, | ||
'int': 1, | ||
'float': 1.0, | ||
'bool': True, | ||
}, | ||
id=1 | ||
), | ||
] | ||
|
||
self._generate_tile(features) | ||
|
||
def test_unicode_property_value(self): | ||
from shapely.geometry import Point | ||
|
||
features = [ | ||
dict( | ||
geometry=Point(0, 0), | ||
properties={ | ||
'string': unicode('unicode_value'), | ||
}, | ||
id=1 | ||
), | ||
] | ||
|
||
self._generate_tile(features) | ||
|
||
def test_unicode_property_key(self): | ||
from shapely.geometry import Point | ||
|
||
features = [ | ||
dict( | ||
geometry=Point(0, 0), | ||
properties={ | ||
unicode('unicode'): 'string_value', | ||
}, | ||
id=1 | ||
), | ||
] | ||
|
||
self._generate_tile(features) | ||
|
||
def test_unicode_layer_name(self): | ||
import coanacatl | ||
from shapely.geometry import Point | ||
|
||
layers = [dict( | ||
name=unicode('layer'), | ||
features=[ | ||
dict( | ||
geometry=Point(0, 0), | ||
properties={ | ||
'foo': 'bar', | ||
}, | ||
id=1 | ||
), | ||
], | ||
)] | ||
|
||
bounds = (0, 0, 1, 1) | ||
extents = 4096 | ||
|
||
tile_data = coanacatl.encode(layers, bounds, extents) | ||
self.assertTrue(tile_data) | ||
return tile_data |