Skip to content

Commit 7766f77

Browse files
committed
adding pytest file
1 parent b42506f commit 7766f77

2 files changed

Lines changed: 110 additions & 0 deletions

File tree

test/example.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,16 @@
2222
print(f"{isomer:>9}", end=", ")
2323
if i % 6 == 0:
2424
print()
25+
26+
27+
# Output:
28+
# str: 58-08-2
29+
# int: 58082
30+
# check digit: 2
31+
# 58-08-2 == 58-08-2: True
32+
# 58-08-2 > 58-08-2: False
33+
# 79-33-4 > 10326-41-7: False
34+
# 79-33-4 < 10326-41-7: True
35+
# 111-65-9, 540-84-1, 560-21-4, 563-16-6, 564-02-3, 565-75-3,
36+
# 583-48-2, 584-94-1, 589-43-5, 589-53-7, 589-81-1, 590-73-8,
37+
# 592-13-2, 592-27-8, 594-82-1, 609-26-7, 619-99-8, 1067-08-9,

test/test.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import pytest
2+
from casregnum import CAS
3+
4+
5+
@pytest.fixture
6+
def octanes():
7+
return [
8+
CAS(111_65_9), CAS(592_27_8), CAS(589_81_1), CAS(589_53_7), CAS(590_73_8), CAS(584_94_1),
9+
CAS(589_43_5), CAS(592_13_2), CAS(563_16_6), CAS(583_48_2), CAS(619_99_8), CAS(564_02_3),
10+
CAS(540_84_1), CAS(560_21_4), CAS(565_75_3), CAS(609_26_7), CAS(1067_08_9), CAS(594_82_1),
11+
]
12+
13+
14+
@pytest.fixture
15+
def octanes_sorted():
16+
return [
17+
CAS(111_65_9), CAS(540_84_1), CAS(560_21_4), CAS(563_16_6), CAS(564_02_3), CAS(565_75_3),
18+
CAS(583_48_2), CAS(584_94_1), CAS(589_43_5), CAS(589_53_7), CAS(589_81_1), CAS(590_73_8),
19+
CAS(592_13_2), CAS(592_27_8), CAS(594_82_1), CAS(609_26_7), CAS(619_99_8), CAS(1067_08_9),
20+
]
21+
22+
23+
# pytest fixtures
24+
25+
26+
@pytest.fixture
27+
def caffeine():
28+
return CAS(58_08_2)
29+
30+
31+
@pytest.fixture
32+
def theine():
33+
return CAS("58-08-2")
34+
35+
36+
@pytest.fixture
37+
def l_lacticacid():
38+
return CAS(79_33_4)
39+
40+
41+
@pytest.fixture
42+
def d_lacticacid():
43+
return CAS("10326-41-7")
44+
45+
46+
# Tests for functionality
47+
48+
49+
def test_cas_check_digit(caffeine):
50+
assert caffeine.check_digit == 2
51+
52+
53+
def test_cas_check_digit_print(caffeine):
54+
assert caffeine.check_digit
55+
56+
57+
def test_cas_check_digit(caffeine):
58+
assert str(caffeine) == "58-08-2"
59+
60+
61+
def test_cas_equal(caffeine, theine):
62+
assert caffeine == theine
63+
64+
65+
def test_cas_lesser_than(l_lacticacid, d_lacticacid):
66+
assert l_lacticacid < d_lacticacid
67+
68+
69+
def test_cas_format_string(caffeine):
70+
assert f"{caffeine:0>12}"
71+
72+
73+
def test_for_sorting(octanes, octanes_sorted):
74+
assert sorted(octanes) == octanes_sorted
75+
76+
77+
# Tests for error handling
78+
79+
80+
@pytest.mark.xfail(raises=TypeError)
81+
def test_cas_invalid_input():
82+
CAS(6417.5)
83+
84+
85+
@pytest.mark.xfail(raises=ValueError)
86+
def test_cas_format_unreadable():
87+
CAS("64 - 17 - 5")
88+
89+
90+
@pytest.mark.xfail(raises=ValueError)
91+
def test_cas_range_error():
92+
CAS(100)
93+
94+
95+
@pytest.mark.xfail(raises=ValueError)
96+
def test_cas_check_digit_error():
97+
CAS("64-17-6")

0 commit comments

Comments
 (0)