Skip to content

Commit

Permalink
Add more checking
Browse files Browse the repository at this point in the history
  • Loading branch information
hongquan committed Nov 8, 2019
1 parent 2aee4c7 commit 6212162
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion biensoxe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '0.8.1'
__version__ = '0.8.2'

from .core import VietnamVehiclePlate, VehicleType # NOQA
7 changes: 5 additions & 2 deletions biensoxe/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,19 @@ def __str__(self):
return f'{self.locality}{self.series}-{order}'

@classmethod
def from_string(cls, number_sequence: str):
def from_string(cls, number_sequence: str) -> 'VietnamVehiclePlate':
"""Parse the number string of Vietnamese vehicle registration plate.
:param number_sequence: Number string as printed on the plate.
:return: :class:`VietnamVehiclePlate` object.
:raises ValueError: If the number string could not be parsed.
:raises TypeError: If the passed value is not a string.
"""
if not isinstance(number_sequence, str):
raise TypeError(f'Need a string, not {type(number_sequence)} type!')
compact = REGEX_CLEAN_PLATE_NUMBER.sub('', number_sequence.upper())
if not compact:
raise ValueError('Empty string')
raise ValueError('Empty string!')
for vtype, regex in REGEXES.items():
m = regex.fullmatch(compact)
if m:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "biensoxe"
version = "0.8.1"
version = "0.8.2"
description = "Library to parse and validate Vietnamese vehicle plate"
authors = ["Nguyễn Hồng Quân <[email protected]>"]
license = "MIT"
Expand Down
10 changes: 10 additions & 0 deletions tests/test_biensoxe.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,13 @@ def test_diplomatic_vehicle(original_string, locality, series, dip_country):
def test_invalid_plate_number():
with pytest.raises(ValueError):
VietnamVehiclePlate.from_string('XXYYZZ11')


def test_invalid_type():
with pytest.raises(TypeError):
VietnamVehiclePlate.from_string(123)


def test_not_accept_none():
with pytest.raises(TypeError):
VietnamVehiclePlate.from_string(None)

0 comments on commit 6212162

Please sign in to comment.