-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
tests.py
184 lines (156 loc) · 6.47 KB
/
tests.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import unittest
from countryinfo import CountryInfo
class Tests(unittest.TestCase):
all_countries = {}
def setUp(self):
self.verificationErrors = [] #Variable used to collect non-fatal errors
"""Loads all the countries just once for all the tests
"""
if not self.all_countries:
print("Loading all countries...")
country_names = CountryInfo().all()
for name in country_names:
country = CountryInfo(name)
self.all_countries[name] = country
def tearDown(self):
"""Loads and prints all exceptions encountered while running tests
"""
self.assertEqual([], self.verificationErrors)
def test_all_countries_have_name(self):
for name in self.all_countries:
try:
country = self.all_countries[name]
self.assertIsNotNone(country.name())
except KeyError as err:
self.verificationErrors.append("name: "+ str(name))
def test_all_countries_have_native_name(self):
for name in self.all_countries:
try:
country = self.all_countries[name]
country.native_name()
except KeyError as err:
self.verificationErrors.append("native_name: "+ str(name))
def test_all_countries_have_iso(self):
for name in self.all_countries:
try:
country = self.all_countries[name]
country.iso()
except KeyError as err:
self.verificationErrors.append("iso: "+ str(name))
def test_all_countries_have_alt_spellings(self):
for name in self.all_countries:
try:
country = self.all_countries[name]
country.alt_spellings()
except KeyError as err:
self.verificationErrors.append("alt_spellings: "+ str(name))
def test_all_countries_have_translations(self):
for name in self.all_countries:
try:
country = self.all_countries[name]
country.translations()
except KeyError as err:
self.verificationErrors.append("translations: "+ str(name))
def test_all_countries_have_latlng(self):
for name in self.all_countries:
try:
country = self.all_countries[name]
country.latlng()
except KeyError as err:
self.verificationErrors.append("latlng: "+ str(name))
def test_all_countries_have_area(self):
for name in self.all_countries:
try:
country = self.all_countries[name]
country.area()
except KeyError as err:
self.verificationErrors.append("area: "+ str(name))
def test_all_countries_have_callingCodes(self):
for name in self.all_countries:
try:
country = self.all_countries[name]
country.calling_codes()
except KeyError as err:
self.verificationErrors.append("callingCodes: "+ str(name))
def test_all_countries_have_capital(self):
for name in self.all_countries:
try:
country = self.all_countries[name]
country.capital()
except KeyError as err:
self.verificationErrors.append("capital: "+ str(name))
def test_all_countries_have_capital_latlng(self):
for name in self.all_countries:
try:
country = self.all_countries[name]
country.capital_latlng()
except KeyError as err:
self.verificationErrors.append("capital_latlng: "+ str(name))
def test_all_countries_have_currencies(self):
for name in self.all_countries:
try:
country = self.all_countries[name]
country.currencies()
except KeyError as err:
self.verificationErrors.append("currencies: "+ str(name))
def test_all_countries_have_demonym(self):
for name in self.all_countries:
try:
country = self.all_countries[name]
country.demonym()
except KeyError as err:
self.verificationErrors.append("demonym: "+ str(name))
def test_all_countries_have_population(self):
for name in self.all_countries:
try:
country = self.all_countries[name]
country.population()
except KeyError as err:
self.verificationErrors.append("population: "+ str(name))
def test_all_countries_have_provinces(self):
for name in self.all_countries:
try:
country = self.all_countries[name]
country.provinces()
except KeyError as err:
self.verificationErrors.append("provinces: "+ str(name))
def test_all_countries_have_region(self):
for name in self.all_countries:
try:
country = self.all_countries[name]
country.region()
except KeyError as err:
self.verificationErrors.append("region: "+ str(name))
def test_all_countries_have_subregion(self):
for name in self.all_countries:
try:
country = self.all_countries[name]
country.subregion()
except KeyError as err:
self.verificationErrors.append("subregion: "+ str(name))
def test_all_countries_have_timezones(self):
for name in self.all_countries:
try:
country = self.all_countries[name]
country.timezones()
except KeyError as err:
self.verificationErrors.append("timezones: "+ str(name))
def test_all_countries_have_tld(self):
for name in self.all_countries:
try:
country = self.all_countries[name]
country.tld()
except KeyError as err:
self.verificationErrors.append("tld "+ str(name))
def test_all_countries_have_wiki(self):
for name in self.all_countries:
try:
country = self.all_countries[name]
country.wiki()
except KeyError as err:
self.verificationErrors.append("wiki: "+ str(name))
def test_select_country_from_alt_name(self):
country = CountryInfo('PK')
assert country.name() == 'pakistan'
if __name__ == '__main__':
unittest.main()