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)]
[]