Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests/test_ee_ik.doctest
blob: b5e14534356c8dd6618dd4b499dec67a00d32c66 (plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
test_ee_ik.doctest - test for estonian personal id

Copyright (C) 2015 Tomas Karasek
Copyright (C) 2015 Arthur de Jong

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA


>>> from stdnum.ee import ik
>>> import stdnum.exceptions

>>> ik.validate('36805280109')
'36805280109'
>>> ik.is_valid('36805280109')
True
>>> ik.calc_check_digit('36805280109')
'9'
>>> ik.validate('06805280106')  # invalid first digit
Traceback (most recent call last):
    ...
InvalidComponent: ...
>>> ik.validate('36805280108')  # invalid check digit
Traceback (most recent call last):
    ...
InvalidChecksum: ...
>>> ik.validate('368052801099')
Traceback (most recent call last):
    ...
InvalidLength: ...


>>> ik.get_birth_date('36805280109')
datetime.date(1968, 5, 28)
>>> ik.get_birth_date('16805280107')
datetime.date(1868, 5, 28)
>>> ik.get_birth_date('51205280105')
datetime.date(2012, 5, 28)
>>> ik.get_birth_date('81205280108')
datetime.date(2112, 5, 28)
>>> ik.get_birth_date('06805280106')  # invalid first digit
Traceback (most recent call last):
    ...
InvalidComponent: ...
>>> ik.get_birth_date('38102290106')  # non-existing date
Traceback (most recent call last):
    ...
InvalidComponent: ...


>>> ik.get_gender('36805280109')
'M'
>>> ik.get_gender('46805280103')
'F'
>>> ik.get_gender('98102290101')  # invalid first digit
Traceback (most recent call last):
    ...
InvalidComponent: ...


>>> numbers = """
... 36205030034
... 36606130166
... 38002090113
... 36703010079
... 36412140053
... 37105250048
... 35806110178
... 38411280151
... 38004160054
... 37406220030
... 37207010076
... 46104090101
... 47306160017
... 35712020095
... 35512240278
... 37111070056
... 36003050128
... 34508136020
... 37112300117
... 37205120111
... 36708120106
... 36204130100
... 36805280109
... 36404240119
... 37609300174
... 38407170099
... 35903140121
... 36912050058
... 36706060097
... 37909180161
... 37210220129
... 35803140053
... 37709190107
... 36306200109
... 36208130099
... 37611280079
... 35806190146
... 44909210102
... 37104020141
... 35907150159
... 36412100145
... 49105080018
... 37406110083
... 36304020091
... 37106220087
... 34706045216
... 37503240119
... 38310150127
... 46708270050
... """
>>> [x for x in numbers.splitlines() if x and not ik.is_valid(x)]
[]