8000 BUG: Fix test_1d_format test. · numpy/numpy@50cdfdd · GitHub
[go: up one dir, main page]

Skip to content

Commit 50cdfdd

Browse files
committed
BUG: Fix test_1d_format test.
The test failed for numpy installed in release mode as the PendingDeprecationWarning issued by `object.__format__(a, '30')` was no longer converted to an error. The fix here is to make the test Python version dependent and suppress the warning when needed.
1 parent 5c16f53 commit 50cdfdd

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

numpy/core/tests/test_multiarray.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7086,21 +7086,14 @@ def test_1d_no_format(self):
70867086
def test_1d_format(self):
70877087
# until gh-5543, ensure that the behaviour matches what it used to be
70887088
a = np.array([np.pi])
7089-
7090-
def ret_and_exc(f, *args, **kwargs):
7091-
try:
7092-
return f(*args, **kwargs), None
7093-
except Exception as e:
7094-
# exceptions don't compare equal, so return type and args
7095-
# which do
7096-
return None, (type(e), e.args)
7097-
7098-
# Could switch on python version here, but all we care about is
7099-
# that the behaviour hasn't changed
7100-
assert_equal(
7101-
ret_and_exc(object.__format__, a, '30'),
7102-
ret_and_exc('{:30}'.format, a)
7103-
)
7089+
if sys.version_info[:2] >= (3, 4):
7090+
assert_raises(TypeError, '{:30}'.format, a)
7091+
else:
7092+
with suppress_warnings() as sup:
7093+
sup.filter(PendingDeprecationWarning)
7094+
res = '{:30}'.format(a)
7095+
dst = object.__format__(a, '30')
7096+
assert_equal(res, dst)
71047097

71057098

71067099
class TestCTypes(object):

0 commit comments

Comments
 (0)
0