|
2 | 2 |
|
3 | 3 | from decimal import Decimal as PyDecimal |
4 | 4 |
|
| 5 | +import pytest |
| 6 | + |
5 | 7 | from stock_indicators._cstypes import Decimal as CsDecimal |
6 | 8 | from stock_indicators._cstypes.decimal import to_pydecimal, to_pydecimal_via_double |
7 | 9 |
|
@@ -136,36 +138,24 @@ def test_edge_cases_conversion_comparison(self): |
136 | 138 | ] |
137 | 139 |
|
138 | 140 | for py_decimal in test_values: |
139 | | - try: |
140 | | - cs_decimal = CsDecimal(py_decimal) |
141 | | - |
142 | | - string_result = to_pydecimal(cs_decimal) |
143 | | - double_result = to_pydecimal_via_double(cs_decimal) |
| 141 | + cs_decimal = CsDecimal(py_decimal) |
144 | 142 |
|
145 | | - print(f"Testing edge case {py_decimal}:") |
146 | | - print(f" String method: {string_result}") |
147 | | - print(f" Double method: {double_result}") |
| 143 | + string_result = to_pydecimal(cs_decimal) |
| 144 | + double_result = to_pydecimal_via_double(cs_decimal) |
148 | 145 |
|
149 | | - if string_result != double_result: |
150 | | - print(f" Difference: {abs(string_result - double_result)}") |
| 146 | + print(f"Testing edge case {py_decimal}:") |
| 147 | + print(f" String method: {string_result}") |
| 148 | + print(f" Double method: {double_result}") |
151 | 149 |
|
152 | | - if string_result is not None and double_result is not None: |
153 | | - assert string_result is not None |
154 | | - assert double_result is not None |
| 150 | + if string_result != double_result: |
| 151 | + print(f" Difference: {abs(string_result - double_result)}") |
155 | 152 |
|
156 | | - except Exception as e: |
157 | | - assert False, str(e) |
| 153 | + assert string_result is not None and double_result is not None |
158 | 154 |
|
159 | 155 | def test_edge_case_infinity_raises(self): |
160 | 156 | """Test that infinity raises an exception.""" |
161 | | - try: |
162 | | - cs_decimal = CsDecimal(float("inf")) |
163 | | - to_pydecimal(cs_decimal) |
164 | | - to_pydecimal_via_double(cs_decimal) |
165 | | - assert False, "Expected exception for infinity was not raised" |
166 | | - except Exception: |
167 | | - # Exception is expected for infinity |
168 | | - pass |
| 157 | + with pytest.raises(ValueError, match=r"."): |
| 158 | + CsDecimal(float("inf")) |
169 | 159 |
|
170 | 160 | def test_none_input_handling(self): |
171 | 161 | """Test that both methods handle None input correctly.""" |
|
0 commit comments