-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_passport.py
78 lines (69 loc) · 1.77 KB
/
test_passport.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import io
import pytest
from typing import Dict
from .passport import parse, validate
def test_parse():
want = [
{
'ecl': 'gry',
'pid': '860033327',
'eyr': '2020',
'hcl': '#fffffd',
'byr': '1937',
'iyr': '2017',
'cid': '147',
'hgt': '183cm',
},
{
'iyr': '2013',
'ecl': 'amb',
'cid': '350',
'eyr': '2023',
'pid': '028048884',
'hcl': '#cfa07d',
'byr': '1929',
},
{
'hcl': '#ae17e1',
'iyr': '2013',
'eyr': '2024',
'ecl': 'brn',
'pid': '760753108',
'byr': '1931',
'hgt': '179cm',
},
{
'hcl': '#cfa07d',
'eyr': '2025',
'pid': '166559648',
'iyr': '2011',
'ecl': 'brn',
'hgt': '59in',
},
]
got = list(parse(io.StringIO("""
ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
byr:1937 iyr:2017 cid:147 hgt:183cm
iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884
hcl:#cfa07d byr:1929
hcl:#ae17e1 iyr:2013
eyr:2024
ecl:brn pid:760753108 byr:1931
hgt:179cm
hcl:#cfa07d eyr:2025 pid:166559648
iyr:2011 ecl:brn hgt:59in
""")))
assert want == got
@pytest.mark.parametrize(['passport', 'is_valid'], [
pytest.param({
'pid': '087499704',
'hgt': '74in',
'ecl': 'grn',
'iyr': '2012',
'eyr': '2030',
'byr': '1980',
'hcl': '#623a2f',
}, True)
])
def test_validate(passport: Dict[str, str], is_valid: bool):
assert validate(passport) == is_valid