Skip to content

Commit

Permalink
Add more guide and test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
hongquan committed Nov 5, 2019
1 parent 0d67e82 commit 2aee4c7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 17 deletions.
16 changes: 16 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,26 @@ Install
Usage
-----

Call ``VietnamVehiclePlate.from_string``, passing the number string, to create ``VietnamVehiclePlate`` object.

.. code-block:: python
>>> from biensoxe import VietnamVehiclePlate
>>> VietnamVehiclePlate.from_string('44A-112.23')
VietnamVehiclePlate(compact='44A11223', vehicle_type=<VehicleType.DOMESTIC_AUTOMOBILE: 1>,
series='A', order='11223', locality='44', dip_country=None)
The method raises ``ValueError`` if the string could not be parsed.

To format the plate number as in daily life, pass ``VietnamVehiclePlate`` to ``str``:

.. code-block:: python
>>> plate = VietnamVehiclePlate.from_string('72E101130')
>>> plate
VietnamVehiclePlate(compact='72E101130', vehicle_type=<VehicleType.DOMESTIC_MOTORCYCLE_50_TO_175CC: 3>, series='E1', order='01130', locality='72', dip_country=None)
>>> str(plate)
'72-E1 011.30'
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.0'
__version__ = '0.8.1'

from .core import VietnamVehiclePlate, VehicleType # NOQA
2 changes: 1 addition & 1 deletion biensoxe/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class NonBusinessSpecialSeries(enum.Enum):
R = 'R' # 51R-14139


# This plate has yellow background
# This plate has yellow background
class SpecialEconomicZoneSeries(enum.Enum):
LB = 'LB' # Lao Bảo
CT = 'CT' # Cầu Treo
Expand Down
14 changes: 1 addition & 13 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "biensoxe"
version = "0.8.0"
version = "0.8.1"
description = "Library to parse and validate Vietnamese vehicle plate"
authors = ["Nguyễn Hồng Quân <[email protected]>"]
license = "MIT"
Expand All @@ -25,7 +25,6 @@ classifiers = [
[tool.poetry.dependencies]
python = "^3.7"
pydantic = "^1.0"
dedict = "^1.0.7"

[tool.poetry.dev-dependencies]
pytest = "^3.0"
Expand Down
10 changes: 10 additions & 0 deletions tests/test_biensoxe.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
('29MĐ1 94190', '29', 'MĐ1'),
)

diplomatic_data = (
('80-011-NG-01', '80', 'NG', '011'),
)


@pytest.mark.parametrize("original_string, locality, series", automobile_data)
def test_automobile(original_string, locality, series):
Expand Down Expand Up @@ -73,6 +77,12 @@ def test_high_capacity_motorcycle(original_string, locality, series):
assert plate.series == series


@pytest.mark.parametrize("original_string, locality, series, dip_country", diplomatic_data)
def test_diplomatic_vehicle(original_string, locality, series, dip_country):
plate = VietnamVehiclePlate.from_string(original_string)
assert plate.dip_country == dip_country


def test_invalid_plate_number():
with pytest.raises(ValueError):
VietnamVehiclePlate.from_string('XXYYZZ11')

0 comments on commit 2aee4c7

Please sign in to comment.