lists.arthurdejong.org
RSS feed

python-stdnum commit: r58 - python-stdnum/tests

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum commit: r58 - python-stdnum/tests



Author: arthur
Date: Sat Feb  5 23:03:16 2011
New Revision: 58
URL: http://arthurdejong.org/viewvc/python-stdnum?view=rev&revision=58

Log:
move all robustness tests into one test file

Added:
   python-stdnum/tests/test_robustness.doctest
Deleted:
   python-stdnum/tests/test_br_cpf.doctest
   python-stdnum/tests/test_issn.doctest
   python-stdnum/tests/test_nl_bsn.doctest
Modified:
   python-stdnum/tests/test_iban.doctest
   python-stdnum/tests/test_imei.doctest
   python-stdnum/tests/test_isan.doctest
   python-stdnum/tests/test_isbn.doctest
   python-stdnum/tests/test_ismn.doctest
   python-stdnum/tests/test_luhn.doctest
   python-stdnum/tests/test_meid.doctest
   python-stdnum/tests/test_verhoeff.doctest

Modified: python-stdnum/tests/test_iban.doctest
==============================================================================
--- python-stdnum/tests/test_iban.doctest       Sat Feb  5 22:57:09 2011        
(r57)
+++ python-stdnum/tests/test_iban.doctest       Sat Feb  5 23:03:16 2011        
(r58)
@@ -182,17 +182,3 @@
 ... '''
 >>> [ x for x in numbers.splitlines() if x and iban.is_valid(x) ]
 []
-
-
-The is_valid() method should be fairly robust against invalid junk passed:
-
->>> iban.is_valid(None)
-False
->>> iban.is_valid('')
-False
->>> iban.is_valid(0)
-False
->>> iban.is_valid(object())
-False
->>> iban.is_valid('3abc6800-0041X1-20')
-False

Modified: python-stdnum/tests/test_imei.doctest
==============================================================================
--- python-stdnum/tests/test_imei.doctest       Sat Feb  5 22:57:09 2011        
(r57)
+++ python-stdnum/tests/test_imei.doctest       Sat Feb  5 23:03:16 2011        
(r58)
@@ -51,20 +51,6 @@
 'IMEISV'
 
 
-The is_valid() method should be fairly robust against invalid junk passed:
-
->>> imei.is_valid(None)
-False
->>> imei.is_valid('')
-False
->>> imei.is_valid(0)
-False
->>> imei.is_valid(object())
-False
->>> imei.is_valid('3abc6800-0041X1-20')
-False
-
-
 The format() function can add the check digit if needed. It should leave
 alone existing check digits (even invalid ones) and only add them to the
 14 digit format.

Modified: python-stdnum/tests/test_isan.doctest
==============================================================================
--- python-stdnum/tests/test_isan.doctest       Sat Feb  5 22:57:09 2011        
(r57)
+++ python-stdnum/tests/test_isan.doctest       Sat Feb  5 23:03:16 2011        
(r58)
@@ -63,21 +63,13 @@
 True
 >>> isan.is_valid('0000-0000-D07A-0090-Q')
 True
->>> isan.is_valid('00000000D07A0090-Z') # wrong check digit
-False
 
 
-The is_valid() method should be fairly robust against invalid junk passed:
+And these should be invalid:
 
->>> isan.is_valid(None)
-False
->>> isan.is_valid('')
-False
->>> isan.is_valid(0)
-False
->>> isan.is_valid(object())
+>>> isan.is_valid('00000000D07A0090-Z') # wrong check digit
 False
->>> isan.is_valid('3abc6800-0041X1-20')
+>>> isan.is_valid('3abc6800-0041X1-20') # illegal character
 False
 
 

Modified: python-stdnum/tests/test_isbn.doctest
==============================================================================
--- python-stdnum/tests/test_isbn.doctest       Sat Feb  5 22:57:09 2011        
(r57)
+++ python-stdnum/tests/test_isbn.doctest       Sat Feb  5 23:03:16 2011        
(r58)
@@ -25,26 +25,6 @@
 >>> from stdnum import isbn
 
 
-These are normal variations that should just work.
-
->>> isbn.is_valid('978-9024538270')
-True
->>> isbn.is_valid(u'1857982185')
-True
->>> isbn.is_valid('85152-629-2') # 9-digit SBN (silently converted to ISBN10)
-True
-
-
-These are tests to check what happes when a wrong type is passed.
-
->>> isbn.is_valid(1857982185) # integer, not string
-False
->>> isbn.is_valid(None)
-False
->>> isbn.is_valid('')
-False
-
-
 Tests for mangling and incorect check digits.
 
 >>> isbn.is_valid('08515x-629-2') # added X in the middle

Modified: python-stdnum/tests/test_ismn.doctest
==============================================================================
--- python-stdnum/tests/test_ismn.doctest       Sat Feb  5 22:57:09 2011        
(r57)
+++ python-stdnum/tests/test_ismn.doctest       Sat Feb  5 23:03:16 2011        
(r58)
@@ -41,16 +41,6 @@
 True
 
 
-These are tests to check what happens when a wrong type is passed.
-
->>> ismn.is_valid(1857982185) # integer, not string
-False
->>> ismn.is_valid(None)
-False
->>> ismn.is_valid('')
-False
-
-
 Tests for mangling and incorect check digits.
 
 >>> ismn.is_valid('979-0-3217-6543-x')

Modified: python-stdnum/tests/test_luhn.doctest
==============================================================================
--- python-stdnum/tests/test_luhn.doctest       Sat Feb  5 22:57:09 2011        
(r57)
+++ python-stdnum/tests/test_luhn.doctest       Sat Feb  5 23:03:16 2011        
(r58)
@@ -58,18 +58,3 @@
 '7'
 >>> luhn.is_valid('3984382462386423786482364872364827347')
 True
-
-
-Furthermore the is_valid() method should be fairly robust against invalid
-junk passed:
-
->>> luhn.is_valid(None)
-False
->>> luhn.is_valid('')
-False
->>> luhn.is_valid(0)
-False
->>> luhn.is_valid(object())
-False
->>> luhn.is_valid('65a4')
-False

Modified: python-stdnum/tests/test_meid.doctest
==============================================================================
--- python-stdnum/tests/test_meid.doctest       Sat Feb  5 22:57:09 2011        
(r57)
+++ python-stdnum/tests/test_meid.doctest       Sat Feb  5 23:03:16 2011        
(r58)
@@ -58,19 +58,12 @@
 
 The is_valid() method should be fairly robust against invalid junk passed:
 
->>> meid.is_valid(None)
-False
->>> meid.is_valid('')
-False
->>> meid.is_valid(0)
-False
->>> meid.is_valid(object())
-False
 >>> meid.is_valid('29360 ABCDE 0070 3710')
 False
 >>> meid.is_valid('GF 01 23 45 0A BC DE')
 False
 
+
 The compact method should convert to HEX if needed and can optionally leave
 the check digit intact.
 

Added: python-stdnum/tests/test_robustness.doctest
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ python-stdnum/tests/test_robustness.doctest Sat Feb  5 23:03:16 2011        
(r58)
@@ -0,0 +1,39 @@
+test_robustness.doctest - test is_valid() fcuntions to not break
+
+Copyright (C) 2011 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 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(),  )
+
+>>> from stdnum import grid, iban, imei, isan, isbn, ismn, issn
+>>> from stdnum import luhn, meid, verhoeff
+>>> from stdnum.iso7064 import mod_11_10, mod_11_2, mod_37_2, mod_37_36, 
mod_97_10
+>>> from stdnum.nl import bsn
+>>> from stdnum.br import cpf
+
+Go over each imported module and try every value.
+
+>>> for mod in locals().values():
+...     if hasattr(mod, 'is_valid'):
+...         results = [ x for x in testvalues if mod.is_valid(x) ]
+...         if results:
+...             print mod.__name__, results

Modified: python-stdnum/tests/test_verhoeff.doctest
==============================================================================
--- python-stdnum/tests/test_verhoeff.doctest   Sat Feb  5 22:57:09 2011        
(r57)
+++ python-stdnum/tests/test_verhoeff.doctest   Sat Feb  5 23:03:16 2011        
(r58)
@@ -59,18 +59,3 @@
 '7'
 >>> verhoeff.is_valid('3984382462386423786482364872364827347')
 True
-
-
-Furthermore the is_valid() method should be fairly robust against invalid
-junk passed:
-
->>> verhoeff.is_valid(None)
-False
->>> verhoeff.is_valid('')
-False
->>> verhoeff.is_valid(0)
-False
->>> verhoeff.is_valid(object())
-False
->>> verhoeff.is_valid('65a4')
-False
-- 
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/python-stdnum-commits