From 2f69eec7fd97ccfcc257beae62beaa01f802a782 Mon Sep 17 00:00:00 2001 From: Flavio Curella Date: Tue, 15 Oct 2024 16:45:46 -0500 Subject: [PATCH] lint code --- faker/providers/job/ka_GE/__init__.py | 1 + tests/providers/test_color.py | 18 +- tests/providers/test_date_time.py | 20 +- tests/providers/test_job.py | 84 +++--- tests/providers/test_phone_number.py | 381 +++++++++++++------------- 5 files changed, 253 insertions(+), 251 deletions(-) diff --git a/faker/providers/job/ka_GE/__init__.py b/faker/providers/job/ka_GE/__init__.py index 6ce5e3883e..e98bdd56fc 100644 --- a/faker/providers/job/ka_GE/__init__.py +++ b/faker/providers/job/ka_GE/__init__.py @@ -1,5 +1,6 @@ from .. import Provider as BaseProvider + class Provider(BaseProvider): # Sourse: https://www.ganmarteba.ge/ jobs = [ diff --git a/tests/providers/test_color.py b/tests/providers/test_color.py index d88fc8d4c2..df83f0f56e 100644 --- a/tests/providers/test_color.py +++ b/tests/providers/test_color.py @@ -16,9 +16,9 @@ from faker.providers.color.he_IL import Provider as HeILColorProvider from faker.providers.color.hy_AM import Provider as HyAmColorProvider from faker.providers.color.id_ID import Provider as IdIdColorProvider +from faker.providers.color.ka_GE import Provider as KaGEColorProvider from faker.providers.color.sk_SK import Provider as SkSkColorProvider from faker.providers.color.vi_VN import Provider as ViVNColorProvider -from faker.providers.color.ka_GE import Provider as KaGEColorProvider class TestColorProvider: @@ -447,33 +447,33 @@ def test_safe_color_name(self, faker, num_samples): assert safe_color_name in IdIdColorProvider.safe_colors -class TestViVn: - """Test vi_VN color provider methods""" +class TestKaGe: + """Test Ka_GE color provider methods""" def test_color_name(self, faker, num_samples): for _ in range(num_samples): color_name = faker.color_name() assert isinstance(color_name, str) - assert color_name in ViVNColorProvider.all_colors.keys() + assert color_name in KaGEColorProvider.all_colors.keys() def test_safe_color_name(self, faker, num_samples): for _ in range(num_samples): safe_color_name = faker.safe_color_name() assert isinstance(safe_color_name, str) - assert safe_color_name in ViVNColorProvider.safe_colors + assert safe_color_name in KaGEColorProvider.safe_colors -class TestKaGe: - """Test Ka_GE color provider methods""" +class TestViVn: + """Test vi_VN color provider methods""" def test_color_name(self, faker, num_samples): for _ in range(num_samples): color_name = faker.color_name() assert isinstance(color_name, str) - assert color_name in KaGEColorProvider.all_colors.keys() + assert color_name in ViVNColorProvider.all_colors.keys() def test_safe_color_name(self, faker, num_samples): for _ in range(num_samples): safe_color_name = faker.safe_color_name() assert isinstance(safe_color_name, str) - assert safe_color_name in KaGEColorProvider.safe_colors + assert safe_color_name in ViVNColorProvider.safe_colors diff --git a/tests/providers/test_date_time.py b/tests/providers/test_date_time.py index 3a4eea3a17..0ad57b03e4 100644 --- a/tests/providers/test_date_time.py +++ b/tests/providers/test_date_time.py @@ -1375,37 +1375,37 @@ def test_traditional_month(self): assert month in JaJpProvider.TRADITIONAL_MONTH_NAMES.values() -class TestViVn(unittest.TestCase): - """Tests date_time in the vi_VN locale""" +class TestKaGe(unittest.TestCase): + """Test Ka_GE date_time provider methods""" def setUp(self): - self.fake = Faker("vi_VN") + self.fake = Faker("Ka_GE") Faker.seed(0) def test_day(self): day = self.fake.day_of_week() assert isinstance(day, str) - assert day in ViVNProvider.DAY_NAMES.values() + assert day in KaGeProvider.DAY_NAMES.values() def test_month(self): month = self.fake.month_name() assert isinstance(month, str) - assert month in ViVNProvider.MONTH_NAMES.values() + assert month in KaGeProvider.MONTH_NAMES.values() -class TestKaGe(unittest.TestCase): - """Test Ka_GE date_time provider methods""" +class TestViVn(unittest.TestCase): + """Tests date_time in the vi_VN locale""" def setUp(self): - self.fake = Faker("Ka_GE") + self.fake = Faker("vi_VN") Faker.seed(0) def test_day(self): day = self.fake.day_of_week() assert isinstance(day, str) - assert day in KaGeProvider.DAY_NAMES.values() + assert day in ViVNProvider.DAY_NAMES.values() def test_month(self): month = self.fake.month_name() assert isinstance(month, str) - assert month in KaGeProvider.MONTH_NAMES.values() + assert month in ViVNProvider.MONTH_NAMES.values() diff --git a/tests/providers/test_job.py b/tests/providers/test_job.py index 31c89ac95a..65d4bc00dd 100644 --- a/tests/providers/test_job.py +++ b/tests/providers/test_job.py @@ -26,6 +26,14 @@ def test_job(self, faker, num_samples): assert faker.job() in JobProvider.jobs +class TestAzAz: + """Test az_AZ job provider""" + + def test_job(self, faker, num_samples): + for _ in range(num_samples): + assert faker.job() in AzAzJobProvider.jobs + + class TestCsCz: """Test cs_CZ job provider""" @@ -36,28 +44,36 @@ def test_job(self, faker, num_samples): assert job in CsCzJobProvider.jobs -class TestAzAz: - """Test az_AZ job provider""" +class TestDeDe: + """Test de_DE job provider""" def test_job(self, faker, num_samples): for _ in range(num_samples): - assert faker.job() in AzAzJobProvider.jobs + assert faker.job() in DeDeJobProvider.jobs -class TestJaJp: - """Test ja_JP job provider""" +class TestElGr: + """Test el_GR job provider""" def test_job(self, faker, num_samples): for _ in range(num_samples): - assert faker.job() in JaJpJobProvider.jobs + assert faker.job() in ElGrJobProvider.jobs -class TestKoKr: - """Test ko_KR job provider""" +class TestEsEs: + """Test es job provider""" def test_job(self, faker, num_samples): for _ in range(num_samples): - assert faker.job() in KoKrJobProvider.jobs + assert faker.job() in EsEsJobProvider.jobs + + +class TestFrFr: + """Test fr_FR job provider""" + + def test_job(self, faker, num_samples): + for _ in range(num_samples): + assert faker.job() in FrFrJobProvider.jobs class TestHuHu: @@ -76,36 +92,38 @@ def test_job(self, faker, num_samples): assert faker.job() in HyAmJobProvider.jobs -class TestDeDe: - """Test de_DE job provider""" +class TestJaJp: + """Test ja_JP job provider""" def test_job(self, faker, num_samples): for _ in range(num_samples): - assert faker.job() in DeDeJobProvider.jobs + assert faker.job() in JaJpJobProvider.jobs -class TestFrFr: - """Test fr_FR job provider""" +class TestKaGe: + """Test ka_GE job provider""" def test_job(self, faker, num_samples): for _ in range(num_samples): - assert faker.job() in FrFrJobProvider.jobs + job = faker.job() + assert isinstance(job, str) + assert job in ViVNJobProvider.jobs -class TestElGr: - """Test el_GR job provider""" +class TestKoKr: + """Test ko_KR job provider""" def test_job(self, faker, num_samples): for _ in range(num_samples): - assert faker.job() in ElGrJobProvider.jobs + assert faker.job() in KoKrJobProvider.jobs -class TestEsEs: - """Test es job provider""" +class TestPtBr: + """Test pt_BR job provider""" def test_job(self, faker, num_samples): for _ in range(num_samples): - assert faker.job() in EsEsJobProvider.jobs + assert faker.job() in PtBrJobProvider.jobs class TestPtPt: @@ -116,12 +134,11 @@ def test_job(self, faker, num_samples): assert faker.job() in PtPtJobProvider.jobs -class TestPtBr: - """Test pt_BR job provider""" +class TestRoRo: + """Test Ro_RO job provider""" def test_job(self, faker, num_samples): - for _ in range(num_samples): - assert faker.job() in PtBrJobProvider.jobs + assert faker.job() in RoRoJobProvider.jobs class TestSkSk: @@ -148,13 +165,6 @@ def test_job(self, faker, num_samples): assert faker.job() in TrTrJobProvider.jobs -class TestRoRo: - """Test Ro_RO job provider""" - - def test_job(self, faker, num_samples): - assert faker.job() in RoRoJobProvider.jobs - - class TestViVn: """Test vi_VN job provider""" @@ -163,13 +173,3 @@ def test_job(self, faker, num_samples): job = faker.job() assert isinstance(job, str) assert job in ViVNJobProvider.jobs - - -class TestKaGe: - """Test ka_GE job provider""" - - def test_job(self, faker, num_samples): - for _ in range(num_samples): - job = faker.job() - assert isinstance(job, str) - assert job in ViVNJobProvider.jobs diff --git a/tests/providers/test_phone_number.py b/tests/providers/test_phone_number.py index 42b5d74352..d276eecb2c 100644 --- a/tests/providers/test_phone_number.py +++ b/tests/providers/test_phone_number.py @@ -22,6 +22,50 @@ def test_msisdn(self, faker, num_samples): assert msisdn.isdigit() +class TestArAe: + """Test ar_AE phone number provider methods""" + + cellphone_pattern: str = r"(?:\+|00)971\s?5[024568]\s?\d{3}\s?\d{4}|" r"05[024568]\s?\d{3}\s?\d{4}" + telephone_pattern: str = r"(?:\+|00)971\s?[1234679]\s?\d{3}\s?\d{4}|" r"0[1234679]\s?\d{3}\s?\d{4}" + toll_pattern: str = r"200\d{4}|" r"600\d{6}|" r"800\d{3,7}" + service_phone_pattern: str = r"9(?:9(?:9|8|7|6|1)|01|22)" + + def test_cellphone_number(self, faker, num_samples): + pattern: Pattern = re.compile(self.cellphone_pattern) + for _ in range(num_samples): + cellphone = faker.cellphone_number() + assert pattern.fullmatch(cellphone) + + def test_telephone_number(self, faker, num_samples): + pattern: Pattern = re.compile(self.telephone_pattern) + for _ in range(num_samples): + telephone = faker.telephone_number() + assert pattern.fullmatch(telephone) + + def test_toll_number(self, faker, num_samples): + pattern: Pattern = re.compile(self.toll_pattern) + for _ in range(num_samples): + toll = faker.toll_number() + assert pattern.fullmatch(toll) + + def test_service_phone_number(self, faker, num_samples): + pattern: Pattern = re.compile(self.service_phone_pattern) + for _ in range(num_samples): + service = faker.service_phone_number() + assert pattern.fullmatch(service) + + def test_phone_number(self, faker, num_samples): + pattern: Pattern = re.compile( + rf"{self.cellphone_pattern}|" + rf"{self.telephone_pattern}|" + rf"{self.toll_pattern}|" + rf"{self.service_phone_pattern}", + ) + for _ in range(num_samples): + phone = faker.phone_number() + assert pattern.fullmatch(phone) + + class TestAzAz: """Test az_AZ phone number provider methods""" @@ -53,16 +97,6 @@ def test_landline_number(self, faker, num_samples): assert self.landline_patterns.fullmatch(landline_number) -class TestJaJp: - """Test ja_JP phone number provider methods""" - - def test_phone_number(self, faker, num_samples): - for _ in range(num_samples): - pattern: Pattern = re.compile(r"(?:0[789]0|\d{2})-\d{4}-\d{4}") - phone_number = faker.phone_number() - assert pattern.fullmatch(phone_number) - - class TestCsCz: """Test cs_CZ phone number provider methods""" @@ -73,98 +107,6 @@ def test_phone_number(self, faker, num_samples): assert pattern.fullmatch(phone_number) -class TestSkSk: - """Test sk_SK phone number provider methods""" - - def test_phone_number(self, faker, num_samples): - pattern: Pattern = re.compile( - r"(^(00421|\+421)? ?[2] ?[0-9]{8}$)|" - r"(^(00421|\+421)? ?[3-5][0-9] ?[0-9]{3} ?[0-9]{4}$)|" - r"(^(00421|\+421)? ?[9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$)" - ) - - for _ in range(num_samples): - phone_number = faker.phone_number() - assert pattern.fullmatch(phone_number) - - -class TestPtBr: - """Test pt_BR phone number provider methods""" - - def test_phone_number(self, faker, num_samples): - pattern: Pattern = re.compile( - r"(?:\+55 )?" r"(?:[1-8]1|84|\((?:0[1-8]1|084)\))" r" \d{4}[ -]\d{4}|" r"\d{4}?[ -]\d{3}[ -]\d{4}", - ) - for _ in range(num_samples): - phone_number = faker.phone_number() - assert pattern.fullmatch(phone_number) - - def test_msisdn(self, faker, num_samples): - pattern: Pattern = re.compile(r"55(?:[1-8]19|849)\d{8}") - for _ in range(num_samples): - msisdn = faker.msisdn() - assert pattern.fullmatch(msisdn) - - def test_cellphone(self, faker, num_samples): - pattern: Pattern = re.compile( - r"(?:\+55 )?" r"(?:\d{2}|\(0?\d{2}\))" r" 9 ?\d{4}[ -]\d{4}", - ) - for _ in range(num_samples): - cellphone = faker.cellphone_number() - assert pattern.fullmatch(cellphone) - - def test_service_phone(self, faker, num_samples): - pattern: Pattern = re.compile(r"1(?:0|2|5|8|9)?(?:[0-9])") - for _ in range(num_samples): - service = faker.service_phone_number() - assert pattern.fullmatch(service) - - -class TestHuHu: - """Test hu_HU phone number provider methods""" - - def test_phone_number(self, faker, num_samples): - pattern: Pattern = re.compile( - r"(?:" r"\+36 \d{2} |" r"\(06\)\d{2}/|" r"\(\d{2}\)/|" r"\d{2}/|" r"06-\d{1,2}/" r")\d{3}[- ]\d{4}", - ) - for _ in range(num_samples): - phone_number = faker.phone_number() - assert isinstance(phone_number, str) - assert pattern.fullmatch(phone_number) - - -class TestThTh: - """Test th_TH phone number provider methods""" - - def test_phone_number(self, faker, num_samples): - pattern: Pattern = re.compile( - # leading zero or internaional code - r"((\+66)|\+66[ -]?\(0\)|0)[ -]?" - # landline or mobile - r"([23457][ -]?(\d[ -]?){6}\d|[689][ -]?(\d[ -]?){7}\d)" - # extension - r"([ ]?(x|ext|ต่อ)[\.]?[ ]?\d{1,5})?", - re.IGNORECASE, - ) - for _ in range(num_samples): - phone_number = faker.phone_number() - assert isinstance(phone_number, str) - assert pattern.fullmatch(phone_number) - - -class TestHyAm: - """Test hy_AM phone number provider methods""" - - def test_phone_number(self, faker, num_samples): - pattern: Pattern = re.compile( - r"(?:[23]\d{2}-|\([23]\d{2}\) |[23]\d{2}\.)\d{5}|" r"(?:(?:10|9\d)-|\((?:10|9\d)\) |(?:10|9\d)\.)\d{6}", - ) - for _ in range(num_samples): - phone_number = faker.phone_number() - assert isinstance(phone_number, str) - assert pattern.fullmatch(phone_number) - - class TestEnPh: """Test en_PH phone number provider methods""" @@ -269,49 +211,133 @@ def test_landline_number(self, faker, num_samples): assert non_area2_match.group(1) in self.non_area2_landline_area_codes +class TestEnUs: + """Test En_US phone provider methods""" + + def test_basic_phone_number(self, faker, num_samples): + pattern_no_whitespaces: Pattern = re.compile( + r"\d{9}", + ) + pattern_dashes: Pattern = re.compile(r"\d{3}-\d{3}-\d{4}") + pattern_parens: Pattern = re.compile(r"\(\d{3}\)\d{3}-\d{4}") + patterns = [pattern_no_whitespaces, pattern_dashes, pattern_parens] + for _ in range(num_samples): + phone_number = faker.basic_phone_number() + + pattern_is_found = False + for pattern in patterns: + if re.match(pattern, phone_number): + pattern_is_found = True + break + assert pattern_is_found + + +class TestEsCo: + """Test es_CO phone number provider methods""" + + def test_phone_number(self, faker, num_samples): + pattern: Pattern = re.compile( + r"((\+?57|\(\+57\))?60\d)?\d{7}|" + r"((\+?57 |\(\+57\) )?60\d )?\d{3} \d{2} \d{2}|" + r"(\+?57|\(\+57\))?3[012]\d{8}|" + r"(\+?57 |\(\+57\) )?3[012]\d \d{3} \d{2} \d{2}|" + r"01800\d{7}|" + r"01 800\d \d{3} \d{3}" + ) + for _ in range(num_samples): + phone_number = faker.phone_number() + assert pattern.fullmatch(phone_number) + + +class TestEsEs: + """Test es_ES phone number provider methods""" + + def test_phone_number(self, faker, num_samples): + pattern: Pattern = re.compile( + r"\+34 ?(?:7[0-4]|[689]\d)\d" r"(?: \d{3} \d{3}|\d{6}| \d{2} \d{2} \d{2})", + ) + for _ in range(num_samples): + phone_number = faker.phone_number() + assert pattern.fullmatch(phone_number) + + class TestFilPh(TestEnPh): """Test fil_PH phone number provider methods""" pass -class TestTlPh(TestEnPh): - """Test tl_PH phone number provider methods""" +class TestFrFr: + def test_phone_number(self, faker, num_samples): + pattern_no_whitespaces: Pattern = re.compile( + r"^0\d{9}$", + ) + pattern_no_country_prefix: Pattern = re.compile( + r"^0\d \d{2} \d{2} \d{2} \d{2}$", + ) + pattern_country_prefix_1: Pattern = re.compile( + r"^\+33 \(0\)\d \d{2} \d{2} \d{2} \d{2}$", + ) + pattern_country_prefix_2: Pattern = re.compile( + r"^\+33 \d \d{2} \d{2} \d{2} \d{2}$", + ) + patterns = [ + pattern_no_whitespaces, + pattern_no_country_prefix, + pattern_country_prefix_1, + pattern_country_prefix_2, + ] + for _ in range(num_samples): + phone_number = faker.phone_number() - pass + pattern_is_found = False + + for pattern in patterns: + if re.match(pattern, phone_number): + pattern_is_found = True + break + assert pattern_is_found -class TestTaIn: - """Test ta_IN phone number provider methods""" +class TestHuHu: + """Test hu_HU phone number provider methods""" def test_phone_number(self, faker, num_samples): pattern: Pattern = re.compile( - r"\+91 \d{3} ?\d{7}|" r"0\d{2}(-)?\d{2}(?(1)| ?)\d{6}", + r"(?:" r"\+36 \d{2} |" r"\(06\)\d{2}/|" r"\(\d{2}\)/|" r"\d{2}/|" r"06-\d{1,2}/" r")\d{3}[- ]\d{4}", ) for _ in range(num_samples): phone_number = faker.phone_number() + assert isinstance(phone_number, str) assert pattern.fullmatch(phone_number) -class TestEsCo: - """Test es_CO phone number provider methods""" +class TestHyAm: + """Test hy_AM phone number provider methods""" def test_phone_number(self, faker, num_samples): pattern: Pattern = re.compile( - r"((\+?57|\(\+57\))?60\d)?\d{7}|" - r"((\+?57 |\(\+57\) )?60\d )?\d{3} \d{2} \d{2}|" - r"(\+?57|\(\+57\))?3[012]\d{8}|" - r"(\+?57 |\(\+57\) )?3[012]\d \d{3} \d{2} \d{2}|" - r"01800\d{7}|" - r"01 800\d \d{3} \d{3}" + r"(?:[23]\d{2}-|\([23]\d{2}\) |[23]\d{2}\.)\d{5}|" r"(?:(?:10|9\d)-|\((?:10|9\d)\) |(?:10|9\d)\.)\d{6}", ) for _ in range(num_samples): + phone_number = faker.phone_number() + assert isinstance(phone_number, str) + assert pattern.fullmatch(phone_number) + + +class TestJaJp: + """Test ja_JP phone number provider methods""" + + def test_phone_number(self, faker, num_samples): + for _ in range(num_samples): + pattern: Pattern = re.compile(r"(?:0[789]0|\d{2})-\d{4}-\d{4}") phone_number = faker.phone_number() assert pattern.fullmatch(phone_number) class TestKaGe: """Test ka_GE phone number provider methods""" + pattern = re.compile( r"(?:" r"\+995 \d{3} \d{3} \d{3}|" # Example: +995 123 456 789 @@ -333,113 +359,88 @@ def test_phone_number(self, faker, num_samples): assert self.pattern.fullmatch(phone_number) -class TestEsEs: - """Test es_ES phone number provider methods""" +class TestPtBr: + """Test pt_BR phone number provider methods""" def test_phone_number(self, faker, num_samples): pattern: Pattern = re.compile( - r"\+34 ?(?:7[0-4]|[689]\d)\d" r"(?: \d{3} \d{3}|\d{6}| \d{2} \d{2} \d{2})", + r"(?:\+55 )?" r"(?:[1-8]1|84|\((?:0[1-8]1|084)\))" r" \d{4}[ -]\d{4}|" r"\d{4}?[ -]\d{3}[ -]\d{4}", ) for _ in range(num_samples): phone_number = faker.phone_number() assert pattern.fullmatch(phone_number) + def test_msisdn(self, faker, num_samples): + pattern: Pattern = re.compile(r"55(?:[1-8]19|849)\d{8}") + for _ in range(num_samples): + msisdn = faker.msisdn() + assert pattern.fullmatch(msisdn) -class TestArAe: - """Test ar_AE phone number provider methods""" - - cellphone_pattern: str = r"(?:\+|00)971\s?5[024568]\s?\d{3}\s?\d{4}|" r"05[024568]\s?\d{3}\s?\d{4}" - telephone_pattern: str = r"(?:\+|00)971\s?[1234679]\s?\d{3}\s?\d{4}|" r"0[1234679]\s?\d{3}\s?\d{4}" - toll_pattern: str = r"200\d{4}|" r"600\d{6}|" r"800\d{3,7}" - service_phone_pattern: str = r"9(?:9(?:9|8|7|6|1)|01|22)" - - def test_cellphone_number(self, faker, num_samples): - pattern: Pattern = re.compile(self.cellphone_pattern) + def test_cellphone(self, faker, num_samples): + pattern: Pattern = re.compile( + r"(?:\+55 )?" r"(?:\d{2}|\(0?\d{2}\))" r" 9 ?\d{4}[ -]\d{4}", + ) for _ in range(num_samples): cellphone = faker.cellphone_number() assert pattern.fullmatch(cellphone) - def test_telephone_number(self, faker, num_samples): - pattern: Pattern = re.compile(self.telephone_pattern) - for _ in range(num_samples): - telephone = faker.telephone_number() - assert pattern.fullmatch(telephone) - - def test_toll_number(self, faker, num_samples): - pattern: Pattern = re.compile(self.toll_pattern) - for _ in range(num_samples): - toll = faker.toll_number() - assert pattern.fullmatch(toll) - - def test_service_phone_number(self, faker, num_samples): - pattern: Pattern = re.compile(self.service_phone_pattern) + def test_service_phone(self, faker, num_samples): + pattern: Pattern = re.compile(r"1(?:0|2|5|8|9)?(?:[0-9])") for _ in range(num_samples): service = faker.service_phone_number() assert pattern.fullmatch(service) + +class TestSkSk: + """Test sk_SK phone number provider methods""" + def test_phone_number(self, faker, num_samples): pattern: Pattern = re.compile( - rf"{self.cellphone_pattern}|" - rf"{self.telephone_pattern}|" - rf"{self.toll_pattern}|" - rf"{self.service_phone_pattern}", + r"(^(00421|\+421)? ?[2] ?[0-9]{8}$)|" + r"(^(00421|\+421)? ?[3-5][0-9] ?[0-9]{3} ?[0-9]{4}$)|" + r"(^(00421|\+421)? ?[9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$)" ) + for _ in range(num_samples): - phone = faker.phone_number() - assert pattern.fullmatch(phone) + phone_number = faker.phone_number() + assert pattern.fullmatch(phone_number) -class TestFrFr: +class TestTaIn: + """Test ta_IN phone number provider methods""" + def test_phone_number(self, faker, num_samples): - pattern_no_whitespaces: Pattern = re.compile( - r"^0\d{9}$", - ) - pattern_no_country_prefix: Pattern = re.compile( - r"^0\d \d{2} \d{2} \d{2} \d{2}$", - ) - pattern_country_prefix_1: Pattern = re.compile( - r"^\+33 \(0\)\d \d{2} \d{2} \d{2} \d{2}$", - ) - pattern_country_prefix_2: Pattern = re.compile( - r"^\+33 \d \d{2} \d{2} \d{2} \d{2}$", + pattern: Pattern = re.compile( + r"\+91 \d{3} ?\d{7}|" r"0\d{2}(-)?\d{2}(?(1)| ?)\d{6}", ) - patterns = [ - pattern_no_whitespaces, - pattern_no_country_prefix, - pattern_country_prefix_1, - pattern_country_prefix_2, - ] for _ in range(num_samples): phone_number = faker.phone_number() - - pattern_is_found = False - - for pattern in patterns: - if re.match(pattern, phone_number): - pattern_is_found = True - break - assert pattern_is_found + assert pattern.fullmatch(phone_number) -class TestEnUs: - """Test En_US phone provider methods""" +class TestThTh: + """Test th_TH phone number provider methods""" - def test_basic_phone_number(self, faker, num_samples): - pattern_no_whitespaces: Pattern = re.compile( - r"\d{9}", + def test_phone_number(self, faker, num_samples): + pattern: Pattern = re.compile( + # leading zero or internaional code + r"((\+66)|\+66[ -]?\(0\)|0)[ -]?" + # landline or mobile + r"([23457][ -]?(\d[ -]?){6}\d|[689][ -]?(\d[ -]?){7}\d)" + # extension + r"([ ]?(x|ext|ต่อ)[\.]?[ ]?\d{1,5})?", + re.IGNORECASE, ) - pattern_dashes: Pattern = re.compile(r"\d{3}-\d{3}-\d{4}") - pattern_parens: Pattern = re.compile(r"\(\d{3}\)\d{3}-\d{4}") - patterns = [pattern_no_whitespaces, pattern_dashes, pattern_parens] for _ in range(num_samples): - phone_number = faker.basic_phone_number() + phone_number = faker.phone_number() + assert isinstance(phone_number, str) + assert pattern.fullmatch(phone_number) - pattern_is_found = False - for pattern in patterns: - if re.match(pattern, phone_number): - pattern_is_found = True - break - assert pattern_is_found + +class TestTlPh(TestEnPh): + """Test tl_PH phone number provider methods""" + + pass class TestViVn: