1test_se_personnummer.doctest - more detailed doctests for stdnum.se.personnummer module
2
3Copyright (C) 2018 Ilya Vihtinsky
4Copyright (C) 2018 Arthur de Jong
5
6This library is free software; you can redistribute it and/or
7modify it under the terms of the GNU Lesser General Public
8License as published by the Free Software Foundation; either
9version 2.1 of the License, or (at your option) any later version.
10
11This library is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14Lesser General Public License for more details.
15
16You should have received a copy of the GNU Lesser General Public
17License along with this library; if not, write to the Free Software
18Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
1902110-1301 USA
20
21
22This file contains more detailed doctests for the stdnum.se.personnummer
23module. It tries to cover more corner cases and detailed functionality that
24is not really useful as module documentation.
25
26>>> from stdnum.se import personnummer
27
28
29Test for non-digit number.
30
31>>> personnummer.validate('a' * 10)
32Traceback (most recent call last):
33    ...
34InvalidFormat: ...
35>>> personnummer.validate('a' * 11)
36Traceback (most recent call last):
37    ...
38InvalidFormat: ...
39
40
41These numbers should be detected as male or female.
42
43>>> personnummer.get_gender('670919-9530')
44'M'
45>>> personnummer.get_gender('8803200420')
46'F'
47
48
49The birth date can be extracted from the number and invalid dates are
50rejected.
51
52>>> personnummer.get_birth_date('8803200420')
53datetime.date(1988, 3, 20)
54>>> personnummer.get_birth_date('191705120424')
55datetime.date(1917, 5, 12)
56>>> personnummer.get_birth_date('121212-1212')
57datetime.date(2012, 12, 12)
58>>> personnummer.get_birth_date('121212+1212')
59datetime.date(1912, 12, 12)
60>>> personnummer.get_birth_date('400606+5827')
61datetime.date(1840, 6, 6)
62>>> personnummer.validate('8899200425')
63Traceback (most recent call last):
64    ...
65InvalidComponent: ...
66
67
68These have been found online and should all be valid numbers.
69
70>>> numbers = '''
71...
72... 670919-9530
73... 811228-9874
74... 880320-0016
75... 880320-0057
76... 8803200073
77... 8803200099
78... 8803200115
79... 8803200131
80... 8803200156
81... 8803200172
82... 8803200198
83... 8803200420
84...
85... '''
86>>> [x for x in numbers.splitlines() if x and not personnummer.is_valid(x)]
87[]
88