Repository: joke2k/faker
Pull request #552 (2017-07-10 20:57:35)

New Provider: Automotive
This PR adds license plate generators for the following locales: `en_US`, `en_CA` and `en_GB`.


Patch:
diff --git a/faker/providers/automotive/__init__.py b/faker/providers/automotive/__init__.py
new file mode 100644
index 00000000..692d59db
--- /dev/null
+++ b/faker/providers/automotive/__init__.py
@@ -0,0 +1,17 @@
+# coding=utf-8
+
+localized = True
+
+from .. import BaseProvider
+from string import ascii_uppercase
+import re
+
+class Provider(BaseProvider):
+    license_formats = ()
+    
+    @classmethod
+    def license_plate(cls):
+        temp = re.sub(r'\?',
+            lambda x: cls.random_element(ascii_uppercase),
+            cls.random_element(cls.license_formats))
+        return cls.numerify(temp)
diff --git a/faker/providers/automotive/en_CA/__init__.py b/faker/providers/automotive/en_CA/__init__.py
new file mode 100644
index 00000000..473a7a42
--- /dev/null
+++ b/faker/providers/automotive/en_CA/__init__.py
@@ -0,0 +1,42 @@
+# coding=utf-8
+
+from __future__ import unicode_literals
+from .. import Provider as AutomotiveProvider
+
+
+class Provider(AutomotiveProvider):
+    # from https://www.revolvy.com/main/index.php?s=Canadian%20licence%20plate%20designs%20and%20serial%20formats
+    license_formats = (
+        # Alberta
+        '???-####',
+        # BC
+        '??# ##?',
+        '?? ####',
+        # Manitoba
+        '??? ###',
+        # New Brunswick
+        '??? ###',
+        # Newfoundland and Labrador
+        '??? ###',
+        # NWT
+        '######',
+        # Nova Scotia
+        '??? ###',
+        # Nunavut
+        '### ###',
+        # Ontario
+        '### ???',
+        '???? ###',
+        '??# ###',
+        '### #??',
+        '?? ####',
+        'GV??-###',
+        # PEI
+        '## ##??',
+        # Quebec
+        '?## ???',
+        # Saskatchewan
+        '### ???',
+        # Yukon
+        '???##'
+    )
\ No newline at end of file
diff --git a/faker/providers/automotive/en_GB/__init__.py b/faker/providers/automotive/en_GB/__init__.py
new file mode 100644
index 00000000..b84c1960
--- /dev/null
+++ b/faker/providers/automotive/en_GB/__init__.py
@@ -0,0 +1,12 @@
+# coding=utf-8
+
+from __future__ import unicode_literals
+from .. import Provider as AutomotiveProvider
+
+
+class Provider(AutomotiveProvider):
+    # from https://en.wikipedia.org/wiki/Vehicle_registration_plates_of_the_United_Kingdom
+    license_formats = (
+            '??## ???',
+            '??##???'
+        )
\ No newline at end of file
diff --git a/faker/providers/automotive/en_US/__init__.py b/faker/providers/automotive/en_US/__init__.py
new file mode 100644
index 00000000..8d2c9ea3
--- /dev/null
+++ b/faker/providers/automotive/en_US/__init__.py
@@ -0,0 +1,164 @@
+# coding=utf-8
+
+from __future__ import unicode_literals
+from .. import Provider as AutomotiveProvider
+
+class Provider(AutomotiveProvider):
+    # from https://en.wikipedia.org/wiki/United_States_license_plate_designs_and_serial_formats#Current_standard-issue_passenger_plate_designs_and_serial_formats
+    license_formats = (
+        # Alabama
+        '#??####',
+        '##??###',
+        # Alaska
+        '### ???',
+        # American Samoa
+        '####',
+        # Arizona
+        '???####',
+        # Arkansas
+        '### ???',
+        '###???',
+        # California
+        '#???###',
+        # Colarado
+        '###-???',
+        '???-###',
+        # Conneticut
+        '###-???',
+        # Delaware
+        '######',
+        # DC
+        '??-####',
+        # Florda
+        '??? ?##',
+        '### ???',
+        '?## #??',
+        '### #??',
+        # Georgia
+        '???####',
+        # Guam
+        '?? ####',
+        # Hawaii
+        '??? ###',
+        'H?? ###',
+        'Z?? ###',
+        'K?? ###',
+        'L?? ###',
+        'M?? ###',
+        # Idaho
+        '? ######',
+        '#? #####',
+        '#? ?####',
+        '#? ??###',
+        '#? #?#???',
+        '#? ####?',
+        '##? ####',
+        # Illinois
+        '?? #####',
+        '??# ####',
+        # Indiana
+        '###?',
+        '###??',
+        '###???',
+        # Iowa
+        '??? ###',
+        # Kansas
+        '### ???',
+        # Kentucky
+        '### ???',
+        # Louisiana
+        '### ???',
+        # Maine
+        '#### ??',
+        # Maryland
+        '#??####',
+        # Massachusetts
+        '#??? ##',
+        '#?? ###',
+        '### ??#',
+        '##? ?##',
+        # Michigan
+        '### ???',
+        '#?? ?##',
+        # Minnesota
+        '###-???',
+        # Mississippi
+        '??? ###',
+        # Missouri
+        '??# ?#?',
+        # Montana
+        '#-#####?',
+        '##-####?',
+        # Nebraska 
+        '??? ###',
+        '#-?####',
+        '##-?###',
+        '##-??##',
+        # Nevada
+        '##?•###',
+        # New Hampshire
+        '### ####',
+        # New Jersey
+        '?##-???',
+        # New Mexico
+        '###-???',
+        '???-###',
+        # New York
+        '???-####',
+        # North Carolina 
+        '###-????',
+        # North Dakota
+        '### ???',
+        # Nothern Mariana Islands
+        '??? ###',
+        # Ohio
+        '??? ####',
+        # Oklahoma
+        '???-###',
+        # Oregon
+        '### ???',
+        # Pennsylvania
+        '???-####',
+        # Peurto Rico
+        '???-###',
+        # Rhode Island
+        '###-###',
+        # South Carolina
+        '### #??',
+        # South Dakota
+        '#?? ###',
+        '#?? ?##',
+        '##? ###',
+        '##? ?##',
+        '##? ??#',
+        # Tennessee
+        '?##-##?',
+        # Texas 
+        '???-####',
+        # Utah
+        '?## #??',
+        '?## #??',
+        # Vermont
+        '??? ###',
+        '##??#',
+        '#??##',
+        '###?#',
+        '#?###',
+        # US Virgin Islands
+        '??? ###',
+        # Virginia
+        '???-####',
+        # Washington
+        '???####',
+        '###-???'
+        # West Virginia
+        '#?? ###',
+        '??? ###',
+        # Wisconsin
+        '???-####',
+        '###-???'
+        # Wyoming
+        '#-#####',
+        '#-####?',
+        '##-#####'
+    )
\ No newline at end of file


Test patch:
diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py
index cd84dead..cfdfe985 100644
--- a/tests/utils/__init__.py
+++ b/tests/utils/__init__.py
@@ -60,6 +60,7 @@ class UtilsTestCase(unittest.TestCase):
 
         expected_providers = list(map(str, [
             'faker.providers.address',
+            'faker.providers.automotive',
             'faker.providers.barcode',
             'faker.providers.color',
             'faker.providers.company',