Skip to content

Commit

Permalink
Add vi-VN automotive provider (#1639)
Browse files Browse the repository at this point in the history
* Add vi-VN automotive provider

* Update test_automotive.py

* Update test_automotive.py

Co-authored-by: Flavio Curella <89607+fcurella@users.noreply.github.com>
  • Loading branch information
zerogonal and fcurella committed Apr 28, 2022
1 parent 141cb8a commit d3f754b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
24 changes: 24 additions & 0 deletions faker/providers/automotive/vi_VN/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import re

from .. import Provider as AutomotiveProvider


class Provider(AutomotiveProvider):
"""Implement automotive provider for ``vi_VN`` locale.
Sources:
- https://en.wikipedia.org/wiki/Vehicle_registration_plates_of_Vietnam
"""

license_formats = ("##?-#####",)
ascii_uppercase_vietnamese = "ABCDĐEFGHKLMNPSTUVXYZ"

def license_plate(self) -> str:
"""Generate a license plate."""
temp = re.sub(
r"\?",
lambda x: self.random_element(self.ascii_uppercase_vietnamese),
self.random_element(self.license_formats),
)
return self.numerify(temp)
14 changes: 10 additions & 4 deletions tests/providers/test_automotive.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ def test_license_plate(self, faker, num_samples):
for _ in range(num_samples):
license_plate = faker.license_plate()
match = self.license_plate_pattern.fullmatch(license_plate)
assert match
assert match is not None
self.perform_extra_checks(license_plate, match)


class TestArBh(_SimpleAutomotiveTestMixin):
"""Test ar_BH automotive provider methods"""

license_plate_pattern: Pattern = re.compile(r"\d{6}")


class TestAzAz(_SimpleAutomotiveTestMixin):
"""Test az_AZ automotive provider methods"""

Expand Down Expand Up @@ -282,7 +288,7 @@ def test_plate_motorbike(self, faker, num_samples):
assert self.license_plate_motorbike_pattern.match(plate)


class TestArBh(_SimpleAutomotiveTestMixin):
"""Test ar_BH automotive provider methods"""
class TestViVn(_SimpleAutomotiveTestMixin):
"""Test vi_VN automotive provider methods"""

license_plate_pattern: Pattern = re.compile(r"\d{6}")
license_plate_pattern: Pattern = re.compile(r"\d{2}[ABCDĐEFGHKLMNPSTUVXYZ]-\d{5}")

0 comments on commit d3f754b

Please sign in to comment.