diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2010-08-20 21:41:39 +0200 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2010-08-20 21:41:39 +0200 |
commit | f125f3e9873f677a664c9b27fcd4e9210da98013 (patch) | |
tree | 3950dc6c6111b43b83b5b2a641c6d683cf244d0b /tests/test_isbn.doctest | |
parent | d622d9268792e791c4f8499eb88d4b430ec97d41 (diff) |
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
Diffstat (limited to 'tests/test_isbn.doctest')
-rw-r--r-- | tests/test_isbn.doctest | 58 |
1 files changed, 58 insertions, 0 deletions
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) |