Esempio n. 1
0
    def test_territory_exception_definition(self):
        # Check that all codes used in constants to define exceptionnal
        # treatment are valid and recognized.
        for subdiv_code, alias_code in SUBDIVISION_ALIASES.items():
            self.assertIn(subdiv_code, supported_subdivision_codes())
            # Target alias is supposed to be a valid subdivision or country
            # recognized by pycountry right away.
            self.assertIn(
                alias_code,
                set(map(attrgetter('alpha_2'),
                        countries)).union(map(attrgetter('code'),
                                              subdivisions)))

        for country_code, alias_code in COUNTRY_ALIASES.items():
            # Aliased country codes are not supposed to be supported by
            # pycountry, as it's the main reason to define an alias in the
            # first place.
            self.assertNotIn(country_code, map(attrgetter('alpha_2'),
                                               countries))
            # Target alias is supposed to be a valid subdivision or country
            # recognized by pycountry right away.
            self.assertIn(
                alias_code,
                set(map(attrgetter('alpha_2'),
                        countries)).union(map(attrgetter('code'),
                                              subdivisions)))
Esempio n. 2
0
    def test_all_territory_codes(self) -> None:
        """Validate & render random addresses with all supported territories."""
        for territory_code in supported_subdivision_codes():
            address = random_address()
            address.country_code = None
            address.subdivision_code = territory_code
            address.normalize(strict=False)
            address.validate()
            address.render()

        for territory_code in supported_country_codes():
            address = random_address()
            address.country_code = territory_code
            address.subdivision_code = None
            address.normalize(strict=False)
            address.validate()
            address.render()
Esempio n. 3
0
    def test_all_territory_codes(self):
        """ Validate & render random addresses with all supported territories.
        """
        for territory_code in supported_subdivision_codes():
            address = random_address()
            address.country_code = None
            address.subdivision_code = territory_code
            address.normalize(strict=False)
            address.validate()
            address.render()

        for territory_code in supported_country_codes():
            address = random_address()
            address.country_code = territory_code
            address.subdivision_code = None
            address.normalize(strict=False)
            address.validate()
            address.render()
Esempio n. 4
0
    def test_territory_exception_definition(self):
        # Check that all codes used in constants to define exceptional
        # treatment are valid and recognized.
        for subdiv_code, alias_code in SUBDIVISION_COUNTRIES.items():
            self.assertIn(subdiv_code, supported_subdivision_codes())
            # Target alias is supposed to be a valid subdivision or country
            # recognized by pycountry right away.
            self.assertIn(alias_code, PYCOUNTRY_CC.union(PYCOUNTRY_SUB))

        for country_code, alias_code in COUNTRY_ALIASES.items():
            # Aliased country codes are not supposed to be supported by
            # pycountry, as it's the main reason to define an alias in the
            # first place.
            self.assertNotIn(country_code, PYCOUNTRY_CC)
            # Target alias is supposed to be a valid subdivision or country
            # recognized by pycountry right away.
            self.assertIn(alias_code, PYCOUNTRY_CC.union(PYCOUNTRY_SUB))

        for country_code, alias_code in RESERVED_COUNTRY_CODES.items():
            self.assertNotIn(country_code, PYCOUNTRY_CC)
            self.assertIn(alias_code, PYCOUNTRY_CC.union(PYCOUNTRY_SUB))
Esempio n. 5
0
    def test_territory_exception_definition(self):
        # Check that all codes used in constants to define exceptional
        # treatment are valid and recognized.
        for subdiv_code, alias_code in SUBDIVISION_COUNTRIES.items():
            self.assertIn(subdiv_code, supported_subdivision_codes())
            # Target alias is supposed to be a valid subdivision or country
            # recognized by pycountry right away.
            self.assertIn(alias_code, PYCOUNTRY_CC.union(PYCOUNTRY_SUB))

        for country_code, alias_code in COUNTRY_ALIASES.items():
            # Aliased country codes are not supposed to be supported by
            # pycountry, as it's the main reason to define an alias in the
            # first place.
            self.assertNotIn(country_code, PYCOUNTRY_CC)
            # Target alias is supposed to be a valid subdivision or country
            # recognized by pycountry right away.
            self.assertIn(alias_code, PYCOUNTRY_CC.union(PYCOUNTRY_SUB))

        for country_code, alias_code in RESERVED_COUNTRY_CODES.items():
            self.assertNotIn(country_code, PYCOUNTRY_CC)
            self.assertIn(alias_code, PYCOUNTRY_CC.union(PYCOUNTRY_SUB))
    def test_territory_exception_definition(self):
        # Check that all codes used in constants to define exceptionnal
        # treatment are valid and recognized.
        for subdiv_code, alias_code in SUBDIVISION_ALIASES.items():
            self.assertIn(subdiv_code, supported_subdivision_codes())
            # Target alias is supposed to be a valid subdivision or country
            # recognized by pycountry right away.
            self.assertIn(
                alias_code, set(imap(attrgetter('alpha2'), countries)).union(
                    imap(attrgetter('code'), subdivisions)))

        for country_code, alias_code in COUNTRY_ALIASES.items():
            # Aliased country codes are not supposed to be supported by
            # pycountry, as it's the main reason to define an alias in the
            # first place.
            self.assertNotIn(
                country_code, imap(attrgetter('alpha2'), countries))
            # Target alias is supposed to be a valid subdivision or country
            # recognized by pycountry right away.
            self.assertIn(
                alias_code, set(imap(attrgetter('alpha2'), countries)).union(
                    imap(attrgetter('code'), subdivisions)))
Esempio n. 7
0
 def test_supported_subdivision_codes(self):
     self.assertIn('FR-59', supported_subdivision_codes())
     self.assertNotIn('FR', supported_subdivision_codes())
     self.assertNotIn('UK', supported_subdivision_codes())
Esempio n. 8
0
 def test_supported_subdivision_codes(self):
     self.assertIn('FR-59', supported_subdivision_codes())
     self.assertNotIn('FR', supported_subdivision_codes())
     self.assertNotIn('UK', supported_subdivision_codes())
Esempio n. 9
0
 def test_supported_subdivision_codes(self) -> None:
     assert "FR-59" in supported_subdivision_codes()
     assert "FR" not in supported_subdivision_codes()
     assert "UK" not in supported_subdivision_codes()