diff --git a/countryinfo/data/holy_see_vatican_city.json b/countryinfo/data/holy_see_vatican_city.json index 85dd348..9c8d706 100644 --- a/countryinfo/data/holy_see_vatican_city.json +++ b/countryinfo/data/holy_see_vatican_city.json @@ -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"} \ No newline at end of file diff --git a/tests.py b/tests.py index b7b253e..f7d3b61 100644 --- a/tests.py +++ b/tests.py @@ -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: @@ -16,13 +18,18 @@ 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: @@ -30,7 +37,7 @@ def test_all_countries_have_native_name(self): 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: @@ -38,7 +45,7 @@ def test_all_countries_have_iso(self): 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: @@ -46,7 +53,7 @@ def test_all_countries_have_alt_spellings(self): 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: @@ -54,120 +61,119 @@ def test_all_countries_have_translations(self): 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')