Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests/test_mu_nid.doctest
blob: 93f6adc693cecc1f81f9f87abcec89f033b9c909 (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
test_mu_nid.doctest - more detailed doctests for the stdnum.mu.nid module

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.mu.nid module. It
tries handle more corner cases than are useful as module documentation.

>>> from stdnum.mu import nid


Some simple tests.

>>> nid.validate('12345678901234')  # all-digits
Traceback (most recent call last):
    ...
InvalidFormat: ...
>>> nid.validate('ABCDEFGHIJKLMN')  # all-alhpa
Traceback (most recent call last):
    ...
InvalidFormat: ...
>>> nid.validate('A311299123456')  # missing check digit
Traceback (most recent call last):
    ...
InvalidLength: ...
>>> nid.validate('A999999123456F')  # invalid date
Traceback (most recent call last):
    ...
InvalidComponent: ...
>>> nid.validate('A3112991234565')  # invalid check digit
Traceback (most recent call last):
    ...
InvalidChecksum: ...
>>> nid.validate('A3112991234567')
'A3112991234567'

These have been randomly generated and tested against the validator at
https://eservices.mra.mu/apptan/feedpdfapptan

>>> numbers = '''
...
... A0503022303817
... A2103451905713
... B120106274060E
... B2209251149773
... C0302977326799
... C090939529731G
... D0906040423734
... D110163477627F
... G270634609988D
... H070461221669C
... H100257938348B
... I050125386993D
... J1205062398729
... K210220118460G
... L2410001918056
... M2206357474780
... N160734180180A
... N1806401273261
... O190339068436F
... P0301682918358
... Q300706590045E
... R2307179551405
... S0408513643074
... S180622940994C
... T1801758951565
... U1010291604172
... U1507158217746
... U1605075318231
... V180331350210A
... W2304253291007
... X1111599499508
... X2402942866912
... Y2504945824300
... Z170971799359B
...
... '''
>>> [x for x in numbers.splitlines() if x and not nid.is_valid(x)]
[]