1test_ee_ik.doctest - test for estonian personal id 2 3Copyright (C) 2015 Tomas Karasek 4Copyright (C) 2015 Arthur de Jong 5 6This library is free software; you can redistribute it and/or 7modify it under the terms of the GNU Lesser General Public 8License as published by the Free Software Foundation; either 9version 2.1 of the License, or (at your option) any later version. 10 11This library is distributed in the hope that it will be useful, 12but WITHOUT ANY WARRANTY; without even the implied warranty of 13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14Lesser General Public License for more details. 15 16You should have received a copy of the GNU Lesser General Public 17License along with this library; if not, write to the Free Software 18Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 1902110-1301 USA 20 21 22>>> from stdnum.ee import ik 23>>> import stdnum.exceptions 24 25>>> ik.validate('36805280109') 26'36805280109' 27>>> ik.is_valid('36805280109') 28True 29>>> ik.calc_check_digit('36805280109') 30'9' 31>>> ik.validate('06805280106') # invalid first digit 32Traceback (most recent call last): 33 ... 34InvalidComponent: ... 35>>> ik.validate('36805280108') # invalid check digit 36Traceback (most recent call last): 37 ... 38InvalidChecksum: ... 39>>> ik.validate('368052801099') 40Traceback (most recent call last): 41 ... 42InvalidLength: ... 43 44 45>>> ik.get_birth_date('36805280109') 46datetime.date(1968, 5, 28) 47>>> ik.get_birth_date('16805280107') 48datetime.date(1868, 5, 28) 49>>> ik.get_birth_date('51205280105') 50datetime.date(2012, 5, 28) 51>>> ik.get_birth_date('81205280108') 52datetime.date(2112, 5, 28) 53>>> ik.get_birth_date('06805280106') # invalid first digit 54Traceback (most recent call last): 55 ... 56InvalidComponent: ... 57>>> ik.get_birth_date('38102290106') # non-existing date 58Traceback (most recent call last): 59 ... 60InvalidComponent: ... 61 62 63>>> ik.get_gender('36805280109') 64'M' 65>>> ik.get_gender('46805280103') 66'F' 67>>> ik.get_gender('98102290101') # invalid first digit 68Traceback (most recent call last): 69 ... 70InvalidComponent: ... 71 72 73>>> numbers = """ 74... 36205030034 75... 36606130166 76... 38002090113 77... 36703010079 78... 36412140053 79... 37105250048 80... 35806110178 81... 38411280151 82... 38004160054 83... 37406220030 84... 37207010076 85... 46104090101 86... 47306160017 87... 35712020095 88... 35512240278 89... 37111070056 90... 36003050128 91... 34508136020 92... 37112300117 93... 37205120111 94... 36708120106 95... 36204130100 96... 36805280109 97... 36404240119 98... 37609300174 99... 38407170099 100... 35903140121 101... 36912050058 102... 36706060097 103... 37909180161 104... 37210220129 105... 35803140053 106... 37709190107 107... 36306200109 108... 36208130099 109... 37611280079 110... 35806190146 111... 44909210102 112... 37104020141 113... 35907150159 114... 36412100145 115... 49105080018 116... 37406110083 117... 36304020091 118... 37106220087 119... 34706045216 120... 37503240119 121... 38310150127 122... 46708270050 123... """ 124>>> [x for x in numbers.splitlines() if x and not ik.is_valid(x)] 125[] 126