-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_functionality.py
More file actions
98 lines (57 loc) · 1.93 KB
/
test_functionality.py
File metadata and controls
98 lines (57 loc) · 1.93 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
91
92
93
94
95
96
97
98
import pytest
from casregnum import CAS
@pytest.fixture
def octanes():
return [
CAS(111_65_9), CAS(592_27_8), CAS(589_81_1), CAS(589_53_7), CAS(590_73_8), CAS(584_94_1),
CAS(589_43_5), CAS(592_13_2), CAS(563_16_6), CAS(583_48_2), CAS(619_99_8), CAS(564_02_3),
CAS(540_84_1), CAS(560_21_4), CAS(565_75_3), CAS(609_26_7), CAS(1067_08_9), CAS(594_82_1),
]
@pytest.fixture
def octanes_sorted():
return [
CAS(111_65_9), CAS(540_84_1), CAS(560_21_4), CAS(563_16_6), CAS(564_02_3), CAS(565_75_3),
CAS(583_48_2), CAS(584_94_1), CAS(589_43_5), CAS(589_53_7), CAS(589_81_1), CAS(590_73_8),
CAS(592_13_2), CAS(592_27_8), CAS(594_82_1), CAS(609_26_7), CAS(619_99_8), CAS(1067_08_9),
]
# pytest fixtures
@pytest.fixture
def caffeine():
return CAS(58_08_2)
@pytest.fixture
def theine():
return CAS("58-08-2")
@pytest.fixture
def l_lacticacid():
return CAS(79_33_4)
@pytest.fixture
def d_lacticacid():
return CAS("10326-41-7")
# Tests for functionality
def test_cas_check_digit(caffeine):
assert caffeine.check_digit == 2
def test_cas_check_digit_print(caffeine):
assert caffeine.check_digit
def test_cas_string_output(caffeine):
assert str(caffeine) == "58-08-2"
def test_cas_equal(caffeine, theine):
assert caffeine == theine
def test_cas_lesser_than(l_lacticacid, d_lacticacid):
assert l_lacticacid < d_lacticacid
def test_cas_format_string(caffeine):
assert f"{caffeine:0>12}"
def test_for_sorting(octanes, octanes_sorted):
assert sorted(octanes) == octanes_sorted
# Tests for error handling
@pytest.mark.xfail(raises=TypeError)
def test_cas_invalid_input():
CAS(6417.5)
@pytest.mark.xfail(raises=ValueError)
def test_cas_format_unreadable():
CAS("64 - 17 - 5")
@pytest.mark.xfail(raises=ValueError)
def test_cas_range_error():
CAS(100)
@pytest.mark.xfail(raises=ValueError)
def test_cas_check_digit_error():
CAS("64-17-6")