Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests/test_ismn.doctest
blob: 55c2271434b4c796a4a8728144a317b58171dcce (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
test_ismn.doctest - more detailed doctests for stdnum.ismn module

Copyright (C) 2010 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.is_valid('979-0-3217-6543-6')
True
>>> ismn.is_valid(u'979-0-3217-6544-3')
True
>>> ismn.is_valid('9790321765450')
True
>>> ismn.is_valid('M-3217-6546-7')
True
>>> ismn.is_valid('M321765474')
True
>>> ismn.is_valid('979-0-260000438')
True


Tests for mangling and incorect check digits.

>>> ismn.is_valid('979-0-3217-6543-x')
False
>>> ismn.is_valid('M-3217-6546-8')
False
>>> ismn.is_valid('979M321765450')
False


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'


Regrouping tests.

>>> ismn.format('M-3217-6546-7')
'979-0-3217-6546-7'
>>> ismn.format('9790321765450')
'979-0-3217-6545-0'