forked from arthurdejong/python-stdnum
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_eu_excise.doctest
More file actions
64 lines (49 loc) · 1.9 KB
/
test_eu_excise.doctest
File metadata and controls
64 lines (49 loc) · 1.9 KB
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
test_eu_excise.doctest - more detailed doctests for the stdnum.eu.excise module
Copyright (C) 2023 Cédric Krier
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.eu.excise module. It
tries to validate a number of Excise numbers that have been found online.
>>> from stdnum.eu import excise
>>> from stdnum.exceptions import *
These have been found online and should all be valid numbers.
>>> numbers = '''
...
... LU 00000987ABC
... FR012907E0820
... '''
>>> [x for x in numbers.splitlines() if x and not excise.is_valid(x)]
[]
The following numbers are wrong in one way or another. First we need a
function to be able to determine the kind of error.
>>> def caught(number, exception):
... try:
... excise.validate(number)
... return False
... except exception:
... return True
...
These numbers should be mostly valid except that they have the wrong length.
>>> numbers = '''
...
... LU987ABC
... '''
>>> [x for x in numbers.splitlines() if x and not caught(x, InvalidLength)]
[]
These numbers should be mostly valid except that they have the wrong prefix
>>> numbers = '''
...
... XX00000987ABC
... '''
>>> [x for x in numbers.splitlines() if x and not caught(x, InvalidComponent)]
[]