diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2010-11-24 23:09:28 +0100 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2010-11-24 23:09:28 +0100 |
commit | 124c16d401d3a8e473886dcb0b02c026ddcfd97d (patch) | |
tree | cd2478e349d3c56f424b4a5139c99dc1cf70c995 /tests/test_isbn.doctest | |
parent | 72a0b96a743c05abffd146916a45b313594641e0 (diff) |
implement a new numdb module to hold information on hierarchically organised numbers and switch the isbn module to use this format instead
git-svn-id: http://arthurdejong.org/svn/python-stdnum/python-stdnum@42 9dea7c4f-944c-4273-ac1a-574ede026edc
Diffstat (limited to 'tests/test_isbn.doctest')
-rw-r--r-- | tests/test_isbn.doctest | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/tests/test_isbn.doctest b/tests/test_isbn.doctest index fc6a7b9..8073645 100644 --- a/tests/test_isbn.doctest +++ b/tests/test_isbn.doctest @@ -77,82 +77,3 @@ Regrouping tests. ('', '99996', '', '7827', '0') >>> isbn.split('979-20-1234567-8') ('979', '', '', '201234567', '8') - - -Some tests for the ranges module. This is more an internal module so -tests here are not very critical. - ->>> from stdnum.isbn import ranges ->>> list(ranges._wrap(2 * 'abc def ghijklmn opqr stuvwx yz', 40))[0] -'abc def ghijklmn opqr stuvwx yzabc def' - - -Test output function. Bit of a limited test but we see if the serialised -form of the prefix/ranges list contains at least the same prefixes as the -current _prefixes list. - ->>> import StringIO ->>> output = StringIO.StringIO() ->>> ranges.output(output) ->>> 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 ->>> ranges.output() -# generated from RangeMessage.xml, downloaded from -# http://www.isbn-international.org/agency?rmxml=1 -# serial 0aad2b046ddd9b30e080cb2b24afc868 -# date Thu, 20 May 2010 18:36:55 GMT -_prefixes = """ -978 0-5 600-649 -978-0 00-19 200-699 -""" - -Restore the original ranges and clean up. - ->>> ranges._prefixes = save_prefixes ->>> import os ->>> os.unlink(xmlfile.name) |