8000 write some more tests (some of which are a bit of a hack) to get cove… · odony/python-stdnum@f125f3e · GitHub
[go: up one dir, main page]

Skip to content

Commit f125f3e

Browse files
committed
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
1 parent d622d92 commit f125f3e

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
with-doctest=true
33
doctest-extension=doctest
44
with-coverage=true
5+
cover-package=stdnum
56
cover-erase=true
67
cover-html=true
78
cover-html-dir=coverage

tests/test_isbn.doctest

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,61 @@ current _prefixes list.
9797
>>> k = set( x.split(' ')[0] for x in StringIO.StringIO(output.getvalue()).readlines() )
9898
>>> k == set(ranges._prefixes.keys())
9999
True
100+
101+
102+
Make an XML file with somre prefix definitions and load that into the
103+
ranges module.
104+
105+
First save the current ranges so we can restore later.
106+
107+
>>> save_prefixes = ranges._prefixes
108+
109+
Write the XML to a file.
110+
111+
>>> import tempfile
112+
>>> xmlfile = tempfile.NamedTemporaryFile(delete=False)
113+
>>> xmlfile.write("""<?xml version='1.0' encoding='utf-8'?>
114+
... <ISBNRangeMessage>
115+
... <MessageSerialNumber>0aad2b046ddd9b30e080cb2b24afc868</MessageSerialNumber>
116+
... <MessageDate>Thu, 20 May 2010 18:36:55 GMT</MessageDate>
117+
... <EAN.UCCPrefixes><EAN.UCC>
118+
... <Prefix>978</Prefix>
119+
... <Rules>
120+
... <Rule><Range>0000000-5999999</Range><Length>1</Length></Rule>
121+
... <Rule><Range>6000000-6499999</Range><Length>3</Length></Rule>
122+
... <Rule><Range>6500000-6999999</Range><Length>0</Length></Rule>
123+
... </Rules>
124+
... </EAN.UCC></EAN.UCCPrefixes>
125+
... <RegistrationGroups>
126+
... <Group>
127+
... <Prefix>978-0</Prefix>
128+
... <Rules>
129+
... <Rule><Range>0000000-1999999</Range><Length>2</Length></Rule>
130+
... <Rule><Range>2000000-6999999</Range><Length>3</Length></Rule>
131+
... </Rules>
132+
... </Group>
133+
... </RegistrationGroups>
134+
... </ISBNRangeMessage>
135+
... """)
136+
>>> xmlfile.close()
137+
138+
Load the XML file by URL and output it to another string. Check if the
139+
content of the XML has been
140+
141+
>>> import urllib
142+
>>> ranges.download('file://' + urllib.pathname2url(xmlfile.name))
143+
>>> import sys
144+
>>> output = StringIO.StringIO()
145+
>>> save_stdout = sys.stdout
146+
>>> sys.stdout = output
147+
>>> ranges.output()
148+
>>> sys.stdout = save_stdout
149+
>>> output = output.getvalue()
150+
>>> '\n978 0-5 600-649\n' in output and '\n978-0 00-19 200-699\n' in output
151+
True
152+
153+
Restore the original ranges and clean up.
154+
155+
>>> ranges._prefixes = save_prefixes
156+
>>> import os
157+
>>> os.unlink(xmlfile.name)

tests/test_issn.doctest

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
test_issn.doctest - more detailed doctests for stdnum.issn module
2+
3+
Copyright (C) 2010 Arthur de Jong
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18+
02110-1301 USA
19+
20+
21+
This file contains more detailed doctests for the stdnum.issn module. It
22+
tries to test more corner cases and detailed functionality that is not
23+
really useful as module documentation.
24+
25+
>>> from stdnum import issn
26+
27+
28+
These are tests to check what happes when a wrong type is passed.
29+
30+
>>> issn.is_valid(1857982185) # integer, not string
31+
False
32+
>>> issn.is_valid(None)
33+
False
34+
>>> issn.is_valid('')
35+
False

0 commit comments

Comments
 (0)
0