Skip to content

Commit

Permalink
Model year check in Vin.verify_checksum() is now optional, on by def…
Browse files Browse the repository at this point in the history
…ault (see #19).
  • Loading branch information
idlesign committed Dec 25, 2021
1 parent 4a0dc13 commit 06ea679
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ vininfo changelog
=================


Unreleased
----------
+ Model year check in Vin.verify_checksum() is now optional, on by default (see #19).


v1.6.0 [2021-08-30]
-------------------
+ WMI dict is updated.
Expand Down
6 changes: 6 additions & 0 deletions tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def test_checksum():
# faked
assert not Vin('1M8GDM9AyKP042788').verify_checksum()

# non strict
non_strict = Vin('WBA71DC010CH14720')
assert non_strict.verify_checksum(check_year=False)
assert not non_strict.verify_checksum()


def test_unsupported_brand():

Expand All @@ -58,6 +63,7 @@ def test_merge_wmi():
assert " '1D': 'Dodge',\n '1DTEST': 'Some'," in lines
assert " '1GT': 'GMC Truck',\n '1GTEST': 'Other'," in lines


def test_squish_vin():
assert Vin('KF1SF08WJ8B257338').squish_vin == 'KF1SF08W8B'

7 changes: 5 additions & 2 deletions vininfo/toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ def validate(self, num: str) -> str:

return num

def verify_checksum(self) -> bool:
def verify_checksum(self, *, check_year: bool = True) -> bool:
"""Performs checksum verification.
.. warning:: Not every manufacturer uses VIN checksum rules.
:param check_year: Whether to also check the model year.
Defaults to False since not all manufacturer abey the rule.
"""
if self.vis[0] in {'U', 'Z', '0'}:
if check_year and self.vis[0] in {'U', 'Z', '0'}:
return False

trans = {
Expand Down

0 comments on commit 06ea679

Please sign in to comment.