python-stdnum branch master updated. 1.9-10-ge58c09a
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum branch master updated. 1.9-10-ge58c09a
- From: Commits of the python-stdnum project <python-stdnum-commits [at] lists.arthurdejong.org>
- To: python-stdnum-commits [at] lists.arthurdejong.org
- Reply-to: python-stdnum-users [at] lists.arthurdejong.org
- Subject: python-stdnum branch master updated. 1.9-10-ge58c09a
- Date: Thu, 30 Aug 2018 21:32:27 +0200 (CEST)
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-stdnum".
The branch, master has been updated
via e58c09a825e64a68bf69204c07afd3a8a1269095 (commit)
via 4a767795a425de28daad743c89241e3803ff95b9 (commit)
from 5af712b0ff232eec4197635c14aa2342e76ff382 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
https://arthurdejong.org/git/python-stdnum/commit/?id=e58c09a825e64a68bf69204c07afd3a8a1269095
commit e58c09a825e64a68bf69204c07afd3a8a1269095
Author: Gerard Dalmau <gdalmau@gisce.net>
Date: Thu Aug 30 09:59:51 2018 +0200
Fix ES test descriptions
diff --git a/tests/test_es_cups.doctest b/tests/test_es_cups.doctest
index 4779124..6c76a86 100644
--- a/tests/test_es_cups.doctest
+++ b/tests/test_es_cups.doctest
@@ -1,4 +1,4 @@
-test_my_nric.doctest - more detailed doctests for stdnum.es.cups module
+test_es_cups.doctest - more detailed doctests for stdnum.es.cups module
Copyright (C) 2016 David García Garzón
Copyright (C) 2016 Arthur de Jong
diff --git a/tests/test_es_referenciacatastral.doctest
b/tests/test_es_referenciacatastral.doctest
index 94610ee..e7fbfad 100644
--- a/tests/test_es_referenciacatastral.doctest
+++ b/tests/test_es_referenciacatastral.doctest
@@ -1,4 +1,4 @@
-test_es_referenciacatastral.doctest - more detailed doctests
+test_es_referenciacatastral.doctest - more detailed doctests for
stdnum.es.referenciacatastral module
Copyright (C) 2016 David García Garzón
Copyright (C) 2015-2017 Arthur de Jong
https://arthurdejong.org/git/python-stdnum/commit/?id=4a767795a425de28daad743c89241e3803ff95b9
commit 4a767795a425de28daad743c89241e3803ff95b9
Author: Gerard Dalmau <gdalmau@gisce.net>
Date: Thu Aug 30 09:59:12 2018 +0200
Improve CIF and NIF validation
NIF starting with K, L or M are NIF instead of CIF.
This also adds NIF-DNI-CIF-NIE classification tests.
Closes https://github.com/arthurdejong/python-stdnum/pull/81
diff --git a/stdnum/es/cif.py b/stdnum/es/cif.py
index 0c87711..8802f87 100644
--- a/stdnum/es/cif.py
+++ b/stdnum/es/cif.py
@@ -34,8 +34,10 @@ InvalidChecksum: ...
Traceback (most recent call last):
...
InvalidLength: ...
->>> validate('M-1234567-L')
-'M1234567L'
+>>> validate('M-1234567-L') # valid NIF but not valid CIF
+Traceback (most recent call last):
+ ...
+InvalidFormat: ...
>>> validate('O-1234567-L') # invalid first character
Traceback (most recent call last):
...
@@ -72,14 +74,7 @@ def validate(number):
raise InvalidFormat()
if len(number) != 9:
raise InvalidLength()
- if number[0] in 'KLM':
- # K: Spanish younger than 14 year old
- # L: Spanish living outside Spain without DNI
- # M: granted the tax to foreigners who have no NIE
- # these use the old checkdigit algorithm (the DNI one)
- if number[-1] != dni.calc_check_digit(number[1:-1]):
- raise InvalidChecksum()
- elif number[0] in 'ABCDEFGHJNPQRSUVW':
+ if number[0] in 'ABCDEFGHJNPQRSUVW':
# there seems to be conflicting information on which organisation types
# should have which type of check digit (alphabetic or numeric) so
# we support either here
diff --git a/stdnum/es/nif.py b/stdnum/es/nif.py
index e2b87e9..b99049d 100644
--- a/stdnum/es/nif.py
+++ b/stdnum/es/nif.py
@@ -40,6 +40,8 @@ InvalidChecksum: ...
'54362315K'
>>> validate('X-5253868-R') # foreign person
'X5253868R'
+>>> validate('M-1234567-L') # foreign person without NIE
+'M1234567L'
"""
from stdnum.es import cif, dni, nie
@@ -64,7 +66,14 @@ def validate(number):
raise InvalidFormat()
if len(number) != 9:
raise InvalidLength()
- if number[0].isdigit():
+ if number[0] in 'KLM':
+ # K: Spanish younger than 14 year old
+ # L: Spanish living outside Spain without DNI
+ # M: granted the tax to foreigners who have no NIE
+ # these use the old checkdigit algorithm (the DNI one)
+ if number[-1] != dni.calc_check_digit(number[1:-1]):
+ raise InvalidChecksum()
+ elif number[0].isdigit():
# natural resident
dni.validate(number)
elif number[0] in 'XYZ':
diff --git a/tests/test_es_nif.doctest b/tests/test_es_nif.doctest
new file mode 100644
index 0000000..17286eb
--- /dev/null
+++ b/tests/test_es_nif.doctest
@@ -0,0 +1,57 @@
+test_es_nif.doctest - more detailed doctests for stdnum.es.nif module
+
+Copyright (C) 2018 Gerard Dalmau
+
+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.es.nif and related
+modules. It tries to cover more corner cases and detailed functionality that
+is not really useful as module documentation.
+
+>>> from stdnum.es import nif, dni, nie, cif
+>>> from stdnum.exceptions import *
+
+
+>>> def check(number):
+... ok = []
+... if nif.is_valid(number):
+... ok.append('nif')
+... if dni.is_valid(number):
+... ok.append('dni')
+... if nie.is_valid(number):
+... ok.append('nie')
+... if cif.is_valid(number):
+... ok.append('cif')
+... return ok
+
+
+>>> check('11111111H') # valid DNI
+['nif', 'dni']
+>>> check('11111111T') # invalid DNI
+[]
+>>> check('A11111119') # valid CIF
+['nif', 'cif']
+>>> check('A11111118') # invalid CIF
+[]
+>>> check('X1111111G') # valid NIE
+['nif', 'nie']
+>>> check('X1111111A') # invalid NIE
+[]
+>>> check('L1111111G') # valid NIF, not classified as DNI, CIF or NIE
+['nif']
+>>> check('L1111111C') # invalid NIF
+[]
-----------------------------------------------------------------------
Summary of changes:
stdnum/es/cif.py | 15 +++-----
stdnum/es/nif.py | 11 +++++-
tests/test_es_cups.doctest | 2 +-
tests/test_es_nif.doctest | 57 +++++++++++++++++++++++++++++++
tests/test_es_referenciacatastral.doctest | 2 +-
5 files changed, 74 insertions(+), 13 deletions(-)
create mode 100644 tests/test_es_nif.doctest
hooks/post-receive
--
python-stdnum
--
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
https://lists.arthurdejong.org/python-stdnum-commits/
- python-stdnum branch master updated. 1.9-10-ge58c09a,
Commits of the python-stdnum project