Skip to content

Commit

Permalink
unittests printout errors at end
Browse files Browse the repository at this point in the history
Rewrote unittests to test everything an print out all exceptions at the end
  • Loading branch information
Jeremys11 committed Oct 28, 2023
1 parent 05bcc4d commit 1ac103b
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 62 deletions.
1 change: 1 addition & 0 deletions countryinfo/data/holy_see_vatican_city.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
"provinces":["Holy See (Vatican City)"],
"timezones":["UTC+01:00"],
"region":"Europe",
"subregion":"Southern Europe",
"tld":[".va"],
"wiki":"http://en.wikipedia.org/wiki/holy_see_vatican_city"}
130 changes: 68 additions & 62 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ 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:
Expand All @@ -16,158 +18,162 @@ def setUp(self):
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.fail("Country '{0}' key error: {1}".format(name, 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.fail("Country '{0}' key error: {1}".format(name, 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.fail("Country '{0}' key error: {1}".format(name, 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.fail("Country '{0}' key error: {1}".format(name, 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.fail("Country '{0}' key error: {1}".format(name, err))
self.verificationErrors.append("translations: "+ str(name))

def test_all_countries_have_latlng(self):
for latlng in self.all_countries:
for name in self.all_countries:
try:
country = self.all_countries[latlng]
country.iso()
country = self.all_countries[name]
country.latlng()
except KeyError as err:
self.fail("Country '{0}' key error: {1}".format(latlng, err))
self.verificationErrors.append("latlng: "+ str(name))

def test_all_countries_have_area(self):
for area in self.all_countries:
for name in self.all_countries:
try:
country = self.all_countries[area]
country.iso()
country = self.all_countries[name]
country.area()
except KeyError as err:
self.fail("Country '{0}' key error: {1}".format(area, err))
self.verificationErrors.append("area: "+ str(name))

def test_all_countries_have_callingCodes(self):
for callingCodes in self.all_countries:
for name in self.all_countries:
try:
country = self.all_countries[callingCodes]
country.iso()
country = self.all_countries[name]
country.calling_codes()
except KeyError as err:
self.fail("Country '{0}' key error: {1}".format(callingCodes, err))
self.verificationErrors.append("callingCodes: "+ str(name))

def test_all_countries_have_capital(self):
for capital in self.all_countries:
for name in self.all_countries:
try:
country = self.all_countries[capital]
country.iso()
country = self.all_countries[name]
country.capital()
except KeyError as err:
self.fail("Country '{0}' key error: {1}".format(capital, err))
self.verificationErrors.append("capital: "+ str(name))

def test_all_countries_have_capital_latlng(self):
for capital_latlng in self.all_countries:
for name in self.all_countries:
try:
country = self.all_countries[capital_latlng]
country.iso()
country = self.all_countries[name]
country.capital_latlng()
except KeyError as err:
self.fail("Country '{0}' key error: {1}".format(capital_latlng, err))
self.verificationErrors.append("capital_latlng: "+ str(name))

def test_all_countries_have_currencies(self):
for currencies in self.all_countries:
for name in self.all_countries:
try:
country = self.all_countries[currencies]
country.iso()
country = self.all_countries[name]
country.currencies()
except KeyError as err:
self.fail("Country '{0}' key error: {1}".format(currencies, err))
self.verificationErrors.append("currencies: "+ str(name))

def test_all_countries_have_demonym(self):
for demonym in self.all_countries:
for name in self.all_countries:
try:
country = self.all_countries[demonym]
country.iso()
country = self.all_countries[name]
country.demonym()
except KeyError as err:
self.fail("Country '{0}' key error: {1}".format(demonym, err))
self.verificationErrors.append("demonym: "+ str(name))

def test_all_countries_have_population(self):
for population in self.all_countries:
for name in self.all_countries:
try:
country = self.all_countries[population]
country.iso()
country = self.all_countries[name]
country.population()
except KeyError as err:
self.fail("Country '{0}' key error: {1}".format(population, err))
self.verificationErrors.append("population: "+ str(name))

def test_all_countries_have_provinces(self):
for provinces in self.all_countries:
for name in self.all_countries:
try:
country = self.all_countries[provinces]
country.iso()
country = self.all_countries[name]
country.provinces()
except KeyError as err:
self.fail("Country '{0}' key error: {1}".format(provinces, err))
self.verificationErrors.append("provinces: "+ str(name))

def test_all_countries_have_region(self):
for region in self.all_countries:
for name in self.all_countries:
try:
country = self.all_countries[region]
country.iso()
country = self.all_countries[name]
country.region()
except KeyError as err:
self.fail("Country '{0}' key error: {1}".format(region, err))
self.verificationErrors.append("region: "+ str(name))

def test_all_countries_have_subregion(self):
for subregion in self.all_countries:
for name in self.all_countries:
try:
country = self.all_countries[subregion]
country.iso()
country = self.all_countries[name]
country.subregion()
except KeyError as err:
self.fail("Country '{0}' key error: {1}".format(subregion, err))
self.verificationErrors.append("subregion: "+ str(name))

def test_all_countries_have_timezones(self):
for timezones in self.all_countries:
for name in self.all_countries:
try:
country = self.all_countries[timezones]
country.iso()
country = self.all_countries[name]
country.timezones()
except KeyError as err:
self.fail("Country '{0}' key error: {1}".format(timezones, err))
self.verificationErrors.append("timezones: "+ str(name))

def test_all_countries_have_tld(self):
for tld in self.all_countries:
for name in self.all_countries:
try:
country = self.all_countries[tld]
country.iso()
country = self.all_countries[name]
country.tld()
except KeyError as err:
self.fail("Country '{0}' key error: {1}".format(tld, err))
self.verificationErrors.append("tld "+ str(name))

def test_all_countries_have_wiki(self):
for wiki in self.all_countries:
for name in self.all_countries:
try:
country = self.all_countries[wiki]
country.iso()
country = self.all_countries[name]
country.wiki()
except KeyError as err:
self.fail("Country '{0}' key error: {1}".format(wiki, err))

self.verificationErrors.append("wiki: "+ str(name))

def test_select_country_from_alt_name(self):
country = CountryInfo('PK')
Expand Down

0 comments on commit 1ac103b

Please sign in to comment.