forked from porimol/countryinfo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
65 lines (53 loc) · 2.15 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
import unittest
from countryinfo import CountryInfo
class Tests(unittest.TestCase):
all_countries = {}
def setUp(self):
"""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 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.fail("Country '{0}' key error: {1}".format(name, err))
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.fail("Country '{0}' key error: {1}".format(name, err))
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.fail("Country '{0}' key error: {1}".format(name, err))
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.fail("Country '{0}' key error: {1}".format(name, err))
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.fail("Country '{0}' key error: {1}".format(name, err))
def test_select_country_from_alt_name(self):
country = CountryInfo('PK')
assert country.name() == 'pakistan'
if __name__ == '__main__':
unittest.main()