|
| 1 | +import operator |
| 2 | + |
| 3 | +import numpy as np |
| 4 | +import pytest |
| 5 | + |
| 6 | +from pandas._libs import ops |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture(name="int_max") |
| 10 | +def fixture_int_max() -> int: |
| 11 | + return np.iinfo(np.int64).max |
| 12 | + |
| 13 | + |
| 14 | +@pytest.fixture(name="int_min") |
| 15 | +def fixture_int_min() -> int: |
| 16 | + return np.iinfo(np.int64).min |
| 17 | + |
| 18 | + |
| 19 | +@pytest.fixture(name="overflow_msg") |
| 20 | +def fixture_overflow_msg() -> str: |
| 21 | + return "Python int too large to convert to C long" |
| 22 | + |
| 23 | + |
| 24 | +def test_raises_for_too_large_arg(int_max: int, overflow_msg: str): |
| 25 | + with pytest.raises(OverflowError, match=overflow_msg): |
| 26 | + ops.calculate(operator.add, int_max + 1, 1) |
| 27 | + |
| 28 | + with pytest.raises(OverflowError, match=overflow_msg): |
| 29 | + ops.calculate(operator.add, 1, int_max + 1) |
| 30 | + |
| 31 | + |
| 32 | +def test_raises_for_too_small_arg(int_min: int, overflow_msg: str): |
| 33 | + with pytest.raises(OverflowError, match=overflow_msg): |
| 34 | + ops.calculate(operator.add, int_min - 1, 1) |
| 35 | + |
| 36 | + with pytest.raises(OverflowError, match=overflow_msg): |
| 37 | + ops.calculate(operator.add, 1, int_min - 1) |
| 38 | + |
| 39 | + |
| 40 | +def test_raises_for_too_large_result(int_max: int, overflow_msg: str): |
| 41 | + with pytest.raises(OverflowError, match=overflow_msg): |
| 42 | + ops.calculate(operator.add, int_max, 1) |
| 43 | + |
| 44 | + with pytest.raises(OverflowError, match=overflow_msg): |
| 45 | + ops.calculate(operator.add, 1, int_max) |
| 46 | + |
| 47 | + |
| 48 | +def test_raises_for_too_small_result(int_min: int, overflow_msg: str): |
| 49 | + with pytest.raises(OverflowError, match=overflow_msg): |
| 50 | + ops.calculate(operator.sub, int_min, 1) |
| 51 | + |
| 52 | + with pytest.raises(OverflowError, match=overflow_msg): |
| 53 | + ops.calculate(operator.sub, 1, int_min) |
0 commit comments