8000 TST: add broadcast_arrays() kwarg unit test for TypeError · numpy/numpy@81bd37e · GitHub
[go: up one dir, main page]

Skip to content

Commit 81bd37e

Browse files
committed
TST: add broadcast_arrays() kwarg unit test for TypeError
* broadcast_arrays() is now tested for the case when an invalid keyword argument is used; the appropriate error string content is also tested for * the TypeError message produced in the above case has been restored to the correct value in Python 3
1 parent 6105281 commit 81bd37e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

numpy/lib/stride_tricks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def broadcast_arrays(*args, **kwargs):
242242
subok = kwargs.pop('subok', False)
243243
if kwargs:
244244
raise TypeError('broadcast_arrays() got an unexpected keyword '
245-
'argument {!r}'.format(kwargs.keys()[0]))
245+
'argument {!r}'.format(list(kwargs.keys())[0]))
246246
args = [np.array(_m, copy=False, subok=subok) for _m in args]
247247

248248
shape = _broadcast_shape(*args)

numpy/lib/tests/test_stride_tricks.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import numpy as np
44
from numpy.core._rational_tests import rational
55
from numpy.testing import (
6-
assert_equal, assert_array_equal, assert_raises, assert_
6+
assert_equal, assert_array_equal, assert_raises, assert_,
7+
assert_raises_regex
78
)
89
from numpy.lib.stride_tricks import (
910
as_strided, broadcast_arrays, _broadcast_shape, broadcast_to
@@ -57,6 +58,17 @@ def test_same():
5758
assert_array_equal(x, bx)
5859
assert_array_equal(y, by)
5960

61+
def test_broadcast_kwargs():
62+
# ensure that a TypeError is appropriately raised when
63+
# np.broadcast_arrays() is called with any keyword
64+
# argument other than 'subok'
65+
x = np.arange(10)
66+
y = np.arange(10)
67+
68+
with assert_raises_regex(TypeError,
69+
'broadcast_arrays\\(\\) got an unexpected keyword*'):
70+
broadcast_arrays(x, y, dtype='float64')
71+
6072

6173
def test_one_off():
6274
x = np.array([[1, 2, 3]])

0 commit comments

Comments
 (0)
0