python-stdnum branch master updated. 1.3-15-gfd9f953
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum branch master updated. 1.3-15-gfd9f953
- 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.3-15-gfd9f953
- Date: Mon, 25 Jul 2016 16:24:23 +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 fd9f9538c362aacf50e4ae32ae51b15ecaf79184 (commit)
via 5ba3a8796fccc44136d325f466ee99f6e1dfd96d (commit)
via dc708f044a78297f0a283c389930b5d8b3a378a9 (commit)
from 4a57d84935d45c78bcd407c2cca558bb74df5a54 (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 -----------------------------------------------------------------
http://arthurdejong.org/git/python-stdnum/commit/?id=fd9f9538c362aacf50e4ae32ae51b15ecaf79184
commit fd9f9538c362aacf50e4ae32ae51b15ecaf79184
Author: Arthur de Jong <arthur@arthurdejong.org>
Date: Mon Jul 25 16:23:54 2016 +0200
Add extra tests for SIREN and SIRET
This adds tests for a few numbers that have been found online and allows
the dot as a seprator because those numbers were found.
It also ensures that the SIREN validation is also called for SIRET and
adds a SIRET formatting function.
diff --git a/stdnum/fr/siren.py b/stdnum/fr/siren.py
index f57b0fa..543f428 100644
--- a/stdnum/fr/siren.py
+++ b/stdnum/fr/siren.py
@@ -50,7 +50,7 @@ from stdnum.util import clean
def compact(number):
"""Convert the number to the minimal representation. This strips the
number of any valid separators and removes surrounding whitespace."""
- return clean(number, ' ').strip()
+ return clean(number, ' .').strip()
def validate(number):
diff --git a/stdnum/fr/siret.py b/stdnum/fr/siret.py
index ab7d59f..22efe20 100644
--- a/stdnum/fr/siret.py
+++ b/stdnum/fr/siret.py
@@ -38,6 +38,8 @@ InvalidChecksum: ...
'44 732 829 320'
>>> to_tva('73282932000074')
'44732829320'
+>>> format('73282932000074')
+'732 829 320 00074'
"""
from stdnum import luhn
@@ -49,7 +51,7 @@ from stdnum.util import clean
def compact(number):
"""Convert the number to the minimal representation. This strips the
number of any valid separators and removes surrounding whitespace."""
- return clean(number, ' ').strip()
+ return clean(number, ' .').strip()
def validate(number):
@@ -61,6 +63,7 @@ def validate(number):
if len(number) != 14:
raise InvalidLength()
luhn.validate(number)
+ siren.validate(number[:9])
return number
@@ -95,3 +98,9 @@ def to_tva(number):
error checking digits.
"""
return siren.to_tva(to_siren(number))
+
+
+def format(number, separator=' '):
+ """Reformat the passed number to the standard format."""
+ number = compact(number)
+ return separator.join((number[0:3], number[3:6], number[6:9], number[9:]))
diff --git a/tests/test_fr_siren.doctest b/tests/test_fr_siren.doctest
new file mode 100644
index 0000000..2169ec9
--- /dev/null
+++ b/tests/test_fr_siren.doctest
@@ -0,0 +1,47 @@
+test_fr_siren.doctest - more detailed doctests for the stdnum.fr.siren module
+
+Copyright (C) 2016 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.fr.siren module.
+
+>>> from stdnum.fr import siren
+>>> from stdnum.exceptions import *
+
+
+These have been found online and should all be valid numbers.
+
+>>> numbers = '''
+...
+... 217601 145
+... 3 1 0 1 8 8 4 2 0
+... 350792008
+... 480318245
+... 500 674 056
+... 529290488
+... 738 205 269
+... 752136200
+... 752490334
+... 775 699 309
+... 775672272
+... 776 944 944
+... 820043784
+...
+... '''
+>>> [x for x in numbers.splitlines() if x and not siren.is_valid(x)]
+[]
diff --git a/tests/test_fr_siret.doctest b/tests/test_fr_siret.doctest
new file mode 100644
index 0000000..699ac33
--- /dev/null
+++ b/tests/test_fr_siret.doctest
@@ -0,0 +1,85 @@
+test_fr_siret.doctest - more detailed doctests for the stdnum.fr.siret module
+
+Copyright (C) 2016 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.fr.siret module.
+
+>>> from stdnum.fr import siret
+>>> from stdnum.exceptions import *
+
+
+These have been found online and should all be valid numbers.
+
+>>> numbers = '''
+...
+... 0 5 7 8 1 3 1 3 1 0 0 0 2 6
+... 1 800 700 39 00 110
+... 2 00 03 00 13 000 11
+... 2 101 005 33 000 12
+... 2 777 000 43 000 15
+... 3 1 0 1 8 8 4 2 0 00 0 8 0
+... 3 12 494 529 000 34
+... 3 24 34 54 20 000 40
+... 30206838200050
+... 314 901 323 00043
+... 31719324100013
+... 32228438100017
+... 32650798500058
+... 32738082000032
+... 329.338.88300153
+... 32929695800039
+... 33770320100034
+... 34530016400018
+... 380 321 430 00023
+... 38446899700034
+... 38536958200023
+... 389 011 529 00036
+... 38981890700203
+... 39039475700020
+... 39102766100050
+... 4 0 0 9 0 8 5 0 5 0 0 0 11
+... 4 0 3 3 1 4 6 6 9 0 0 0 4 1
+... 4 0 9 0 8 5 2 1 4 0 0 0 2 4
+... 4 2 0 3 0 9 6 2 7 0 0 0 3 2
+... 4 4 3 4 8 9 2 7 3 0 0 0 1 3
+... 4 4 3 5 4 9 8 7 8 0 0 0 4 1
+... 4 8 2 7 8 1 9 11 0 0 0 11
+... 40300300700032
+... 44126652500019
+... 44142526100019
+... 44796433900017
+... 479 461 675 00049
+... 5 12 326 653 000 15
+... 5 17 758 173 000 10
+... 50397442000021
+... 513 133 637 000 35
+... 52524288900042
+... 542 097 324 0006 6
+... 652 059 213 00023
+... 7 7821 0526 00019
+... 775.563.232.00104
+... 778 239 798 000 11
+... 79068156300017
+... 8 1 0 2 4 7 3 8 7 0 0 0 1 4
+... 8 1002665800015
+... 8 21 114 55000014
+...
+... '''
+>>> [x for x in numbers.splitlines() if x and not siret.is_valid(x)]
+[]
http://arthurdejong.org/git/python-stdnum/commit/?id=5ba3a8796fccc44136d325f466ee99f6e1dfd96d
commit 5ba3a8796fccc44136d325f466ee99f6e1dfd96d
Author: Yoann Aubineau <y.aubineau@criteo.com>
Date: Fri May 27 16:43:53 2016 +0200
Add French SIRET number
Add a SIRET (Système d'Identification du Répertoire des ETablissements,
a French company etablishment identification number) module.
diff --git a/stdnum/fr/siret.py b/stdnum/fr/siret.py
new file mode 100644
index 0000000..ab7d59f
--- /dev/null
+++ b/stdnum/fr/siret.py
@@ -0,0 +1,97 @@
+# siret.py - functions for handling French SIRET numbers
+# coding: utf-8
+#
+# Copyright (C) 2016 Yoann Aubineau
+#
+# 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
+
+"""SIRET (a French company establishment identification number).
+
+The SIRET (Système d'Identification du Répertoire des ETablissements)
+is a 14 digit number used to identify French companies' establishments
+and facilities. The Luhn checksum is used to validate the numbers.
+
+>>> validate('73282932000074')
+'73282932000074'
+>>> validate('73282932000079')
+Traceback (most recent call last):
+ ...
+InvalidChecksum: ...
+>>> to_siren('732 829 320 00074')
+'732 829 320'
+>>> to_siren('73282932000074')
+'732829320'
+>>> to_tva('732 829 320 00074')
+'44 732 829 320'
+>>> to_tva('73282932000074')
+'44732829320'
+"""
+
+from stdnum import luhn
+from stdnum.exceptions import *
+from stdnum.fr import siren
+from stdnum.util import clean
+
+
+def compact(number):
+ """Convert the number to the minimal representation. This strips the
+ number of any valid separators and removes surrounding whitespace."""
+ return clean(number, ' ').strip()
+
+
+def validate(number):
+ """Checks to see if the number provided is a valid number. This checks
+ the length, formatting and check digit."""
+ number = compact(number)
+ if not number.isdigit():
+ raise InvalidFormat()
+ if len(number) != 14:
+ raise InvalidLength()
+ luhn.validate(number)
+ return number
+
+
+def is_valid(number):
+ """Checks to see if the number provided is a valid number. This checks
+ the length, formatting and check digit."""
+ try:
+ return bool(validate(number))
+ except ValidationError:
+ return False
+
+
+def to_siren(number):
+ """Return SIREN number from the given SIRET number.
+
+ The SIREN number is the 9 first digits of the SIRET number.
+ """
+ _siren = []
+ digit_count = 0
+ for char in number:
+ if digit_count < 9:
+ _siren.append(char)
+ if char.isdigit():
+ digit_count += 1
+ return ''.join(_siren)
+
+
+def to_tva(number):
+ """Return TVA number from the given SIRET number.
+
+ The TVA number is built from the SIREN number, prepended by two extra
+ error checking digits.
+ """
+ return siren.to_tva(to_siren(number))
http://arthurdejong.org/git/python-stdnum/commit/?id=dc708f044a78297f0a283c389930b5d8b3a378a9
commit dc708f044a78297f0a283c389930b5d8b3a378a9
Author: Arthur de Jong <arthur@arthurdejong.org>
Date: Sun May 29 13:07:57 2016 +0200
Add more ISIL tests
This moves a few of the tests from the module to a dedicated test file
and adds tests for a number of ISIL numbers found online.
diff --git a/stdnum/isil.py b/stdnum/isil.py
index 30dea53..ec1afd6 100644
--- a/stdnum/isil.py
+++ b/stdnum/isil.py
@@ -51,14 +51,8 @@ More information:
Traceback (most recent call last):
...
InvalidComponent: ...
->>> validate('WW-RM026712423345334534512334534545') # too long
-Traceback (most recent call last):
- ...
-InvalidLength: ...
>>> format('it-RM0267')
'IT-RM0267'
->>> format('zz-RM0267') # unknown agencies are left alone
-'zz-RM0267'
"""
from stdnum.exceptions import *
diff --git a/tests/test_isil.doctest b/tests/test_isil.doctest
new file mode 100644
index 0000000..1668563
--- /dev/null
+++ b/tests/test_isil.doctest
@@ -0,0 +1,404 @@
+test_isil.doctest - more detailed doctests for the stdnum.isil module
+
+Copyright (C) 2016 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.isil module. It
+tries to validate a number of numbers that have been found online.
+
+>>> from stdnum import isil
+>>> from stdnum.exceptions import *
+
+
+The number should start with a valid country code or prefix:
+
+>>> isil.validate('ZZ-1234')
+Traceback (most recent call last):
+ ...
+InvalidComponent: ...
+
+
+The number should not be too long:
+
+>>> isil.validate('WW-RM026712423345334534512334534545')
+Traceback (most recent call last):
+ ...
+InvalidLength: ...
+
+
+A number with an unknown agency should not be upper-cased:
+
+>>> isil.format('zz-RM0267')
+'zz-RM0267'
+
+
+These have been found online and should all be valid numbers.
+
+>>> numbers = '''
+...
+... AT-FHJ-BG
+... AT-FHK
+... AT-FHK-FE
+... AT-FHS-K
+... AT-GEOL
+... AT-HGMW
+... AT-KWPU
+... AT-LAST
+... AT-LBB
+... AT-NMW-Z
+... AT-NOeLB
+... AT-OBV
+... AT-OeAW-BA
+... AT-PHK
+... AT-PHS
+... AT-PHST
+... AT-PHT
+... AT-PHV
+... AT-STICHWORT
+... AT-UBG-SH
+... AT-UBGL
+... AT-UBI-HB
+... AT-UBL
+... AT-UBMG-HB
+... AT-UBMS
+... AT-UBMS-MUS
+... AT-UBMUL-FBG
+... AT-UBMUL-HB
+... AT-UBMUW-360
+... AT-UBMUW-400
+... AT-UBMW
+... AT-UBTUG-HB
+... AT-UBVUW-UB
+... AT-UBW
+... AT-UBWW
+... AT-UBWW-874
+... AT-VMW
+... AT-WBR
+... AT-WHK
+... AT-WSTLA-B
+...
+... AU-ABC:ARC
+... AU-ABC:PL
+... AU-ABC:RN
+... AU-ANL:AJA
+... AU-ANU:ADBO
+... AU-ANU:IR
+... AU-ANU:ON
+... AU-NABC
+... AU-NABM
+... AU-NACON
+... AU-NACU:AA
+... AU-NAIM
+... AU-NEF
+... AU-NJHS
+... AU-NNCU:A
+... AU-NRNA
+... AU-NU
+... AU-NU:DF
+... AU-NUWS
+... AU-QMINT
+... AU-QU
+... AU-SMUA
+... AU-SUSA
+... AU-TS:RL
+... AU-TU
+... AU-VAAPM
+... AU-VACMU
+... AU-VAGH
+... AU-VAHRI
+... AU-VAMD
+... AU-VANDS
+... AU-VDU
+... AU-VEMU
+... AU-VLGA
+... AU-VPM
+... AU-VS:NAH
+... AU-VSWT
+... AU-VU
+... AU-WAHB
+... AU-XACA
+...
+... BE-A0510
+... BE-A3004
+... BE-A5000
+... BE-A5001
+... BE-A5002
+... BE-AAR00
+... BE-ALN00
+... BE-ANN03
+... BE-ANT01
+... BE-BDE00
+... BE-BEE00
+... BE-BRL06
+... BE-BRL07
+... BE-BRL10
+... BE-BUE01
+... BE-DIT00
+... BE-DNE00
+... BE-DPE00
+... BE-EKN00
+... BE-GAN00
+... BE-GET02
+... BE-HCT00
+... BE-HED00
+... BE-HEN00
+... BE-HES01
+... BE-JEE00
+... BE-KLT00
+... BE-KNE00
+... BE-KRG00
+... BE-LLE00
+... BE-LNL00
+... BE-LUK01
+... BE-LUN00
+... BE-MSE00
+... BE-NET00
+... BE-OSE00
+... BE-RIT00
+... BE-SJS01
+... BE-ZEE00
+... BE-ZUE00
+...
+... CA-QMCB
+...
+... CH-000050-X
+... CH-000051-7
+... CH-000084-8
+... CH-000190-0
+... CH-000244-3
+... CH-000422-7
+... CH-000423-4
+... CH-000425-9
+... CH-000560-3
+... CH-000886-6
+... CH-001008-0
+... CH-001010-9
+... CH-001057-5
+... CH-001059-X
+... CH-001113-6
+... CH-001243-0
+... CH-001283-6
+... CH-001350-0
+... CH-001539-4
+... CH-001631-1
+... CH-001644-X
+... CH-001645-7
+... CH-001646-4
+... CH-001648-9
+... CH-001649-6
+... CH-001654-6
+... CH-001666-7
+... CH-001669-9
+... CH-001760-9
+... CH-001800-6
+... CH-001815-9
+... CH-001821-6
+... CH-001824-8
+... CH-001825-5
+... CH-001832-X
+... CH-001839-0
+... CH-001844-0
+... CH-001845-8
+... CH-001846-5
+... CH-001851-5
+...
+... CY-02-CUT
+...
+... DE-101c
+... DE-16-18
+... DE-1769
+... DE-1786
+... DE-180-1-2
+... DE-1834h
+... DE-1834k
+... DE-1869
+... DE-188-878
+... DE-188-e
+... DE-1886
+... DE-1935
+... DE-1939
+... DE-1988
+... DE-1996
+... DE-2300
+... DE-2343
+... DE-360
+... DE-379
+... DE-38-230
+... DE-412
+... DE-416
+... DE-450
+... DE-465M-15
+... DE-469
+... DE-46a
+... DE-570
+... DE-6-235
+... DE-6-271
+... DE-6-321
+... DE-7-040
+... DE-7-061
+... DE-718
+... DE-758
+... DE-781
+... DE-82-204
+... DE-82-219
+... DE-Bor4
+... DE-Kn184
+... DE-Tue120
+...
+... GB-NiBfQU
+... GB-StAlCLS
+... GB-StDnUAD
+... GB-StGlU
+... GB-StPaUWSP
+... GB-UK-AbCCL
+... GB-UK-DhCL
+... GB-UK-LoRCN
+... GB-UK-WiU
+... GB-UkBrCC
+... GB-UkBsBC
+... GB-UkCU-TRH
+... GB-UkCmUG
+... GB-UkCoI
+... GB-UkCvUL
+... GB-UkCyUK
+... GB-UkElC
+... GB-UkExU
+... GB-UkFlBUFL
+... GB-UkHsBUUC
+... GB-UkIfBRL
+... GB-UkLRCM
+... GB-UkLUC
+... GB-UkLoBS
+... GB-UkLoMdU
+... GB-UkLoSTAC
+... GB-UkLuBC
+... GB-UkMaUHSM
+... GB-UkNrSTB
+... GB-UkOlOLS
+... GB-UkRlWC
+... GB-UkSbWC-T
+... GB-UkScaSH
+... GB-UkSfCL
+... GB-UkSfSSSH
+... GB-UkSofDA
+... GB-UkTeS
+... GB-UkWbSWB
+... GB-UkWfC
+... GB-WlCaUW
+...
+... IT-RM0267
+...
+... NL-04-0041-000
+... NL-AlSARM
+... NL-AsdUvA
+... NL-AsnDA
+... NL-CoGC
+... NL-DdvHVA
+... NL-DtAD
+... NL-DtHHD
+... NL-EhvRHCE
+... NL-EmnGE
+... NL-FwGF
+... NL-GnADNG
+... NL-GnGRA
+... NL-GnPG
+... NL-GnUMG
+... NL-HAMuscom
+... NL-HaKV
+... NL-HaNIMH
+... NL-HaNRK
+... NL-HlGH
+... NL-HnWFA
+... NL-HvsSAGV
+... NL-KrdGA
+... NL-LdnRMV
+... NL-LnsGDM
+... NL-LwPF
+... NL-MpGM
+... NL-MssHVM
+... NL-MtmGM
+... NL-NmRAN
+... NL-OmnHKO
+... NL-OmnOO
+... NL-OmsVHO
+... NL-RtEUR
+... NL-RtSA
+... NL-SelGV
+... NL-SloGS
+... NL-VbGALV
+... NL-WtGAW
+... NL-WtslGT
+... NL-ZhGZ
+... Nl-GdSAMH
+...
+... OCLC-ABI
+... OCLC-ATNHK
+... OCLC-ATQCO
+... OCLC-ATVMV
+... OCLC-BEMCH
+... OCLC-BRI
+... OCLC-CKI
+... OCLC-CSF
+... OCLC-DEKNV
+... OCLC-EMSBC
+... OCLC-ENC
+... OCLC-EZU
+... OCLC-FLNSW
+... OCLC-FNL
+... OCLC-GYR
+... OCLC-I8S
+... OCLC-IDT
+... OCLC-ILW
+... OCLC-JAKUC
+... OCLC-JXE
+... OCLC-JYY
+... OCLC-KW5
+... OCLC-LABMH
+... OCLC-MLBVL
+... OCLC-MSL
+... OCLC-NEZH8
+... OCLC-OME
+... OCLC-QBA
+... OCLC-QP7
+... OCLC-SMP
+... OCLC-SVZ
+... OCLC-TXCLY
+... OCLC-TY7
+... OCLC-U9V
+... OCLC-UDU
+... OCLC-WK6
+... OCLC-WYEMB
+... OCLC-XOH
+... OCLC-YA6
+... OCLC-YEJ
+...
+... US-DLC
+... US-InU-Mu
+... US-MdBJ-W
+...
+... '''
+>>> [x for x in numbers.splitlines() if x and not isil.is_valid(x)]
+[]
+
+
+These have been found online but seem invalid:
+
+... OCLC-B#P
+... OCLC-LT$
+... OCLC-RE#
+... OCLC-RG$
-----------------------------------------------------------------------
Summary of changes:
stdnum/fr/siren.py | 2 +-
stdnum/fr/{siren.py => siret.py} | 79 ++--
stdnum/isil.py | 6 -
..._is_kennitala.doctest => test_fr_siren.doctest} | 37 +-
tests/test_fr_siret.doctest | 85 +++++
tests/test_isil.doctest | 404 +++++++++++++++++++++
6 files changed, 558 insertions(+), 55 deletions(-)
copy stdnum/fr/{siren.py => siret.py} (51%)
copy tests/{test_is_kennitala.doctest => test_fr_siren.doctest} (62%)
create mode 100644 tests/test_fr_siret.doctest
create mode 100644 tests/test_isil.doctest
hooks/post-receive
--
python-stdnum
--
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/python-stdnum-commits/
- python-stdnum branch master updated. 1.3-15-gfd9f953,
Commits of the python-stdnum project