diff options
| -rw-r--r-- | numpy/core/tests/test_dtype.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py index 3a43bba68..3d15009ea 100644 --- a/numpy/core/tests/test_dtype.py +++ b/numpy/core/tests/test_dtype.py @@ -88,18 +88,23 @@ class TestBuiltin: assert_raises(TypeError, np.dtype, 'q8') assert_raises(TypeError, np.dtype, 'Q8') - @pytest.mark.parametrize( - ['operator', 'expected'], - [('==', False), ('!=', True), - ('>', False), ('<', False), - ('>=', False), ('<=', False)]) - def test_richcompare_invalid_dtype(self, operator, expected): + def test_richcompare_invalid_dtype_equality(self): # Make sure objects that cannot be converted to valid - # dtypes results in False when compared to valid dtypes. + # dtypes results in False/True when compared to valid dtypes. # Here 7 cannot be converted to dtype. No exceptions should be raised - assert eval(f"np.dtype(np.int32) {operator} 7") == expected,\ - f"dtype richcompare failed for {operator}" + assert not np.dtype(np.int32) == 7, "dtype richcompare failed for ==" + assert np.dtype(np.int32) != 7, "dtype richcompare failed for !=" + + @pytest.mark.parametrize( + 'operation', + [operator.le, operator.lt, operator.ge, operator.gt]) + def test_richcompare_invalid_dtype_comparison(self, operation): + # Make sure TypeError is raised for comparison operators + # for invalid dtypes. Here 7 is an invalid dtype. + + with pytest.raises(TypeError): + operation(np.dtype(np.int32), 7) @pytest.mark.parametrize("dtype", ['Bool', 'Complex32', 'Complex64', 'Float16', 'Float32', 'Float64', |
