1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
"""
Tests for geojson object constructor
"""
import unittest
import geojson
class TestGeoJSONConstructor(unittest.TestCase):
def test_copy_construction(self):
coords = [1, 2]
pt = geojson.Point(coords)
self.assertEqual(geojson.Point(pt), pt)
def test_nested_constructors(self):
a = [5, 6]
b = [9, 10]
c = [-5, 12]
mp = geojson.MultiPoint([geojson.Point(a), b])
self.assertEqual(mp.coordinates, [a, b])
mls = geojson.MultiLineString([geojson.LineString([a, b]), [a, c]])
self.assertEqual(mls.coordinates, [[a, b], [a, c]])
outer = [a, b, c, a]
poly = geojson.Polygon(geojson.MultiPoint(outer))
other = [[1, 1], [1, 2], [2, 1], [1, 1]]
poly2 = geojson.Polygon([outer, other])
self.assertEqual(geojson.MultiPolygon([poly, poly2]).coordinates,
[[outer], [outer, other]])
|