From f125f3e9873f677a664c9b27fcd4e9210da98013 Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Fri, 20 Aug 2010 19:41:39 +0000 Subject: write some more tests (some of which are a bit of a hack) to get coverage to 100% git-svn-id: http://arthurdejong.org/svn/python-stdnum/python-stdnum@29 9dea7c4f-944c-4273-ac1a-574ede026edc --- tests/test_isbn.doctest | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'tests/test_isbn.doctest') 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(""" +... +... 0aad2b046ddd9b30e080cb2b24afc868 +... Thu, 20 May 2010 18:36:55 GMT +... +... 978 +... +... 0000000-59999991 +... 6000000-64999993 +... 6500000-69999990 +... +... +... +... +... 978-0 +... +... 0000000-19999992 +... 2000000-69999993 +... +... +... +... +... """) +>>> 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) -- cgit v1.2.3