From 6b79537ae5190dc3433db285c99243f532be66eb Mon Sep 17 00:00:00 2001 From: Hazel Noack Date: Thu, 12 Jun 2025 16:27:05 +0200 Subject: [PATCH] feat: implemented tests --- tests/test_fallback.py | 43 +++++++++++++++++++++++++++++++++++ tests/test_no_fallback.py | 48 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 tests/test_fallback.py create mode 100644 tests/test_no_fallback.py diff --git a/tests/test_fallback.py b/tests/test_fallback.py new file mode 100644 index 0000000..44e640b --- /dev/null +++ b/tests/test_fallback.py @@ -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() diff --git a/tests/test_no_fallback.py b/tests/test_no_fallback.py new file mode 100644 index 0000000..c35ab1c --- /dev/null +++ b/tests/test_no_fallback.py @@ -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()