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
126
|
test_my_nric.doctest - more detailed doctests for stdnum.my.nric module
Copyright (C) 2013, 2014 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.my.nric. It
tries to cover more corner cases and detailed functionality that is not
really useful as module documentation.
>>> from stdnum.my import nric
>>> from stdnum.exceptions import *
Normal values that should just work.
>>> nric.validate('770305-02-1234')
'770305021234'
>>> nric.validate('890131-06-1224')
'890131061224'
>>> nric.validate('810909785542')
'810909785542'
>>> nric.validate('880229875542')
'880229875542'
Get the birth date:
>>> nric.get_birth_date('770305-02-1234')
datetime.date(1977, 3, 5)
>>> nric.get_birth_date('890131-06-1224')
datetime.date(1989, 1, 31)
>>> nric.get_birth_date('810909785542')
datetime.date(1981, 9, 9)
>>> nric.get_birth_date('880229875542')
datetime.date(1988, 2, 29)
Get the birth place:
>>> str(nric.get_birth_place('770305-02-1234')['state'])
'Kedah'
>>> str(nric.get_birth_place('890131-06-1224')['state'])
'Pahang'
>>> str(nric.get_birth_place('810909785542')['country']).upper()
'SRI LANKA'
>>> str(nric.get_birth_place('880229875542')['countries']).upper()
'BRITAIN, GREAT BRITAIN, IRELAND'
Formatting:
>>> nric.format('770305-02-1234')
'770305-02-1234'
>>> nric.format('890131-06-1224')
'890131-06-1224'
>>> nric.format('810909785542')
'810909-78-5542'
>>> nric.format('880229875542')
'880229-87-5542'
Invalid date:
>>> nric.validate('771305-02-1234')
Traceback (most recent call last):
...
InvalidComponent: ...
>>> nric.validate('890132-06-1224')
Traceback (most recent call last):
...
InvalidComponent: ...
>>> nric.validate('870229875542')
Traceback (most recent call last):
...
InvalidComponent: ...
Invalid birth place:
>>> nric.validate('770305-00-1234')
Traceback (most recent call last):
...
InvalidComponent: ...
>>> nric.validate('890131-17-1224')
Traceback (most recent call last):
...
InvalidComponent: ...
>>> nric.validate('810909805542')
Traceback (most recent call last):
...
InvalidComponent: ...
>>> nric.validate('880229195542')
Traceback (most recent call last):
...
InvalidComponent: ...
Just invalid numbers:
>>> nric.validate('770305-00')
Traceback (most recent call last):
...
InvalidLength: ...
>>> nric.validate('890A31-17-1224')
Traceback (most recent call last):
...
InvalidFormat: ...
>>> nric.get_birth_place('8109098')
Traceback (most recent call last):
...
InvalidComponent: ...
|