|
| 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