def test_nissan(): vin = Vin('5N1NJ01CXST000001') assert '%s' % vin assert vin.wmi == '5N1' assert vin.manufacturer == 'Nissan' assert vin.vds == 'NJ01CX' assert vin.vis == 'ST000001' assert vin.years == [1995] assert vin.region_code == '5' assert vin.region == 'North America' assert vin.country_code == '5N' assert vin.country == 'United States' assert '%s' % vin.brand == 'Nissan (Nissan)' details = vin.details assert details.model_code == 'J' assert details.model == ['Maxima'] assert details.body_code == '1' assert details.body == ['4-Door Sedan', 'Standard Body Truck'] assert details.engine_code == 'N' assert details.engine == ['VH45DE'] assert details.plant_code == 'T' assert details.plant == ['Tochigi', 'Oppama'] assert details.serial == '000001' assert vin.verify_checksum()
def test_validation(): with pytest.raises(ValidationError): Vin('tooshort') with pytest.raises(ValidationError): Vin('AAAAAAAAAAAAAAAAO')
def validate_vin_code(value): try: Vin.validate(value) except VinValidationError as e: raise ValidationError( _(e.message), params={'value': value}, )
def test_basic(): # number faked vin = Vin('JSA12345678901234') assert vin.manufacturer == 'Suzuki' assert not vin.manufacturer_is_small # number faked assert Vin('TM912345678901234').manufacturer_is_small
def test_opel(): vin = Vin('W0LPC6DB3CC123456') assert '%s' % vin assert vin.wmi == 'W0L' assert vin.manufacturer == 'Opel/Vauxhall' assert vin.vds == 'PC6DB3' assert vin.vis == 'CC123456' assert vin.years == [2012, 1982] assert vin.region_code == 'W' assert vin.region == 'Europe' assert vin.country_code == 'W0' assert vin.country == 'Germany' assert '%s' % vin.brand == 'Opel (Opel/Vauxhall)' details = vin.details assert details.model.code == 'P' assert details.model.name == ['Astra J', 'Zafira C'] assert details.body.code == '6' assert details.body.name == 'Hatchback, 5-Door' assert details.engine.code == 'B' assert details.engine.name == 'A14XER100HP' assert details.plant.code == 'C' assert details.plant.name == 'Yelabuga' assert details.serial.code == '123456'
def test_renault(): vin = Vin('VF14SRAP451234567') assert '%s' % vin assert vin.wmi == 'VF1' assert vin.manufacturer == 'Renault' assert vin.vds == '4SRAP4' assert vin.vis == '51234567' assert vin.years == [2005] assert vin.region_code == 'V' assert vin.region == 'Europe' assert vin.country_code == 'VF' assert vin.country == 'France' assert '%s' % vin.brand == 'Renault (Renault)' details = vin.details assert details.model.code == 'S' assert details.model.name == [ 'Logan', 'Sandero', 'Duster', 'Dokker', 'Lodgy' ] assert details.body.code == '4' assert details.body.name == 'Sedan, 4-Door' assert details.plant.code == 'P' assert details.plant.name == 'Mexico' assert details.transmission.code == '4' assert details.transmission.name == 'Manual, 5-Gears' assert details.serial.code == '1234567'
def check(vin): """Perform VIN checksum validation""" if Vin(vin).verify_checksum(): click.secho('Checksum is valid', fg='green') else: click.secho('Checksum is not valid', fg='red', err=True) sys.exit(1)
def test_lada(): vin = Vin('XTAGFK330JY144213') assert '%s' % vin assert vin.wmi == 'XTA' assert vin.manufacturer == 'AvtoVAZ' assert vin.vds == 'GFK330' assert vin.vis == 'JY144213' assert vin.years == [2018, 1988] assert vin.region_code == 'X' assert vin.region == 'Europe' assert vin.country_code == 'XT' assert vin.country == 'USSR/CIS' assert vin.annotate() == OrderedDict([ ('Country', 'USSR/CIS'), ('Manufacturer', 'AvtoVAZ'), ('Region', 'Europe'), ('Years', '2018, 1988'), ]) assert '%s' % vin.brand == 'Lada (AvtoVAZ)' details = vin.details assert details.model.code == 'F' assert details.model.name == 'Vesta' assert details.body.code == 'K' assert details.body.name == 'Station Wagon, 5-Door' assert details.engine.code == '3' assert details.engine.name == '21179' assert details.transmission.code == '3' assert details.transmission.name == 'Manual, 5-Gear (Renault JH3 514)' assert details.plant.code == 'Y' assert details.plant.name == 'Izhevsk' assert details.annotate() == OrderedDict([ ('Body', 'Station Wagon, 5-Door'), ('Engine', '21179'), ('Model', 'Vesta'), ('Plant', 'Izhevsk'), ('Serial', '144213'), ('Transmission', 'Manual, 5-Gear (Renault JH3 514)'), ]) assert not vin.verify_checksum()
def test_checksum(): assert Vin('1M8GDM9AXKP042788').verify_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 show(vin): """Show information for VIN""" num = Vin(vin) click.secho('Basic:') def out(annotatable): for k, v in annotatable.annotate().items(): click.secho('%s: ' % k, fg='green', nl=False) click.secho(v) out(num) details = num.details if details: click.secho('') click.secho('Details:') out(details)
def test_basic(): # faked assert Vin('JSA12345678901234').manufacturer == 'Suzuki'
#! python3 import sys from vininfo import Vin from pprint import pprint try: vin = Vin(sys.argv[1]) pprint(vin.annotate()) except Exception as e: print('Error: %s' % e) sys.exit(1)
# from vininfo import Vin # # vin = Vin('XTAGFK330JY144213') # # print(vin.annotate()) # code =vin.country_code # valied = vin.verify_checksum() from vininfo import Vin vin = Vin('VF1LM1B0H36666155') vin.country # France vin.manufacturer # Renault vin.region # Europe vin.wmi # VF1 vin.vds # LM1B0H vin.vis # 36666155 annotated = vin.annotate() details = vin.details vin.verify_checksum() # False Vin('1M8GDM9AXKP042788').verify_checksum() # True print(vin.annotate()) print(vin.vis)
def test_unsupported_brand(): vin = Vin('200BL8EV9AX604020') assert vin.manufacturer == 'UnsupportedBrand' assert vin.country == 'Canada'
def test_checksum(): assert Vin('1M8GDM9AXKP042788').verify_checksum() # faked assert not Vin('1M8GDM9AyKP042788').verify_checksum()
def test_bogus(): vin = Vin('VF1KG1PBE34488860') details = vin.details assert details.engine.code == '' assert not details.engine
#!/usr/bin/env python3 # Challenge 036 # # TASK #1 # Write a program to validate given Vehicle Identification Number (VIN). # For more information, please checkout wikipedia. import sys from vininfo import Vin vin = Vin(sys.argv[1]) print(1 if vin.verify_checksum() else 0)
def test_squish_vin(): assert Vin('KF1SF08WJ8B257338').squish_vin == 'KF1SF08W8B'