From 441723b9e0e4d23aa3311c29074bb6c2aac3fd3a Mon Sep 17 00:00:00 2001 From: armedHeistKino Date: Fri, 15 Nov 2024 03:46:42 +0900 Subject: [PATCH 1/7] Change format with better representation --- faker/providers/address/ko_KR/__init__.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/faker/providers/address/ko_KR/__init__.py b/faker/providers/address/ko_KR/__init__.py index 437a2c00de..0c08d3a511 100644 --- a/faker/providers/address/ko_KR/__init__.py +++ b/faker/providers/address/ko_KR/__init__.py @@ -454,12 +454,8 @@ class Provider(AddressProvider): "{{building_name}} {{building_dong}}동 ###호", ) road_formats = ( - "{{road_name}}{{road_suffix}} ###", - "{{road_name}}{{road_suffix}} 지하###", - "{{road_name}}{{road_suffix}} ###-##", - "{{road_name}}{{road_number}}{{road_suffix}} ###", - "{{road_name}}{{road_number}}{{road_suffix}} 지하###", - "{{road_name}}{{road_number}}{{road_suffix}} ###-##", + "{{road_name}}{{road_suffix}} {{building_number}}", + "{{road_name}}{{road_number}}{{road_suffix}} {{building_number}}", ) road_address_formats = ( "{{metropolitan_city}} {{borough}} {{road}}", From 5f2915578e601938700f26a0e51c50c07c22aa43 Mon Sep 17 00:00:00 2001 From: armedHeistKino Date: Fri, 15 Nov 2024 03:49:56 +0900 Subject: [PATCH 2/7] Add function generating building number --- faker/providers/address/ko_KR/__init__.py | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/faker/providers/address/ko_KR/__init__.py b/faker/providers/address/ko_KR/__init__.py index 0c08d3a511..b39e2a56d3 100644 --- a/faker/providers/address/ko_KR/__init__.py +++ b/faker/providers/address/ko_KR/__init__.py @@ -527,6 +527,44 @@ def road_suffix(self) -> str: """ return self.random_element(self.road_suffixes) + def building_number(self) -> str: + """ + :returns: A random building number + + Generates building number(건물 번호). There are 3 types of building number with current ROK addressing system. + (1) 19: A typical format. Only marks one building. + (2) 지하11: The building entrance is underground. + (3) 132-1: Several buildings are distinguished with sub-building-number(가지 번호). + + Generating probability is arbitrarily. + + :example: 19, 지하11, 143-1 + """ + if self.random_int() % 9 < 1: + return self.building_number_underground() + elif self.random_int() % 9 < 4: + return self.building_number_segregated() + else: + return self.generator.random.randint(1, 999) + + def building_number_underground(self) -> str: + """ + :returns: A random building number with undergrond entrances + + :example: 지하11 + """ + return "지하%d" % (self.generator.random.randint(1,999)) + + def building_number_segregated(self) -> str: + """ + :returns: A random building number distinguished with sub-building-number(가지 번호) + + :example: 143-1 + """ + main_building_number = self.generator.random.randint(1, 999) + sub_building_number = self.generator.random.randint(1, 99) + return "%d-%d" % (main_building_number, sub_building_number) + def metropolitan_city(self) -> str: """ :example: 서울특별시 From 8960ba532260aec12c357eefdb3deacff21e5c7b Mon Sep 17 00:00:00 2001 From: armedHeistKino Date: Fri, 15 Nov 2024 04:19:25 +0900 Subject: [PATCH 3/7] Add tests for building number methods --- tests/providers/test_address.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/providers/test_address.py b/tests/providers/test_address.py index a510132470..b8c893e8e7 100644 --- a/tests/providers/test_address.py +++ b/tests/providers/test_address.py @@ -1321,6 +1321,21 @@ def test_road_address(self, faker, num_samples): road_address = faker.road_address() assert isinstance(road_address, str) + def test_building_number(self, faker, num_samples): + for _ in range(num_samples): + building_number = faker.building_number() + assert isinstance(building_number, (str, int)) + + def test_building_number_underground(self, faker, num_samples): + for _ in range(num_samples): + building_number = faker.building_number_underground() + assert isinstance(building_number, str) + + def test_building_number_segregated(self, faker, num_samples): + for _ in range(num_samples): + building_number = faker.building_number_segregated() + assert isinstance(building_number, str) + class TestNeNp: """Test ne_NP address provider methods""" From 0d91207d32c199fad5d75388bc451293eddfe52e Mon Sep 17 00:00:00 2001 From: armedHeistKino Date: Fri, 15 Nov 2024 04:37:52 +0900 Subject: [PATCH 4/7] Reorder test methods alphabetically --- tests/providers/test_address.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/providers/test_address.py b/tests/providers/test_address.py index b8c893e8e7..179ceb6ad9 100644 --- a/tests/providers/test_address.py +++ b/tests/providers/test_address.py @@ -1305,6 +1305,21 @@ def test_building_name(self, faker, num_samples): building_name = faker.building_name() assert isinstance(building_name, str) + def test_building_number(self, faker, num_samples): + for _ in range(num_samples): + building_number = faker.building_number() + assert isinstance(building_number, (str, int)) + + def test_building_number_underground(self, faker, num_samples): + for _ in range(num_samples): + building_number = faker.building_number_underground() + assert isinstance(building_number, str) + + def test_building_number_segregated(self, faker, num_samples): + for _ in range(num_samples): + building_number = faker.building_number_segregated() + assert isinstance(building_number, str) + def test_building_suffix(self, faker, num_samples): for _ in range(num_samples): building_suffix = faker.building_suffix() @@ -1321,21 +1336,6 @@ def test_road_address(self, faker, num_samples): road_address = faker.road_address() assert isinstance(road_address, str) - def test_building_number(self, faker, num_samples): - for _ in range(num_samples): - building_number = faker.building_number() - assert isinstance(building_number, (str, int)) - - def test_building_number_underground(self, faker, num_samples): - for _ in range(num_samples): - building_number = faker.building_number_underground() - assert isinstance(building_number, str) - - def test_building_number_segregated(self, faker, num_samples): - for _ in range(num_samples): - building_number = faker.building_number_segregated() - assert isinstance(building_number, str) - class TestNeNp: """Test ne_NP address provider methods""" From 88d7ba45d9eb51a7b9619c2ea9ef279050697d7c Mon Sep 17 00:00:00 2001 From: armedHeistKino Date: Fri, 15 Nov 2024 13:27:34 +0900 Subject: [PATCH 5/7] Ensure method always returns a string type --- faker/providers/address/ko_KR/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/faker/providers/address/ko_KR/__init__.py b/faker/providers/address/ko_KR/__init__.py index b39e2a56d3..5d67409d5a 100644 --- a/faker/providers/address/ko_KR/__init__.py +++ b/faker/providers/address/ko_KR/__init__.py @@ -545,7 +545,7 @@ def building_number(self) -> str: elif self.random_int() % 9 < 4: return self.building_number_segregated() else: - return self.generator.random.randint(1, 999) + return "%d" % self.generator.random.randint(1, 999) def building_number_underground(self) -> str: """ From 3d89fb1b1d146e13b6e0c925b5268adb0b8c4791 Mon Sep 17 00:00:00 2001 From: armedHeistKino Date: Fri, 15 Nov 2024 13:28:54 +0900 Subject: [PATCH 6/7] Update assertation to check only for string type --- tests/providers/test_address.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/providers/test_address.py b/tests/providers/test_address.py index 179ceb6ad9..faea3c9171 100644 --- a/tests/providers/test_address.py +++ b/tests/providers/test_address.py @@ -1308,7 +1308,7 @@ def test_building_name(self, faker, num_samples): def test_building_number(self, faker, num_samples): for _ in range(num_samples): building_number = faker.building_number() - assert isinstance(building_number, (str, int)) + assert isinstance(building_number, str) def test_building_number_underground(self, faker, num_samples): for _ in range(num_samples): From 25c0b0952a26022d0dd4baa81b8dea9a8b1bf892 Mon Sep 17 00:00:00 2001 From: armedHeistKino Date: Thu, 21 Nov 2024 13:01:36 +0900 Subject: [PATCH 7/7] Add test cases --- tests/providers/test_address.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/providers/test_address.py b/tests/providers/test_address.py index faea3c9171..d677bffbd1 100644 --- a/tests/providers/test_address.py +++ b/tests/providers/test_address.py @@ -1309,16 +1309,21 @@ def test_building_number(self, faker, num_samples): for _ in range(num_samples): building_number = faker.building_number() assert isinstance(building_number, str) + assert '#' not in building_number def test_building_number_underground(self, faker, num_samples): for _ in range(num_samples): building_number = faker.building_number_underground() assert isinstance(building_number, str) + assert '#' not in building_number + assert building_number[:2] == '지하' def test_building_number_segregated(self, faker, num_samples): for _ in range(num_samples): building_number = faker.building_number_segregated() assert isinstance(building_number, str) + assert '#' not in building_number + assert '-' in building_number def test_building_suffix(self, faker, num_samples): for _ in range(num_samples):