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 127 128 129
|
test_it_codicefiscale.doctest - tests for the stdnum.it.codicefiscale module
Copyright (C) 2009-2013 Emanuele Rocca
Copyright (C) 2014 Augusto Destrero
Copyright (C) 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.it.codicefiscale
module. It tries to validate a number of tax codes that have been found
online.
>>> from stdnum.it import codicefiscale
>>> from stdnum.exceptions import *
Some valid numbers
>>> numbers = '''
... MRTNTN23M02D969P
... RCCMNL83S18D969H
... MRSMSR81D60Z611H
... CNTCHR83T41D969D
... FOXDRA26C24H872Y
... MAILCU91A25F839D
... RSSMRA45C12F205C
... RSSMRA45C12F20RX
... RSSMRA45C12F2L5N
... RSSMRA45C12F2LRI
... RSSMRAQRCMNFNLRG
... '''
>>> [x for x in numbers.splitlines() if x and not codicefiscale.is_valid(x)]
[]
These should be invalid:
>>> codicefiscale.validate('CSTNGL22I10D086I') # the first 'I' shouldn't be there
Traceback (most recent call last):
...
InvalidFormat: ...
>>> codicefiscale.validate('FOXDRA26C24H872A')
Traceback (most recent call last):
...
InvalidChecksum: ...
>>> codicefiscale.validate('CNTCHR83T32D969H') # invalid date
Traceback (most recent call last):
...
InvalidComponent: ...
Test getting the birth date.
>>> codicefiscale.get_birth_date('MRTNTN23M02D969P')
datetime.date(1923, 8, 2)
>>> codicefiscale.get_birth_date('RCCMNL83S18D969H')
datetime.date(1983, 11, 18)
>>> codicefiscale.get_birth_date('MRSMSR81D60Z611H')
datetime.date(1981, 4, 20)
>>> codicefiscale.get_birth_date('CNTCHR83T41D969D')
datetime.date(1983, 12, 1)
>>> codicefiscale.get_birth_date('FOXDRA26C24H872Y')
datetime.date(1926, 3, 24)
>>> codicefiscale.get_birth_date('MAILCU91A25F839D')
datetime.date(1991, 1, 25)
>>> codicefiscale.get_birth_date('RSSMRA45C12F205C')
datetime.date(1945, 3, 12)
>>> codicefiscale.get_birth_date('RSSMRA45C12F20RX')
datetime.date(1945, 3, 12)
>>> codicefiscale.get_birth_date('RSSMRA45C12F2L5N')
datetime.date(1945, 3, 12)
>>> codicefiscale.get_birth_date('RSSMRA45C12F2LRI')
datetime.date(1945, 3, 12)
>>> codicefiscale.get_birth_date('RSSMRAQRCMNFNLRG')
datetime.date(1945, 3, 12)
>>> codicefiscale.get_birth_date('MRTNTN23M02D969P')
datetime.date(1923, 8, 2)
Test getting the gender.
>>> codicefiscale.get_gender('MRTNTN23M02D969P')
'M'
>>> codicefiscale.get_gender('RCCMNL83S18D969H')
'M'
>>> codicefiscale.get_gender('RCDLSN84S16D969Z')
'M'
>>> codicefiscale.get_gender('MRSMSR81D60Z611H')
'F'
>>> codicefiscale.get_gender('CNTCHR83T41D969D')
'F'
>>> codicefiscale.get_gender('FOXDRA26C24H872Y')
'M'
>>> codicefiscale.get_gender('MAILCU91A25F839D')
'M'
Test calculating the check digit.
>>> codicefiscale.calc_check_digit('MRTNTN23M02D969')
'P'
>>> codicefiscale.calc_check_digit('MRSMSR81D60Z611')
'H'
>>> codicefiscale.calc_check_digit('RCDLSN84S16D969')
'Z'
>>> codicefiscale.calc_check_digit('CNTCHR83T41D969')
'D'
>>> codicefiscale.calc_check_digit('BNCSFN85T58G702')
'W'
>>> codicefiscale.calc_check_digit('RCCMNL83S18D969')
'H'
>>> codicefiscale.calc_check_digit('FOXDRA26C24H872')
'Y'
>>> codicefiscale.calc_check_digit('MAILCU91A25F839')
'D'
|