From d9d70c46020edf0fcae72fd51a8abd58516a34d2 Mon Sep 17 00:00:00 2001 From: Ali Yaman Date: Fri, 3 Jan 2025 22:15:35 +0100 Subject: [PATCH] Add support for Zulu (`zu_ZA`) address provider and corresponding tests (#2143) --- faker/providers/address/zu_ZA/__init__.py | 185 ++++++++++++++++++++++ tests/providers/test_address.py | 46 ++++++ 2 files changed, 231 insertions(+) create mode 100644 faker/providers/address/zu_ZA/__init__.py diff --git a/faker/providers/address/zu_ZA/__init__.py b/faker/providers/address/zu_ZA/__init__.py new file mode 100644 index 0000000000..f3a5bcda9e --- /dev/null +++ b/faker/providers/address/zu_ZA/__init__.py @@ -0,0 +1,185 @@ +from .. import Provider as AddressProvider + + +class Provider(AddressProvider): + """ + Address Provider for the zu_ZA locale (Zulu, South Africa). + + Data sourced from: + - South African cities and towns: https://en.wikipedia.org/wiki/List_of_cities_and_towns_in_South_Africa + - South African postal codes: https://en.wikipedia.org/wiki/List_of_postal_codes_in_South_Africa + - Languages of South Africa: https://en.wikipedia.org/wiki/Languages_of_South_Africa + """ + + city_formats = ("{{city_name}}",) + building_number_formats = ("%#", "%##", "%###") + postcode_formats = ("%###",) # Güncellendi: 4 haneli posta kodu için + section_formats = ("",) + street_address_formats = ("{{building_number}} {{street_name}} {{street_suffix}}",) + address_formats = ("{{street_address}}, {{city}}, {{postcode}}",) + secondary_address_formats = ("Flat #%#", "Unit #%#", "Suite #%#") + + street_names = ( + "Main", + "Church", + "President", + "Voortrekker", + "Nelson Mandela", + "Albertina Sisulu", + "Rivonia", + "Jan Smuts", + "Commissioner", + "Long", + "High", + "Short", + "Victoria", + "Queen", + "King", + "Oxford", + "George", + "William", + "York", + "Smith", + "Adelaide", + "Charles", + "Churchill", + "Cecil", + "Clarence", + "Edward", + "Elizabeth", + "Frere", + "Gandhi", + "Grey", + "James", + "Joseph", + "Milner", + "Napier", + "Paul Kruger", + "Prince", + "Somerset", + "Stanley", + "Thomas", + "Walter Sisulu", + "West", + ) + + street_suffixes = ("Umgwaqo", "Indlela", "Isitaladi", "Ithafa", "Indawo") + + cities = ( + "eGoli", + "eThekwini", + "iBhayi", + "iKapa", + "uMgungundlovu", + "Polokwane", + "Mbombela", + "Mahikeng", + "Kimberley", + "Bloemfontein", + "Rustenburg", + "Soweto", + "Benoni", + "Tembisa", + "Welkom", + "Vereeniging", + "Chatsworth", + "Uitenhage", + "Middelburg", + "Springs", + "Randfontein", + "Boksburg", + "Witbank", + "Klerksdorp", + "Bethlehem", + "George", + "Upington", + "Musina", + "Vanderbijlpark", + "Stellenbosch", + "Krugersdorp", + "Sasolburg", + "Centurion", + "Newcastle", + "Thohoyandou", + "Potchefstroom", + "Kathu", + "Paarl", + ) + + city_suffixes = ("",) + + countries = ( + "iNingizimu Afrika", + "Botswana", + "Lesotho", + "Namibia", + "Eswatini", + "Zimbabwe", + "Mozambique", + "Angola", + "Zambia", + "Malawi", + "Madagascar", + "Tanzania", + "Kenya", + "Nigeria", + "Ghana", + "Egypt", + "Morocco", + "Tunisia", + "Algeria", + "Ethiopia", + "Sudan", + "Somalia", + "Uganda", + "Cameroon", + "DR Congo", + "Rwanda", + "Burundi", + "Senegal", + "Mali", + "Ivory Coast", + "Niger", + "Chad", + "Mauritania", + "Eritrea", + "Djibouti", + "Cape Verde", + "Seychelles", + "Mauritius", + "Comoros", + "Gambia", + "Liberia", + "Sierra Leone", + "Benin", + "Togo", + "Equatorial Guinea", + "Gabon", + "Congo", + "Central African Republic", + "Sao Tome and Principe", + "Guinea", + "Guinea-Bissau", + "Burkina Faso", + ) + + def secondary_address(self) -> str: + return self.numerify(self.random_element(self.secondary_address_formats)) + + def building_number(self) -> str: + return self.numerify(self.random_element(self.building_number_formats)) + + def street_name(self) -> str: + return self.random_element(self.street_names) + + def street_suffix(self) -> str: + return self.random_element(self.street_suffixes) + + def city_name(self) -> str: + return self.random_element(self.cities) + + def city_name_suffix(self) -> str: + return self.random_element(self.city_suffixes) + + def section_number(self) -> str: + return self.numerify(self.random_element(self.section_formats)) diff --git a/tests/providers/test_address.py b/tests/providers/test_address.py index 2657bfbcc3..1202c968e5 100644 --- a/tests/providers/test_address.py +++ b/tests/providers/test_address.py @@ -56,6 +56,7 @@ from faker.providers.address.vi_VN import Provider as ViVNAddressProvider from faker.providers.address.zh_CN import Provider as ZhCnAddressProvider from faker.providers.address.zh_TW import Provider as ZhTwAddressProvider +from faker.providers.address.zu_ZA import Provider as ZuZaAddressProvider class TestBaseProvider: @@ -2584,3 +2585,48 @@ def test_postalcode(self, faker, num_samples): postalcode = faker.postalcode() match = re.findall(r"^^\d{2}-\d{3}$$", postalcode) assert match + + +class TestZuZa: + """Test zu_ZA address provider methods""" + + def test_postcode(self, faker, num_samples): + for _ in range(num_samples): + postcode = faker.postcode() + assert isinstance(postcode, str) + assert re.fullmatch(r"\d{4}", postcode) + + def test_city_name(self, faker, num_samples): + for _ in range(num_samples): + city_name = faker.city_name() + assert isinstance(city_name, str) + assert city_name in ZuZaAddressProvider.cities + + def test_city_suffix(self, faker, num_samples): + for _ in range(num_samples): + city_suffix = faker.city_suffix() + assert isinstance(city_suffix, str) + assert city_suffix in ZuZaAddressProvider.city_suffixes + + def test_city(self, faker, num_samples): + for _ in range(num_samples): + city = faker.city() + assert isinstance(city, str) + assert city in ZuZaAddressProvider.cities + + def test_country(self, faker, num_samples): + for _ in range(num_samples): + country = faker.country() + assert isinstance(country, str) + assert country in ZuZaAddressProvider.countries + + def test_street_name(self, faker, num_samples): + for _ in range(num_samples): + street_name = faker.street_name() + assert isinstance(street_name, str) + assert street_name in ZuZaAddressProvider.street_names + + def test_address(self, faker, num_samples): + for _ in range(num_samples): + address = faker.address() + assert isinstance(address, str)