-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathphone_test.py
More file actions
55 lines (40 loc) · 1.68 KB
/
Copy pathphone_test.py
File metadata and controls
55 lines (40 loc) · 1.68 KB
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
import unittest
from phone import Phone
class TestPhone(unittest.TestCase):
def setUp(self):
self.p = Phone(dat_file="./phone.2503.dat")
def tearDown(self):
pass
def test_get_phone_no_type(self):
self.assertEqual(self.p.get_phone_no_type(1), '移动')
self.assertEqual(self.p.get_phone_no_type(2), '联通')
self.assertEqual(self.p.get_phone_no_type(3), '电信')
self.assertEqual(self.p.get_phone_no_type(4), '电信虚拟运营商')
self.assertEqual(self.p.get_phone_no_type(5), '联通虚拟运营商')
self.assertEqual(self.p.get_phone_no_type(6), '移动虚拟运营商')
self.assertEqual(self.p.get_phone_no_type(7), '广电')
self.assertEqual(self.p.get_phone_no_type(19), None)
def test_find_on_assert_error(self):
try:
self.p.find(123)
self.assertTrue(False)
except AssertionError:
pass
def test_find_on_ok(self):
res = self.p.find(1521147)
self.assertEqual(res['zip_code'], '421000')
self.assertEqual(res['area_code'], '0734')
self.assertEqual(res['city'], '衡阳')
self.assertEqual(res['province'], '湖南')
self.assertEqual(res['phone_type'], '移动')
res = self.p.find(1490507)
self.assertEqual(res['zip_code'], '200000')
self.assertEqual(res['area_code'], '021')
self.assertEqual(res['city'], '上海')
self.assertEqual(res['province'], '上海')
self.assertEqual(res['phone_type'], None)
def test_find_on_no_res(self):
res = self.p.find(1991147)
self.assertEqual(res, None)
if __name__ == '__main__':
unittest.main()