diff --git a/dpnp/tests/test_binary_ufuncs.py b/dpnp/tests/test_binary_ufuncs.py index 5af97d22ef60..4823b5a1cd9a 100644 --- a/dpnp/tests/test_binary_ufuncs.py +++ b/dpnp/tests/test_binary_ufuncs.py @@ -128,12 +128,15 @@ def test_invalid_shape(self, shape): with pytest.raises(ValueError): dpnp.add(a, b, out=out) - @pytest.mark.parametrize("out", [4, (), [], (3, 7), [2, 4]]) - def test_invalid_out(self, out): - a = dpnp.arange(10) - - assert_raises(TypeError, dpnp.add, a, 2, out) - assert_raises(TypeError, numpy.add, a.asnumpy(), 2, out) + @pytest.mark.parametrize("xp", [dpnp, numpy]) + @pytest.mark.parametrize( + "out", + [4, (), [], (3, 7), [2, 4]], + ids=["scalar", "empty_tuple", "empty_list", "tuple", "list"], + ) + def test_invalid_out(self, xp, out): + a = xp.arange(10) + assert_raises(TypeError, xp.add, a, 2, out) class TestBoundFuncs: @@ -194,13 +197,16 @@ def test_invalid_shape(self, func_params, shape): with pytest.raises(ValueError): getattr(dpnp, func_name)(a, b, out=out) - @pytest.mark.parametrize("out", [4, (), [], (3, 7), [2, 4]]) - def test_invalid_out(self, func_params, out): + @pytest.mark.parametrize("xp", [dpnp, numpy]) + @pytest.mark.parametrize( + "out", + [4, (), [], (3, 7), [2, 4]], + ids=["scalar", "empty_tuple", "empty_list", "tuple", "list"], + ) + def test_invalid_out(self, func_params, xp, out): func_name = func_params["func_name"] - a = dpnp.arange(10) - - assert_raises(TypeError, getattr(dpnp, func_name), a, 2, out) - assert_raises(TypeError, getattr(numpy, func_name), a.asnumpy(), 2, out) + a = xp.arange(10) + assert_raises(TypeError, getattr(xp, func_name), a, 2, out) class TestDivide: @@ -288,12 +294,15 @@ def test_invalid_shape(self, shape): with pytest.raises(ValueError): dpnp.divide(a, b, out=out) - @pytest.mark.parametrize("out", [4, (), [], (3, 7), [2, 4]]) - def test_invalid_out(self, out): - a = dpnp.arange(10) - - assert_raises(TypeError, dpnp.divide, a, 2, out) - assert_raises(TypeError, numpy.divide, a.asnumpy(), 2, out) + @pytest.mark.parametrize("xp", [dpnp, numpy]) + @pytest.mark.parametrize( + "out", + [4, (), [], (3, 7), [2, 4]], + ids=["scalar", "empty_tuple", "empty_list", "tuple", "list"], + ) + def test_invalid_out(self, xp, out): + a = xp.arange(10) + assert_raises(TypeError, xp.divide, a, 2, out) @pytest.mark.parametrize("func", ["floor_divide", "remainder"]) @@ -378,12 +387,15 @@ def test_invalid_shape(self, func, shape): with pytest.raises(ValueError): getattr(dpnp, func)(a, b, out=out) - @pytest.mark.parametrize("out", [4, (), [], (3, 7), [2, 4]]) - def test_invalid_out(self, func, out): - a = dpnp.arange(10) - - assert_raises(TypeError, getattr(dpnp, func), a, 2, out) - assert_raises(TypeError, getattr(numpy, func), a.asnumpy(), 2, out) + @pytest.mark.parametrize("xp", [dpnp, numpy]) + @pytest.mark.parametrize( + "out", + [4, (), [], (3, 7), [2, 4]], + ids=["scalar", "empty_tuple", "empty_list", "tuple", "list"], + ) + def test_invalid_out(self, func, xp, out): + a = xp.arange(10) + assert_raises(TypeError, getattr(xp, func), a, 2, out) class TestFmaxFmin: @@ -659,12 +671,15 @@ def test_invalid_shape(self, shape): with pytest.raises(ValueError): dpnp.multiply(a, b, out=out) - @pytest.mark.parametrize("out", [4, (), [], (3, 7), [2, 4]]) - def test_invalid_out(self, out): - a = dpnp.arange(10) - - assert_raises(TypeError, dpnp.multiply, a, 2, out) - assert_raises(TypeError, numpy.multiply, a.asnumpy(), 2, out) + @pytest.mark.parametrize("xp", [dpnp, numpy]) + @pytest.mark.parametrize( + "out", + [4, (), [], (3, 7), [2, 4]], + ids=["scalar", "empty_tuple", "empty_list", "tuple", "list"], + ) + def test_invalid_out(self, xp, out): + a = xp.arange(10) + assert_raises(TypeError, xp.multiply, a, 2, out) class TestNextafter: @@ -911,12 +926,15 @@ def test_invalid_shape(self, shape): with pytest.raises(ValueError): dpnp.power(a, b, out=out) - @pytest.mark.parametrize("out", [4, (), [], (3, 7), [2, 4]]) - def test_invalid_out(self, out): - a = dpnp.arange(10) - - assert_raises(TypeError, dpnp.power, a, 2, out) - assert_raises(TypeError, numpy.power, a.asnumpy(), 2, out) + @pytest.mark.parametrize("xp", [dpnp, numpy]) + @pytest.mark.parametrize( + "out", + [4, (), [], (3, 7), [2, 4]], + ids=["scalar", "empty_tuple", "empty_list", "tuple", "list"], + ) + def test_invalid_out(self, xp, out): + a = xp.arange(10) + assert_raises(TypeError, xp.power, a, 2, out) @pytest.mark.usefixtures("suppress_invalid_numpy_warnings") def test_complex_values(self): @@ -1124,9 +1142,12 @@ def test_invalid_shape(self, shape): with pytest.raises(ValueError): dpnp.subtract(a, b, out=out) - @pytest.mark.parametrize("out", [4, (), [], (3, 7), [2, 4]]) - def test_invalid_out(self, out): - a = dpnp.arange(10) - - assert_raises(TypeError, dpnp.subtract, a, 2, out) - assert_raises(TypeError, numpy.subtract, a.asnumpy(), 2, out) + @pytest.mark.parametrize("xp", [dpnp, numpy]) + @pytest.mark.parametrize( + "out", + [4, (), [], (3, 7), [2, 4]], + ids=["scalar", "empty_tuple", "empty_list", "tuple", "list"], + ) + def test_invalid_out(self, xp, out): + a = xp.arange(10) + assert_raises(TypeError, xp.subtract, a, 2, out) diff --git a/dpnp/tests/test_mathematical.py b/dpnp/tests/test_mathematical.py index 6fe2e70bb59d..d53be2fb4665 100644 --- a/dpnp/tests/test_mathematical.py +++ b/dpnp/tests/test_mathematical.py @@ -2518,16 +2518,15 @@ def test_invalid_shape(self, shape): with pytest.raises(ValueError): dpnp.hypot(dp_array1, dp_array2, out=dp_out) + @pytest.mark.parametrize("xp", [dpnp, numpy]) @pytest.mark.parametrize( "out", [4, (), [], (3, 7), [2, 4]], - ids=["4", "()", "[]", "(3, 7)", "[2, 4]"], + ids=["scalar", "empty_tuple", "empty_list", "tuple", "list"], ) - def test_invalid_out(self, out): - a = dpnp.arange(10) - - assert_raises(TypeError, dpnp.hypot, a, 2, out) - assert_raises(TypeError, numpy.hypot, a.asnumpy(), 2, out) + def test_invalid_out(self, xp, out): + a = xp.arange(10) + assert_raises(TypeError, xp.hypot, a, 2, out) class TestLogSumExp: diff --git a/dpnp/tests/test_umath.py b/dpnp/tests/test_umath.py index 94426ce4b5d1..75f0a7578d5c 100644 --- a/dpnp/tests/test_umath.py +++ b/dpnp/tests/test_umath.py @@ -659,16 +659,15 @@ def test_invalid_shape(self, shape): with pytest.raises(ValueError): dpnp.square(dp_array, out=dp_out) + @pytest.mark.parametrize("xp", [dpnp, numpy]) @pytest.mark.parametrize( "out", [4, (), [], (3, 7), [2, 4]], - ids=["4", "()", "[]", "(3, 7)", "[2, 4]"], + ids=["scalar", "empty_tuple", "empty_list", "tuple", "list"], ) - def test_invalid_out(self, out): - a = dpnp.arange(10) - - assert_raises(TypeError, dpnp.square, a, out) - assert_raises(TypeError, numpy.square, a.asnumpy(), out) + def test_invalid_out(self, xp, out): + a = xp.arange(10) + assert_raises(TypeError, xp.square, a, out) class TestUmath: @@ -759,16 +758,16 @@ def test_invalid_shape(self, func_params, shape): with pytest.raises(ValueError): getattr(dpnp, func_name)(dp_array, out=dp_out) + @pytest.mark.parametrize("xp", [dpnp, numpy]) @pytest.mark.parametrize( "out", [4, (), [], (3, 7), [2, 4]], - ids=["4", "()", "[]", "(3, 7)", "[2, 4]"], + ids=["scalar", "empty_tuple", "empty_list", "tuple", "list"], ) - def test_invalid_out(self, func_params, out): + def test_invalid_out(self, func_params, xp, out): func_name = func_params["func_name"] - a = dpnp.arange(10) - assert_raises(TypeError, getattr(dpnp, func_name), a, out) - assert_raises(TypeError, getattr(numpy, func_name), a.asnumpy(), out) + a = xp.arange(10) + assert_raises(TypeError, getattr(xp, func_name), a, out) def test_trigonometric_hyperbolic_aliases():