Skip to content

Commit cd362aa

Browse files
committed
FIX: Context
1 parent a1ddae8 commit cd362aa

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

nibabel/tests/test_floating.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
"""Test floating point deconstructions and floor methods
22
"""
33
import sys
4+
from contextlib import nullcontext
45

56
import numpy as np
67
import pytest
8+
from packaging.version import Version
79

810
from ..casting import (
911
FloatingError,
@@ -27,6 +29,8 @@
2729

2830
LD_INFO = type_info(np.longdouble)
2931

32+
FP_OVERFLOW_WARN = Version(np.__version__) <= Version('2.0.0.dev0')
33+
3034

3135
def dtt2dict(dtt):
3236
"""Create info dictionary from numpy type"""
@@ -149,9 +153,14 @@ def test_as_int():
149153
nexp64 = floor_log2(type_info(np.float64)['max'])
150154
with np.errstate(over='ignore'):
151155
val = np.longdouble(2**nexp64) * 2 # outside float64 range
152-
with pytest.raises(OverflowError):
156+
assert val > np.finfo('float64').max
157+
if FP_OVERFLOW_WARN:
158+
ctx = pytest.raises(OverflowError)
159+
else:
160+
ctx = nullcontext()
161+
with ctx:
153162
as_int(val)
154-
with pytest.raises(OverflowError):
163+
with ctx:
155164
as_int(-val)
156165

157166

0 commit comments

Comments
 (0)