This repository has been archived by the owner on Apr 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest.py
69 lines (56 loc) · 2.11 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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
import statestyle
class BaseTest(unittest.TestCase):
def setUp(self):
self.good_postals = ['CA', 'IA', 'dc', 'iL ']
self.bad_postals = ['XX', 'xx', 'Xx']
self.good_names = ['Washington DC', 'California', 'Iowa', 'district of columbia', 'ILLINOIS']
self.bad_names = ['Los Angeles', 'Cedar Rapids', 'Shaw', 'CHICAGO']
self.good_fips = ['6', '19', 11, 17, '08']
self.bad_fips = [-6, '190', '11x ', 0]
self.good_ap = ['Calif.', 'Iowa', 'd.c.', 'ILL.']
self.bad_ap = ['Cali', 'iow', 'CD', 'ILLI']
class GetTest(BaseTest):
def test_attr(self):
obj = statestyle.get("CA")
self.assertEqual(obj.postal, 'CA')
self.assertEqual(obj.fips, '6')
self.assertEqual(obj.name, 'California')
self.assertEqual(obj.type, 'state')
self.assertEqual(obj.ap, 'Calif.')
self.assertEqual(obj.stateface, 'E')
obj.__repr__()
obj.__str__()
obj.__unicode__()
def test_postals(self):
for i in self.good_postals:
statestyle.get(i)
for i in self.bad_postals:
self.assertRaises(ValueError, statestyle.get, i)
def test_names(self):
for i in self.good_names:
statestyle.get(i)
for i in self.bad_names:
self.assertRaises(ValueError, statestyle.get, i)
def test_fips(self):
for i in self.good_fips:
statestyle.get(i)
for i in self.bad_fips:
self.assertRaises(ValueError, statestyle.get, i)
def test_ap(self):
for i in self.good_ap:
statestyle.get(i)
for i in self.bad_ap:
self.assertRaises(ValueError, statestyle.get, i)
def test_dict(self):
o = statestyle.get("IA")
self.assertEqual(o['ap'], o.ap)
with self.assertRaises(AttributeError):
o['foobar']
self.assertDictEqual(o.__dict__, o.to_dict())
self.assertDictEqual(dict(o), o.to_dict())
self.assertDictEqual(dict(o), o.__dict__)
if __name__ == '__main__':
unittest.main()