Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests/test_isan.doctest
blob: 10fc5b09fa6a51a2d3f1d88e958549f9726eaff8 (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
88
89
90
91
test_isan.doctest - more detailed doctests for stdnum.isan 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.isan module. It
tries to test more corner cases and detailed functionality that is not
really useful as module documentation.

>>> from stdnum import isan


This is how numbers should be split (possible with and without
episode number):

>>> isan.split('000000018947000000000000')
('000000018947', '0000', '', '00000000', '')
>>> isan.split('0000-0000-D07A-0090-Q-0000-0000-X')
('00000000D07A', '0090', 'Q', '00000000', 'X')
>>> isan.split('000000018947000000000000')
('000000018947', '0000', '', '00000000', '')
>>> isan.split('1881-66C7-3420-6541-Y')
('188166C73420', '6541', 'Y', '', '')
>>> isan.split('1881-66C7-3420-6541')
('188166C73420', '6541', '', '', '')

Compacting should also work:

>>> isan.compact('000000018947000000000000')
'000000018947000000000000'
>>> isan.compact('0000-0000-D07A-0090-Q-0000-0000-X')
'00000000D07A009000000000'
>>> isan.compact('000000018947000000000000')
'000000018947000000000000'
>>> isan.compact('1881-66C7-3420-6541-Y')
'188166C734206541'
>>> isan.compact('1881-66C7-3420-6541')
'188166C734206541'


These should be valid numbers:

>>> isan.is_valid('0000-0000-D07A-0090-Q-0000-0000-X')
True
>>> isan.is_valid('1881-66C7-3420-6541-Y-9F3A-0245-O')
True
>>> isan.is_valid('0000-0000-D07A-0090-Q-0000-0000-X')
True
>>> isan.is_valid('0000-0000-D07A-0090-Q')
True


And these should be invalid:

>>> isan.is_valid('00000000D07A0090-Z') # wrong check digit
False
>>> isan.is_valid('3abc6800-0041X1-20') # illegal character
False


The format() function can add the check digit if needed. It should leave
alone existing check digits (even invalid ones) and respect the presence
or absence of a version number.

>>> isan.format('00000000D07A0090')
'0000-0000-D07A-0090-Q'
>>> isan.format('1881-66C734206541-9F3A-0245')
'1881-66C7-3420-6541-Y-9F3A-0245-O'
>>> isan.format('1881-66C7-3420-6541-?-9F3A-0245-?', strip_check_digits=True, add_check_digits=True)
'1881-66C7-3420-6541-Y-9F3A-0245-O'


A simple test for the to_binary() function.

>>> isan.to_binary('0000-0000-D07A-0090-Q').encode('hex')
'00000000d07a0090'