Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests/test_no_fodselsnummer.doctest
blob: abec35ef0fb4ab2a0bfec12c5d936ddb88814a58 (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
test_no_fodselsnummer.doctest - more detailed doctests for stdnum.no.fodselsnummer module

Copyright (C) 2018 Ilya Vihtinsky
Copyright (C) 2018 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


This file contains more detailed doctests for the stdnum.no.fodselsnummer
module. It tries to cover more corner cases and detailed functionality that
is not really useful as module documentation.

>>> from stdnum.no import fodselsnummer


These numbers should be detected as male or female.

>>> fodselsnummer.get_gender('70624830529')
'M'
>>> fodselsnummer.get_gender('56403643756')
'M'
>>> fodselsnummer.get_gender('70341666064')
'F'
>>> fodselsnummer.get_gender('82938389280')
'F'


The last two check digits are validated independently of each other.

>>> fodselsnummer.is_valid('42485176432')
True
>>> fodselsnummer.is_valid('42485176431')  # only change last digit
False
>>> fodselsnummer.is_valid('42485176412')  # only change first digit
False
>>> fodselsnummer.is_valid('42485176416')  # change first, correct second
False


Length and format are also validated.

>>> fodselsnummer.validate('42485176432123')
Traceback (most recent call last):
    ...
InvalidLength: ...
>>> fodselsnummer.validate('a0gzaB30529')
Traceback (most recent call last):
    ...
InvalidFormat: ...


These have been found online and should all be valid numbers.

>>> numbers = '''
...
... 11027794191
... 11051996811
... 19575770838
... 21918484865
... 24396859900
... 27213364885
... 27389446152
... 30383131118
... 30777674125
... 31042639152
... 34831582121
... 39043009846
... 40070897972
... 40673759612
... 42115114470
... 42485176432
... 42957044500
... 44207789809
... 45014054018
... 46929323343
... 50067834221
... 56403643756
... 56653047547
... 63282310041
... 68413152112
... 70031073454
... 70341666064
... 70624830529
... 71494457037
... 71946503120
... 75442702381
... 79189404641
... 79318270827
... 82938389280
... 83814827871
... 89829529360
... 92782833709
... 95700625908
... 96517753502
... 98576936818
...
... '''
>>> [x for x in numbers.splitlines() if x and not fodselsnummer.is_valid(x)]
[]