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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
"""
Tests for geojson/base.py
"""
import unittest
import geojson
class TypePropertyTestCase(unittest.TestCase):
def test_type_property(self):
json_str = ('{"type": "Feature",'
' "geometry": null,'
' "id": 1,'
' "properties": {"type": "é"}}')
geojson_obj = geojson.loads(json_str)
self.assertTrue(isinstance(geojson_obj, geojson.GeoJSON))
self.assertTrue("type" in geojson_obj.properties)
json_str = ('{"type": "Feature",'
' "geometry": null,'
' "id": 1,'
' "properties": {"type": null}}')
geojson_obj = geojson.loads(json_str)
self.assertTrue(isinstance(geojson_obj, geojson.GeoJSON))
self.assertTrue("type" in geojson_obj.properties)
json_str = ('{"type": "Feature",'
' "geometry": null,'
' "id": 1,'
' "properties": {"type": "meow"}}')
geojson_obj = geojson.loads(json_str)
self.assertTrue(isinstance(geojson_obj, geojson.GeoJSON))
self.assertTrue("type" in geojson_obj.properties)
class OperatorOverloadingTestCase(unittest.TestCase):
"""
Tests for operator overloading
"""
def setUp(self):
self.coords = (12, -5)
self.point = geojson.Point(self.coords)
def test_setattr(self):
new_coords = (27, 42)
self.point.coordinates = new_coords
self.assertEqual(self.point['coordinates'], new_coords)
def test_getattr(self):
self.assertEqual(self.point['coordinates'], self.point.coordinates)
def test_delattr(self):
del self.point.coordinates
self.assertFalse(hasattr(self.point, 'coordinates'))
class BaseTestCase(unittest.TestCase):
def test_to_instance(self):
FAKE = 'fake'
self.assertEqual(FAKE, geojson.GeoJSON.to_instance(
None, (lambda: FAKE)))
with self.assertRaises(ValueError):
geojson.GeoJSON.to_instance({"type": "Not GeoJSON"}, strict=True)
def test_errors(self):
class Fake(geojson.GeoJSON):
pass
with self.assertRaises(NotImplementedError):
Fake().errors()
|