-
Notifications
You must be signed in to change notification settings - Fork 13
/
test.py
executable file
·77 lines (65 loc) · 2.89 KB
/
test.py
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
75
76
77
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
from googlegeocoder import *
class BaseTest(unittest.TestCase):
def setUp(self):
self.geocoder = GoogleGeocoder()
class GoogleTest(BaseTest):
def test_address(self):
result = self.geocoder.get("Winnetka")
self.assertEqual(type(result[0]), GeocoderResult)
def test_latlng(self):
result = self.geocoder.get((34.236144,-118.500938))
self.assertEqual(len(result), 10)
self.assertRaises(
ValueError,
self.geocoder.get,
(('a','b','c'))
)
def test_result_attributes(self):
result = self.geocoder.get("Winnetka")[0]
self.assertEqual(type(result.address_components), type([]))
[self.assertEqual(type(i), AddressComponent) for i in result.address_components]
[self.assertEqual(type(i.long_name), type(u"")) for i in result.address_components]
[self.assertEqual(type(i.short_name), type(u"")) for i in result.address_components]
[self.assertEqual(type(i.types), type([])) for i in result.address_components]
self.assertEqual(type(result.formatted_address), type(u""))
self.assertEqual(type(result.types), type([]))
self.assertEqual(type(result.geometry), Geometry)
self.assertEqual(type(result.geometry.location), Coordinates)
self.assertEqual(type(result.geometry.location_type), type(u""))
self.assertEqual(type(result.geometry.viewport), Bounds)
self.assertEqual(type(result.geometry.bounds), Bounds)
self.assertTrue(isinstance(result.geometry.partial_match, bool))
self.assertEqual(type(result.geometry.partial_match), type(True))
self.assertTrue(result.geometry.location.wkt.startswith('POINT(-87'))
result.__str__()
result.__repr__()
result.__unicode__()
result.address_components[0].__unicode__()
result.geometry.__str__()
result.geometry.__repr__()
result.geometry.__unicode__()
result.geometry.bounds.__str__()
result.geometry.bounds.__repr__()
result.geometry.bounds.__unicode__()
def test_viewport_bias(self):
result = self.geocoder.get("Winnetka",
bounding_box=((34.172684,-118.604794), (34.236144,-118.500938)))
self.assertEqual(result[0].formatted_address,
u'Winnetka, Los Angeles, CA, USA')
self.assertRaises(
ValueError,
self.geocoder.get,
"Winnetka",
bounding_box=(1,2,3)
)
def test_region_bias(self):
result = self.geocoder.get("Toledo", region='ES')
self.assertEqual(result[0].formatted_address, u'Toledo, Spain')
def test_language(self):
result = self.geocoder.get('Moscow', language='ru')
self.assertEqual(result[0].formatted_address, u'Москва, Россия')
if __name__ == '__main__':
unittest.main()