33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
from uk_plate_reader import read_licence_plate
|
|
import pytest # type: ignore
|
|
|
|
def test_old_plate_returns_correct_area():
|
|
assert read_licence_plate("N12 ANA")[0] == "Manchester"
|
|
assert read_licence_plate("L12 AOE")[0] == "Birmingham"
|
|
assert read_licence_plate("L12 AP")[0] == "Surrey"
|
|
|
|
def test_new_plate_returns_correct_area():
|
|
assert read_licence_plate("LL07 XYZ")[0] == "London"
|
|
assert read_licence_plate("OJ57 XYZ")[0] == "Oxford"
|
|
assert read_licence_plate("BB62 XYZ")[0] == "Birmingham"
|
|
|
|
def test_old_plate_returns_correct_year():
|
|
assert read_licence_plate("N12 AOE")[1] in [1995, 1996]
|
|
assert read_licence_plate("L12 AOE")[1] in [1993, 1994]
|
|
|
|
def test_new_plate_returns_correct_year():
|
|
assert read_licence_plate("AB07 XYZ")[1] == 2007
|
|
assert read_licence_plate("AB57 XYZ")[1] in [2007, 2008]
|
|
assert read_licence_plate("AB62 XYZ")[1] in [2012, 2013]
|
|
|
|
def test_invalid_plate_returns_error():
|
|
for plate in ["A", "ZZ07 LMA", "Z12 ANA", "Y12 ZZZ"]:
|
|
with pytest.raises(Exception):
|
|
read_licence_plate(plate)
|
|
|
|
def test_empty_input_returns_error():
|
|
with pytest.raises(IndexError):
|
|
read_licence_plate("")
|
|
|
|
def test_legacy_single_char_area():
|
|
assert read_licence_plate("N12 AM")[0] == "Cheshire" |