diff options
-rw-r--r-- | setup.cfg | 1 | ||||
-rw-r--r-- | tests/test_isbn.doctest | 58 | ||||
-rw-r--r-- | tests/test_issn.doctest | 35 |
3 files changed, 94 insertions, 0 deletions
@@ -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 diff --git a/tests/test_isbn.doctest b/tests/test_isbn.doctest index d71988d..3798651 100644 --- a/tests/test_isbn.doctest +++ b/tests/test_isbn.doctest @@ -97,3 +97,61 @@ current _prefixes list. >>> 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) diff --git a/tests/test_issn.doctest b/tests/test_issn.doctest new file mode 100644 index 0000000..b88cd7c --- /dev/null +++ b/tests/test_issn.doctest @@ -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 |