feat: implemented tests

This commit is contained in:
Hazel Noack 2025-06-12 16:27:05 +02:00
parent 4abc43ac1c
commit 6b79537ae5
2 changed files with 91 additions and 0 deletions

43
tests/test_fallback.py Normal file
View File

@ -0,0 +1,43 @@
import unittest
from pycountry_wrapper import Country, EmptyCountry, config, EmptyCountryException
class TestCountry(unittest.TestCase):
def test_alpha_2(self):
config.fallback_country = "US"
c = Country("DE")
self.assertEqual(c.alpha_2, "DE")
def test_alpha_3(self):
config.fallback_country = "US"
c = Country("DEU")
self.assertEqual(c.alpha_2, "DE")
def test_fuzzy(self):
config.fallback_country = "US"
c = Country("Germany")
self.assertEqual(c.alpha_2, "DE")
def test_not_found(self):
config.fallback_country = "US"
c = Country("does not exist")
self.assertEqual(c.alpha_2, "US")
class TestEmptyCountry(unittest.TestCase):
def test_found(self):
config.fallback_country = "US"
c = EmptyCountry("DE")
self.assertEqual(type(c), Country)
self.assertEqual(c.alpha_2, "DE")
def test_not_found(self):
config.fallback_country = "US"
c = EmptyCountry("does not exist")
self.assertEqual(type(c), EmptyCountry)
self.assertEqual(c.alpha_2, None)
if __name__ == '__main__':
unittest.main()

48
tests/test_no_fallback.py Normal file
View File

@ -0,0 +1,48 @@
import unittest
from pycountry_wrapper import Country, EmptyCountry, config, EmptyCountryException
class TestCountry(unittest.TestCase):
def test_alpha_2(self):
config.fallback_country = None
c = Country("DE")
self.assertEqual(c.alpha_2, "DE")
def test_alpha_3(self):
config.fallback_country = None
c = Country("DEU")
self.assertEqual(c.alpha_2, "DE")
def test_fuzzy(self):
config.fallback_country = None
c = Country("Germany")
self.assertEqual(c.alpha_2, "DE")
def test_not_found(self):
config.fallback_country = None
with self.assertRaises(EmptyCountryException):
Country("does not exist")
class TestEmptyCountry(unittest.TestCase):
def test_found(self):
config.fallback_country = None
c = EmptyCountry("DE")
self.assertEqual(type(c), Country)
def test_data(self):
config.fallback_country = None
c = EmptyCountry("DE")
self.assertEqual(c.alpha_2, "DE")
def test_not_found(self):
config.fallback_country = None
c = EmptyCountry("does not exist")
self.assertEqual(type(c), EmptyCountry)
if __name__ == '__main__':
unittest.main()