summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_index_tricks.py
diff options
context:
space:
mode:
authorTyler Reddy <tyler.je.reddy@gmail.com>2018-10-10 14:58:42 -0700
committerTyler Reddy <tyler.je.reddy@gmail.com>2018-10-10 14:58:42 -0700
commita3bb6fc35e1ce41df94847decda38bf4742cc514 (patch)
tree0a0e74a22ea83c1666b0453ced84c3b5b6132ea4 /numpy/lib/tests/test_index_tricks.py
parent2ed08ba2ec29a8ef5fb60fa1a17a3d9366ae6c5d (diff)
downloadnumpy-a3bb6fc35e1ce41df94847decda38bf4742cc514.tar.gz
TST: error tests for diag_indices_from()
* add unit tests for previously uncovered error handling code in diag_indices_from()
Diffstat (limited to 'numpy/lib/tests/test_index_tricks.py')
-rw-r--r--numpy/lib/tests/test_index_tricks.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/numpy/lib/tests/test_index_tricks.py b/numpy/lib/tests/test_index_tricks.py
index 33b98629d..aa3c7b8a4 100644
--- a/numpy/lib/tests/test_index_tricks.py
+++ b/numpy/lib/tests/test_index_tricks.py
@@ -365,11 +365,23 @@ def test_diag_indices():
)
-def test_diag_indices_from():
- x = np.random.random((4, 4))
- r, c = diag_indices_from(x)
- assert_array_equal(r, np.arange(4))
- assert_array_equal(c, np.arange(4))
+class TestDiagIndicesFrom(object):
+
+ def test_diag_indices_from(self):
+ x = np.random.random((4, 4))
+ r, c = diag_indices_from(x)
+ assert_array_equal(r, np.arange(4))
+ assert_array_equal(c, np.arange(4))
+
+ def test_error_small_input(self):
+ x = np.ones(7)
+ with assert_raises_regex(ValueError, "at least 2-d"):
+ diag_indices_from(x)
+
+ def test_error_shape_mismatch(self):
+ x = np.zeros((3, 3, 2, 3), int)
+ with assert_raises_regex(ValueError, "equal length"):
+ diag_indices_from(x)
def test_ndindex():