python-stdnum branch master updated. 1.3-12-g4a57d84
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum branch master updated. 1.3-12-g4a57d84
- 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-12-g4a57d84
- Date: Sun, 29 May 2016 12:44:20 +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 4a57d84935d45c78bcd407c2cca558bb74df5a54 (commit)
via 9b74840002acc370d4de405a73dd35fc9df62187 (commit)
via f3c2491c45c39e2052be3e7ee769248f40aacb58 (commit)
via b5397ed3ed77bc8a75f65197309a928158fab138 (commit)
via d85b27f9b03b0ccb25e6e40b6c4179a2ab51ba75 (commit)
from a1afa76b39de86d76be947be07b846d44ea59ce9 (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=4a57d84935d45c78bcd407c2cca558bb74df5a54
commit 4a57d84935d45c78bcd407c2cca558bb74df5a54
Author: Arthur de Jong <arthur@arthurdejong.org>
Date: Sun May 29 12:06:32 2016 +0200
Fix formatting of bulleted list
diff --git a/stdnum/us/tin.py b/stdnum/us/tin.py
index bdac205..b2696b1 100644
--- a/stdnum/us/tin.py
+++ b/stdnum/us/tin.py
@@ -21,6 +21,7 @@
The Taxpayer Identification Number is used used for tax purposes in the
United States. A TIN may be:
+
* a Social Security Number (SSN)
* an Individual Taxpayer Identification Number (ITIN)
* an Employer Identification Number (EIN)
http://arthurdejong.org/git/python-stdnum/commit/?id=9b74840002acc370d4de405a73dd35fc9df62187
commit 9b74840002acc370d4de405a73dd35fc9df62187
Author: Arthur de Jong <arthur@arthurdejong.org>
Date: Sat May 28 17:48:09 2016 +0200
Fix bug in Swiss SSN validation
The validation was delegated to the EAN module but the number is
supposed to be an EAN-13 only and and EAN-8 was also accepted.
This also reformats the docstring.
diff --git a/stdnum/ch/ssn.py b/stdnum/ch/ssn.py
index 548ffa1..78d72a2 100644
--- a/stdnum/ch/ssn.py
+++ b/stdnum/ch/ssn.py
@@ -1,6 +1,7 @@
# vat.py - functions for handling Swiss social security numbers
#
# Copyright (C) 2014 Denis Krienbuehl
+# 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
@@ -19,12 +20,10 @@
"""Swiss social security number ("Sozialversicherungsnummer").
-Also known as "Neue AHV Nummer".
+Also known as "Neue AHV Nummer". The Swiss Sozialversicherungsnummer is used
+to identify individuals for taxation and pension purposes.
-The Swiss Sozialversicherungsnummer is used to identify indivduals for taxation
-and pension purposes.
-
-The number is validated using EAN-13, though dashes are substitued for dots.
+The number is validated using EAN-13, though dashes are substituted for dots.
>>> compact('756.9217.0769.85')
'7569217076985'
@@ -40,8 +39,8 @@ Traceback (most recent call last):
InvalidChecksum: ...
"""
-from stdnum.exceptions import ValidationError
from stdnum import ean
+from stdnum.exceptions import *
from stdnum.util import clean
@@ -58,9 +57,12 @@ def format(number):
def validate(number):
- """Checks to see if the number provided is a valid
- Swiss Sozialversicherungsnummer."""
- return ean.validate(compact(number))
+ """Checks to see if the number provided is a valid Swiss
+ Sozialversicherungsnummer."""
+ number = compact(number)
+ if len(number) != 13:
+ raise InvalidLength()
+ return ean.validate(number)
def is_valid(number):
diff --git a/tests/test_ch_ssn.doctest b/tests/test_ch_ssn.doctest
new file mode 100644
index 0000000..2a496ca
--- /dev/null
+++ b/tests/test_ch_ssn.doctest
@@ -0,0 +1,33 @@
+test_ch_ssn.doctest - more detailed doctests for stdnum.ch.ssn 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.ch.ssn module. It
+tries to cover more corner cases and detailed functionality that is not
+really useful as module documentation.
+
+>>> from stdnum.ch import ssn
+
+
+Extra tests for length checking and corner cases:
+
+>>> ssn.validate('54165168') # valid EAN-8 but incorrect length
+Traceback (most recent call last):
+ ...
+InvalidLength: ...
http://arthurdejong.org/git/python-stdnum/commit/?id=f3c2491c45c39e2052be3e7ee769248f40aacb58
commit f3c2491c45c39e2052be3e7ee769248f40aacb58
Author: Arthur de Jong <arthur@arthurdejong.org>
Date: Sat May 28 13:17:52 2016 +0200
Fix bug in Irish VAT number validation
The last digits of the number that should be letters were not tested to
be letters which could result in ValueError being raised for certain
validations.
This also clarifies the documentation and adds a convert() function to
convert numbers from the old format (where the second character would be
a letter or symbol) to the new format (7 digits followed by 1 or 2
letters).
diff --git a/stdnum/ie/vat.py b/stdnum/ie/vat.py
index c3740e7..215480a 100644
--- a/stdnum/ie/vat.py
+++ b/stdnum/ie/vat.py
@@ -1,6 +1,6 @@
# vat.py - functions for handling Irish VAT numbers
#
-# Copyright (C) 2012, 2013 Arthur de Jong
+# Copyright (C) 2012-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
@@ -17,10 +17,11 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
-"""VAT (Irish VAT number).
+"""VAT (Irish tax reference number).
-The Irish VAT number consists of 8 digits. The last digit is a check
-letter, the second digit may be a number, a letter, "+" or "*".
+The Irish VAT number consists of 8 or 9 digits. The number is either 7 digits
+and 1 letter (optionally followed by a W for married women), 7 digits and 2
+letters, or 6 digits and 2 letters or symbols (in second and last position).
>>> validate('IE 6433435F') # pre-2013 format
'6433435F'
@@ -36,6 +37,8 @@ InvalidChecksum: ...
Traceback (most recent call last):
...
InvalidFormat: ...
+>>> convert('1F23456T')
+'0234561T'
"""
from stdnum.exceptions import *
@@ -51,14 +54,16 @@ def compact(number):
return number
+_alphabet = 'WABCDEFGHIJKLMNOPQRSTUV'
+
+
def calc_check_digit(number):
"""Calculate the check digit. The number passed should not have the
check digit included."""
- alphabet = 'WABCDEFGHIJKLMNOPQRSTUV'
number = compact(number).zfill(7)
- return alphabet[(
+ return _alphabet[(
sum((8 - i) * int(n) for i, n in enumerate(number[:7])) +
- 9 * alphabet.index(number[7:])) % 23]
+ 9 * _alphabet.index(number[7:])) % 23]
def validate(number):
@@ -67,14 +72,16 @@ def validate(number):
number = compact(number)
if not number[:1].isdigit() or not number[2:7].isdigit():
raise InvalidFormat()
+ if not all(x in _alphabet for x in number[7:]):
+ raise InvalidFormat()
if len(number) not in (8, 9):
raise InvalidLength()
if number[:7].isdigit():
- # new system
+ # new system (7 digits followed by 1 or 2 letters)
if number[7] != calc_check_digit(number[:7] + number[8:]):
raise InvalidChecksum()
elif number[1] in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ+*':
- # old system
+ # old system (second character is a letter or symbol)
if number[7] != calc_check_digit(number[2:7] + number[0]):
raise InvalidChecksum()
else:
@@ -89,3 +96,13 @@ def is_valid(number):
return bool(validate(number))
except ValidationError:
return False
+
+
+def convert(number):
+ """Convert an "old" style 8-digit VAT number where the second character
+ is a letter to the new 8-digit format where only the last digit is a
+ character."""
+ number = compact(number)
+ if len(number) == 8 and not number[1].isdigit():
+ number = '0' + number[2:7] + number[0] + number[7:]
+ return number
diff --git a/tests/test_ie_vat.doctest b/tests/test_ie_vat.doctest
new file mode 100644
index 0000000..cbdf958
--- /dev/null
+++ b/tests/test_ie_vat.doctest
@@ -0,0 +1,48 @@
+test_ie_vat.doctest - more detailed doctests for stdnum.ie.vat 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.ie.vat module. It
+tries to cover more corner cases and detailed functionality that is not
+really useful as module documentation.
+
+>>> from stdnum.ie import vat
+
+
+Extra tests for length checking and corner cases:
+
+>>> vat.validate('111222333') # check digits should be letters
+Traceback (most recent call last):
+ ...
+InvalidFormat: ...
+>>> vat.validate('1234567ABC') # too long
+Traceback (most recent call last):
+ ...
+InvalidLength: ...
+
+
+The convert() function should leave invalid or already converted values
+alone.
+
+>>> vat.convert('IE8D79739I')
+'0797398I'
+>>> vat.convert('IE 632 3420 C')
+'6323420C'
+>>> vat.convert('123')
+'123'
http://arthurdejong.org/git/python-stdnum/commit/?id=b5397ed3ed77bc8a75f65197309a928158fab138
commit b5397ed3ed77bc8a75f65197309a928158fab138
Author: Arthur de Jong <arthur@arthurdejong.org>
Date: Sat May 28 11:47:57 2016 +0200
Small improvements to tests
This includes a formatting fix and removes an unused variable from a
test.
diff --git a/tests/test_robustness.doctest b/tests/test_robustness.doctest
index b38ff97..8e2c4be 100644
--- a/tests/test_robustness.doctest
+++ b/tests/test_robustness.doctest
@@ -1,6 +1,6 @@
test_robustness.doctest - test is_valid() functions to not break
-Copyright (C) 2011, 2012 Arthur de Jong
+Copyright (C) 2011-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
@@ -22,12 +22,11 @@ This file contains some tests for modules in the stdnum
package to
check whether all provided is_valid() functions can handle clearly
invalid junk.
->>> testvalues = ( None, '*&^%$', '', 0, False, object(), 'Q', 'QQ', '3')
+>>> testvalues = (None, '*&^%$', '', 0, False, object(), 'Q', 'QQ', '3')
>>> from stdnum.util import get_number_modules
Go over each module and try every value.
->>> badmodules = []
>>> for mod in get_number_modules():
... results = [ x for x in testvalues if mod.is_valid(x) != False ]
... if results:
http://arthurdejong.org/git/python-stdnum/commit/?id=d85b27f9b03b0ccb25e6e40b6c4179a2ab51ba75
commit d85b27f9b03b0ccb25e6e40b6c4179a2ab51ba75
Author: Arthur de Jong <arthur@arthurdejong.org>
Date: Sat May 28 11:29:34 2016 +0200
Fix get_module_description()
This fixes the initial implementation in 3f6d52a.
diff --git a/stdnum/util.py b/stdnum/util.py
index 266b292..21307ba 100644
--- a/stdnum/util.py
+++ b/stdnum/util.py
@@ -162,7 +162,7 @@ def get_module_description(module):
"""Return a description of the number."""
doc = pydoc.splitdoc(pydoc.getdoc(module))[1]
# remove the doctests
- return _strip_doctest_re.sub('', doc[1]).strip(),
+ return _strip_doctest_re.sub('', doc).strip()
def get_module_list():
-----------------------------------------------------------------------
Summary of changes:
stdnum/ch/ssn.py | 20 ++++++-----
stdnum/ie/vat.py | 35 ++++++++++++++-----
stdnum/us/tin.py | 1 +
stdnum/util.py | 2 +-
tests/{test_no_mva.doctest => test_ch_ssn.doctest} | 37 +++++++-------------
tests/{test_ean.doctest => test_ie_vat.doctest} | 39 ++++++++++++----------
tests/test_robustness.doctest | 5 ++-
7 files changed, 75 insertions(+), 64 deletions(-)
copy tests/{test_no_mva.doctest => test_ch_ssn.doctest} (58%)
copy tests/{test_ean.doctest => test_ie_vat.doctest} (56%)
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-12-g4a57d84,
Commits of the python-stdnum project