blob: c3d46b6405314b8b18094536b83f93d1f04cc29a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
test_ismn.doctest - more detailed doctests for stdnum.ismn module
Copyright (C) 2010, 2011, 2012, 2013 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.ismn module. It
tries to test more corner cases and detailed functionality that is not
really useful as module documentation.
>>> from stdnum import ismn
These are normal variations that should just work.
>>> ismn.validate('979-0-3217-6543-6')
'9790321765436'
>>> ismn.validate('979-0-3217-6544-3')
'9790321765443'
>>> ismn.validate('9790321765450')
'9790321765450'
>>> ismn.validate('M-3217-6546-7')
'M321765467'
>>> ismn.validate('M321765474')
'M321765474'
>>> ismn.validate('979-0-260000438')
'9790260000438'
Tests for mangling and incorect check digits.
>>> ismn.validate('979-0-3217-6543-x')
Traceback (most recent call last):
...
InvalidFormat: ...
>>> ismn.validate('M-3217-6546-8')
Traceback (most recent call last):
...
InvalidChecksum: ...
>>> ismn.validate('979M321765450')
Traceback (most recent call last):
...
InvalidFormat: ...
>>> ismn.validate('Z-3217-6546-8')
Traceback (most recent call last):
...
InvalidFormat: ...
See if 10 to 13 digit conversion works.
>>> ismn.to_ismn13('979-0-32176544-3') # ismn13 should stay ismn13
'979-0-32176544-3'
>>> ismn.to_ismn13('M-32176546-7')
'979-0-32176546-7'
>>> ismn.to_ismn13('M 3217 65504')
'979 0 3217 65504'
Test the ismn_type() function
>>> ismn.ismn_type('M-3217-6546-7')
'ISMN10'
>>> ismn.ismn_type('BAD')
>>> ismn.ismn_type('9790321765450')
'ISMN13'
Regrouping tests.
>>> ismn.format('M-3217-6546-7')
'979-0-3217-6546-7'
>>> ismn.format('9790321765450')
'979-0-3217-6545-0'
|