lists.arthurdejong.org
RSS feed

python-stdnum commit: r29 - in python-stdnum: . tests

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

python-stdnum commit: r29 - in python-stdnum: . tests



Author: arthur
Date: Fri Aug 20 21:41:39 2010
New Revision: 29
URL: http://arthurdejong.org/viewvc/python-stdnum?view=rev&revision=29

Log:
write some more tests (some of which are a bit of a hack) to get coverage to 
100%

Added:
   python-stdnum/tests/test_issn.doctest
Modified:
   python-stdnum/setup.cfg
   python-stdnum/tests/test_isbn.doctest

Modified: python-stdnum/setup.cfg
==============================================================================
--- python-stdnum/setup.cfg     Fri Aug 20 18:25:33 2010        (r28)
+++ python-stdnum/setup.cfg     Fri Aug 20 21:41:39 2010        (r29)
@@ -2,6 +2,7 @@
 with-doctest=true
 doctest-extension=doctest
 with-coverage=true
+cover-package=stdnum
 cover-erase=true
 cover-html=true
 cover-html-dir=coverage

Modified: python-stdnum/tests/test_isbn.doctest
==============================================================================
--- python-stdnum/tests/test_isbn.doctest       Fri Aug 20 18:25:33 2010        
(r28)
+++ python-stdnum/tests/test_isbn.doctest       Fri Aug 20 21:41:39 2010        
(r29)
@@ -97,3 +97,61 @@
 >>> k = set( x.split(' ')[0] for x in 
 >>> StringIO.StringIO(output.getvalue()).readlines() )
 >>> k == set(ranges._prefixes.keys())
 True
+
+
+Make an XML file with somre prefix definitions and load that into the
+ranges module.
+
+First save the current ranges so we can restore later.
+
+>>> save_prefixes = ranges._prefixes
+
+Write the XML to a file.
+
+>>> import tempfile
+>>> xmlfile = tempfile.NamedTemporaryFile(delete=False)
+>>> xmlfile.write("""<?xml version='1.0' encoding='utf-8'?>
+... <ISBNRangeMessage>
+... <MessageSerialNumber>0aad2b046ddd9b30e080cb2b24afc868</MessageSerialNumber>
+... <MessageDate>Thu, 20 May 2010 18:36:55 GMT</MessageDate>
+...  <EAN.UCCPrefixes><EAN.UCC>
+...   <Prefix>978</Prefix>
+...   <Rules>
+...    <Rule><Range>0000000-5999999</Range><Length>1</Length></Rule>
+...    <Rule><Range>6000000-6499999</Range><Length>3</Length></Rule>
+...    <Rule><Range>6500000-6999999</Range><Length>0</Length></Rule>
+...   </Rules>
+...  </EAN.UCC></EAN.UCCPrefixes>
+...  <RegistrationGroups>
+...   <Group>
+...    <Prefix>978-0</Prefix>
+...    <Rules>
+...     <Rule><Range>0000000-1999999</Range><Length>2</Length></Rule>
+...     <Rule><Range>2000000-6999999</Range><Length>3</Length></Rule>
+...    </Rules>
+...   </Group>
+...  </RegistrationGroups>
+... </ISBNRangeMessage>
+... """)
+>>> xmlfile.close()
+
+Load the XML file by URL and output it to another string. Check if the
+content of the XML has been
+
+>>> import urllib
+>>> ranges.download('file://' + urllib.pathname2url(xmlfile.name))
+>>> import sys
+>>> output = StringIO.StringIO()
+>>> save_stdout = sys.stdout
+>>> sys.stdout = output
+>>> ranges.output()
+>>> sys.stdout = save_stdout
+>>> output = output.getvalue()
+>>> '\n978 0-5 600-649\n' in output and '\n978-0 00-19 200-699\n' in output
+True
+
+Restore the original ranges and clean up.
+
+>>> ranges._prefixes = save_prefixes
+>>> import os
+>>> os.unlink(xmlfile.name)

Added: python-stdnum/tests/test_issn.doctest
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ python-stdnum/tests/test_issn.doctest       Fri Aug 20 21:41:39 2010        
(r29)
@@ -0,0 +1,35 @@
+test_issn.doctest - more detailed doctests for stdnum.issn module
+
+Copyright (C) 2010 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.issn module. It
+tries to test more corner cases and detailed functionality that is not
+really useful as module documentation.
+
+>>> from stdnum import issn
+
+
+These are tests to check what happes when a wrong type is passed.
+
+>>> issn.is_valid(1857982185) # integer, not string
+False
+>>> issn.is_valid(None)
+False
+>>> issn.is_valid('')
+False
--
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/python-stdnum-commits