Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests/test_casrn.doctest
blob: 3ba6906f822211a9911bbe99b8d502b2f07a572a (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
test_casrn.doctest - more detailed doctests for the stdnum.casrn module

Copyright (C) 2017 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.casrn module. It
contains some corner case tests and tries to validate numbers that have been
found online.

>>> from stdnum import casrn
>>> from stdnum.exceptions import *


The number seems to always include separators so we introduce them if they
are not present (but will fail validation if they are in the incorrect
place or are inconsistently placed).

>>> casrn.validate('329-65-7')
'329-65-7'
>>> casrn.validate('329657')
'329-65-7'
>>> casrn.validate('32-96-57')
Traceback (most recent call last):
    ...
InvalidFormat: ...
>>> casrn.validate('32965-7')
Traceback (most recent call last):
    ...
InvalidFormat: ...


The first component of a CAS RN can be 2 to 7 digits long.

>>> casrn.validate('51-43-4')
'51-43-4'
>>> casrn.validate('1-43-4')
Traceback (most recent call last):
    ...
InvalidLength: ...
>>> casrn.validate('2040295-03-0')
'2040295-03-0'
>>> casrn.validate('12040295-03-0')
Traceback (most recent call last):
    ...
InvalidLength: ...


These should all be valid CAS Registry Numbers.

>>> numbers = '''
...
... 51-43-4
... 87-86-5
... 150-05-0
... 329-65-7
... 608-93-5
... 1305-78-8
... 1344-09-8
... 1972-08-3
... 2650-18-2
... 3087-16-9
... 3524-62-7
... 6104-58-1
... 7440-44-0
... 7440-47-3
... 7732-18-5
... 7782-40-3
... 7782-42-5
... 8007-40-7
... 9031-72-5
... 9032-02-4
... 9035-40-9
... 12627-53-1
... 14314-42-2
... 16065-83-1
... 18540-29-9
... 49863-03-8
... 55480-22-3
... 56182-07-1
... 60679-64-3
... 70051-97-7
... 126266-35-1
... 126371-03-7
... 153250-52-3
... 308067-58-5
... 2040295-03-0
...
... '''
>>> [x for x in numbers.splitlines() if x and not casrn.is_valid(x)]
[]