Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests/test_nz_ird.doctest
blob: aa0dff3f1a8bee53ad8841ea6408c7f0acebd824 (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
test_nz_ird.doctest - more detailed tests for stdnum.nz.ird

Copyright (C) 2019 Leandro Regueiro
Copyright (C) 2019 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.nz.ird module.

>>> from stdnum.nz import ird
>>> from stdnum.exceptions import *


This is a selection of numbers (which should be valid) found at
https://www.ird.govt.nz/-/media/Project/IR/PDF/2020RWTNRWTSpecificationDocumentv10.pdf

>>> ird.validate('49091850')
'49091850'
>>> ird.validate('136410133')
Traceback (most recent call last):
    ...
InvalidChecksum: ...
>>> ird.validate('9125568')
Traceback (most recent call last):
    ...
InvalidLength: ...


Test for corner cases.

>>> ird.validate('1234567A')
Traceback (most recent call last):
    ...
InvalidFormat: ...
>>> ird.validate('150000001')
Traceback (most recent call last):
    ...
InvalidComponent: ...


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

>>> numbers = '''
...
... 047-179-025
... 136410132
... 35901981
... 49098576
... 53-710-220
... 61-631-852
...
... '''
>>> [x for x in numbers.splitlines() if x and not ird.is_valid(x)]
[]