Repository navigation
Expand file tree
/
Copy pathtest_finance.py
More file actions
90 lines (66 loc) · 2.49 KB
/
Copy pathtest_finance.py
File metadata and controls
90 lines (66 loc) · 2.49 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
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
"""Test Finance."""
# standard
from typing import Callable
# external
import pytest
# local
from validators import ValidationError, cusip, isin, sedol
# ==> CUSIP <== #
@pytest.mark.parametrize("value", ["912796X38", "912796X20", "912796x20"])
def test_returns_true_on_valid_cusip(value: str):
"""Test returns true on valid cusip."""
assert cusip(value)
@pytest.mark.parametrize("value", ["912796T67", "912796T68", "XCVF", "00^^^1234"])
def test_returns_failed_validation_on_invalid_cusip(value: str):
"""Test returns failed validation on invalid cusip."""
assert isinstance(cusip(value), ValidationError)
# ==> ISIN <== #
@pytest.mark.parametrize("value", ["US0004026250", "US0378331005", "GB0002634946", "DE000BAY0017"])
def test_returns_true_on_valid_isin(value: str):
"""Test returns true on valid isin."""
assert isin(value)
@pytest.mark.parametrize(
"value",
[
"010378331005",
"XCVF",
"00^^^1234",
"A000009",
# valid length and characters but wrong check digit
"US0378331006",
"US0004026251",
"GB0002634947",
],
)
def test_returns_failed_validation_on_invalid_isin(value: str):
"""Test returns failed validation on invalid isin."""
assert isinstance(isin(value), ValidationError)
# ==> SEDOL <== #
@pytest.mark.parametrize("value", ["0263494", "0540528", "B000009"])
def test_returns_true_on_valid_sedol(value: str):
"""Test returns true on valid sedol."""
assert sedol(value)
@pytest.mark.parametrize("value", ["0540526", "XCVF", "00^^^1234", "A000009"])
def test_returns_failed_validation_on_invalid_sedol(value: str):
"""Test returns failed validation on invalid sedol."""
assert isinstance(sedol(value), ValidationError)
@pytest.mark.parametrize(
"validate, value",
[
(cusip, "03783310J"),
(cusip, "03783310j"),
(cusip, "03783310@"),
(sedol, "293692L"),
(sedol, "B12345G"),
(sedol, "B12345Q"),
],
)
def test_rejects_non_numeric_check_digit(validate: Callable[[str], object], value: str):
"""Reject letters and symbols that accidentally satisfy the checksum."""
assert isinstance(validate(value), ValidationError)
@pytest.mark.parametrize(
"validate, value", [(cusip, "037833100"), (sedol, "2936921"), (sedol, "B123456")]
)
def test_accepts_numeric_check_digit(validate: Callable[[str], object], value: str):
"""Keep valid numeric check digits, including alphanumeric identifiers."""
assert validate(value) is True