nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: joke2k/faker
Pull request #1852 (2023-04-24 12:43:21)

Improve fr_FR provider postcode
### What does this change

Improve postcode for fr_FR address provider

### What was wrong

The current provider may generate postcodes for invalid departments (any number starting with 96 is invalid)

### How this fixes it

Generate postcode from department codes


NB: I'm not sure how to test this commit : I could check that the generated postcode always match a department, but the test would be flaky before the fix... 

fcurella: we could just check that the first 2 characters are a valid department code? Better than nothing :)
tonial: I added the check.
And thanks to it, I noticed I previously made a mistake as if the department code is 2A or 2B, the postcode starts with 20....  
tonial: I fixed it :)

Patch:
diff --git a/faker/providers/address/fr_FR/__init__.py b/faker/providers/address/fr_FR/__init__.py
index fa7010da..1125716e 100644
--- a/faker/providers/address/fr_FR/__init__.py
+++ b/faker/providers/address/fr_FR/__init__.py
@@ -46,7 +46,6 @@ class Provider(AddressProvider):
     address_formats = ("{{street_address}}\n{{postcode}} {{city}}",)
 
     building_number_formats = ("%", "%#", "%#", "%#", "%##")
-    postcode_formats = ("#####",)
     countries = (
         "Afghanistan",
         "Afrique du sud",
@@ -467,3 +466,13 @@ class Provider(AddressProvider):
         :example: '59'
         """
         return self.department()[0]
+
+    def postcode(self) -> str:
+        """
+        Randomly returns a postcode generated from existing french depertment number.
+        exemple: '33260'
+        """
+        department = self.department_number()
+        if department in ["2A", "2B"]:
+            department = "20"
+        return f"{department}{self.random_number(digits=5 - len(department))}"


Test patch:
diff --git a/tests/providers/test_address.py b/tests/providers/test_address.py
index 0a0e2cbb..0e5c47ef 100644
--- a/tests/providers/test_address.py
+++ b/tests/providers/test_address.py
@@ -865,6 +865,17 @@ class TestFrFr:
             assert isinstance(department_number, str)
             assert department_number in department_numbers
 
+    def test_postcode(self, faker, num_samples):
+        department_numbers = [dept_num for dept_num, dept_name in FrFrAddressProvider.departments]
+        for _ in range(num_samples):
+            postcode = faker.postcode()
+            assert isinstance(postcode, str)
+            assert (
+                postcode[:3] in department_numbers  # for 3 digits deparments number
+                or postcode[:2] == "20"  # for Corsica : "2A" or "2B"
+                or postcode[:2] in department_numbers  # any other
+            )
+
 
 class TestHeIl:
     """Test he_IL address provider methods"""
Repository: joke2k/faker
Pull request #1858 (2023-05-03 06:17:52)

Add zh_CN automotive license_plate rules and test functions
### What does this change

add zh_CN automotive license_plate rules

### What was wrong

Was not implemented before.

### How this fixes it

will generate the fake license plate data in zh_CN locale



Patch:
diff --git a/faker/providers/automotive/zh_CN/__init__.py b/faker/providers/automotive/zh_CN/__init__.py
new file mode 100644
index 00000000..1982959f
--- /dev/null
+++ b/faker/providers/automotive/zh_CN/__init__.py
@@ -0,0 +1,47 @@
+from .. import Provider as AutomotiveProvider
+
+
+class Provider(AutomotiveProvider):
+    """
+    Implement automotive provider for `zh_CN` locale.
+    electric vehicles or downtown-restricted plates are not included
+    """
+
+    province_code = (
+        "京",
+        "津",
+        "冀",
+        "晋",
+        "蒙",
+        "辽",
+        "吉",
+        "黑",
+        "沪",
+        "苏",
+        "浙",
+        "皖",
+        "闽",
+        "赣",
+        "鲁",
+        "豫",
+        "鄂",
+        "湘",
+        "粤",
+        "桂",
+        "琼",
+        "渝",
+        "川",
+        "贵",
+        "云",
+        "藏",
+        "陕",
+        "甘",
+        "青",
+        "宁",
+        "新",
+    )
+
+    def license_plate(self) -> str:
+        """Generate a license plate."""
+        pattern: str = str(self.random_element(self.province_code)) + self.random_uppercase_letter() + "-#####"
+        return self.numerify(self.generator.parse(pattern))


Test patch:
diff --git a/tests/providers/test_automotive.py b/tests/providers/test_automotive.py
index 654d4388..62f725b0 100644
--- a/tests/providers/test_automotive.py
+++ b/tests/providers/test_automotive.py
@@ -318,6 +318,12 @@ class TestNlBe(_SimpleAutomotiveTestMixin):
     license_plate_pattern: Pattern = re.compile(r"(\d{3}-[A-Z]{3})|" r"([A-Z]{3}-\d{3})|" r"([1-2]-[A-Z]{3}-\d{3})")
 
 
+class TestZhCn(_SimpleAutomotiveTestMixin):
+    """Test zh_CN automotive provider methods"""
+
+    license_plate_pattern: Pattern = re.compile(r"^[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云渝藏陕甘青宁新]{1}[A-Z]{1}-[A-Z0-9]{5}")
+
+
 class TestZhTw(_SimpleAutomotiveTestMixin):
     """Test zh_TW automotive provider methods"""