From 8ba8841e4addae00a5a7e1ea9acc5987db452d2a Mon Sep 17 00:00:00 2001 From: Ganesh Kathiresan Date: Sat, 12 Jun 2021 19:38:59 +0530 Subject: TST: Check invalid dtypes comparison --- numpy/core/tests/test_dtype.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py index 8a6b7dcd5..3a43bba68 100644 --- a/numpy/core/tests/test_dtype.py +++ b/numpy/core/tests/test_dtype.py @@ -88,6 +88,19 @@ 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): + # Make sure objects that cannot be converted to valid + # dtypes results in False 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}" + @pytest.mark.parametrize("dtype", ['Bool', 'Complex32', 'Complex64', 'Float16', 'Float32', 'Float64', 'Int8', 'Int16', 'Int32', 'Int64', 'Object0', 'Timedelta64', -- cgit v1.2.1