Skip to content

Commit

Permalink
Add zh_CN automotive license_plate rules and test functions (#1858)
Browse files Browse the repository at this point in the history
* Add `license_plate` for `zh_CN`
  • Loading branch information
cyanghsieh committed May 8, 2023
1 parent 294768d commit 9a68dfd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
47 changes: 47 additions & 0 deletions faker/providers/automotive/zh_CN/__init__.py
Original file line number Diff line number Diff line change
@@ -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))
6 changes: 6 additions & 0 deletions tests/providers/test_automotive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down

0 comments on commit 9a68dfd

Please sign in to comment.