diff --git a/setup.py b/setup.py index 4aca629..19c9f7c 100644 --- a/setup.py +++ b/setup.py @@ -5,5 +5,5 @@ version="0.1.0", license="BSD", packages=find_packages(), - test_suite = 'test.topojson_test' + test_suite="tests" ) diff --git a/test/__init__.py b/test/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/test/topojson_test.py b/test/topojson_test.py deleted file mode 100644 index f53f11d..0000000 --- a/test/topojson_test.py +++ /dev/null @@ -1,37 +0,0 @@ -import json -import unittest - -from topojson.conversion import convert - -class TestTopojson(unittest.TestCase): - - GeoJSON = json.loads(""" - { - "type": "FeatureCollection", - "features": [ - { - "type": "Feature", - "properties": {}, - "geometry": { - "type": "Polygon", - "coordinates": [[ - [-10, 10], - [ 10, 10], - [ 10, -10], - [-10, -10], - [-10, 10] - ]] - } - } - ] - } - """) - - def setUp(self): - pass - - def test_topojson(self): - tj = convert(self.GeoJSON) - self.assertEqual(tj['type'], 'Topology') - # with open('/tmp/out.topojson', 'w') as f: - # json.dump(tj, f) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..99b2f0d --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ +from .topojson_test import TestTopojson diff --git a/tests/data/square.geojson b/tests/data/square.geojson new file mode 100644 index 0000000..2b60039 --- /dev/null +++ b/tests/data/square.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": { + "description": "A 20°x20° box surrounding Null Island." + }, + "geometry": { + "type": "Polygon", + "coordinates": [[ + [-10, 10], + [ 10, 10], + [ 10, -10], + [-10, -10], + [-10, 10] + ]] + } + } + ] +} diff --git a/tests/topojson_test.py b/tests/topojson_test.py new file mode 100644 index 0000000..1fe7710 --- /dev/null +++ b/tests/topojson_test.py @@ -0,0 +1,15 @@ +import json +import unittest + +from topojson.conversion import convert + + +class TestTopojson(unittest.TestCase): + + def setUp(self): + with open("tests/data/square.geojson") as f: + self.square_geojson = json.load(f) + + def test_convert_geojson_to_topojson(self): + tj = convert(self.square_geojson) + self.assertEqual(tj['type'], 'Topology') diff --git a/topojson/coordinatesystems.py b/topojson/coordinatesystems.py index 07f9b6b..e810fa5 100644 --- a/topojson/coordinatesystems.py +++ b/topojson/coordinatesystems.py @@ -1,4 +1,5 @@ # coding=utf8 +from __future__ import division from math import sqrt, pi, cos, sin, atan2, tan, atan, asin PI4 = pi / 4 @@ -115,4 +116,4 @@ def distance(self, x0, y0, x1, y1): return 2.0 * asin(sqrt(self.haversin(y1 - y0) + cos(y0) * cos(y1) * self.haversin(x1 - x0))) -systems = {'cartesian': Cartesian(), 'spherical': Spherical()} \ No newline at end of file +systems = {'cartesian': Cartesian(), 'spherical': Spherical()} diff --git a/topojson/hashtable.py b/topojson/hashtable.py index 07ba88f..3dca767 100644 --- a/topojson/hashtable.py +++ b/topojson/hashtable.py @@ -1,5 +1,7 @@ +from __future__ import division from math import ceil, log + def hasher(size): mask = int(size) - 1 diff --git a/topojson/simplify.py b/topojson/simplify.py index 09ac02f..91f7622 100644 --- a/topojson/simplify.py +++ b/topojson/simplify.py @@ -1,4 +1,5 @@ #from https://github.com/omarestrella/simplify.py +from __future__ import division from .mytypes import Types def getSquareDistance(p1, p2): diff --git a/topojson/topology.py b/topojson/topology.py index 69e1af0..b677a0c 100644 --- a/topojson/topology.py +++ b/topojson/topology.py @@ -1,4 +1,5 @@ # coding=utf8 +from __future__ import division from .mytypes import Types from .stitchpoles import stitch from .coordinatesystems import systems