diff --git a/numba_dppy/tests/test_controllable_fallback.py b/numba_dppy/tests/test_controllable_fallback.py index 6a722d2d72..4565b801ca 100644 --- a/numba_dppy/tests/test_controllable_fallback.py +++ b/numba_dppy/tests/test_controllable_fallback.py @@ -3,8 +3,8 @@ import numba import numba_dppy from numba_dppy.testing import unittest -from numba.tests.support import captured_stderr import dpctl +import warnings @unittest.skipUnless(dpctl.has_gpu_queues(), "test only on GPU system") @@ -24,7 +24,7 @@ def inner_call_fallback(): return a numba_dppy.compiler.DEBUG = 1 - with captured_stderr() as msg_fallback_true: + with warnings.catch_warnings(record=True) as w: with dpctl.device_context("opencl:gpu") as gpu_queue: dppy = numba.njit(parallel=True)(inner_call_fallback) dppy_fallback_true = dppy() @@ -33,9 +33,7 @@ def inner_call_fallback(): numba_dppy.compiler.DEBUG = 0 np.testing.assert_array_equal(dppy_fallback_true, ref_result) - self.assertTrue( - "Failed to lower parfor on DPPY-device" in msg_fallback_true.getvalue() - ) + self.assertIn("Failed to lower parfor on DPPY-device", str(w[-1].message)) @unittest.expectedFailure def test_dppy_fallback_false(self): @@ -55,7 +53,7 @@ def inner_call_fallback(): try: numba_dppy.compiler.DEBUG = 1 numba_dppy.config.FALLBACK_ON_CPU = 0 - with captured_stderr() as msg_fallback_true: + with warnings.catch_warnings(record=True) as w: with dpctl.device_context("opencl:gpu") as gpu_queue: dppy = numba.njit(parallel=True)(inner_call_fallback) dppy_fallback_false = dppy() @@ -66,8 +64,8 @@ def inner_call_fallback(): numba_dppy.compiler.DEBUG = 0 not np.testing.assert_array_equal(dppy_fallback_false, ref_result) - not self.assertTrue( - "Failed to lower parfor on DPPY-device" in msg_fallback_true.getvalue() + self.assertNotIn( + "Failed to lower parfor on DPPY-device", str(w[-1].message) ) diff --git a/numba_dppy/tests/test_dppy_fallback.py b/numba_dppy/tests/test_dppy_fallback.py index 3ebad7aed9..b68ea54512 100644 --- a/numba_dppy/tests/test_dppy_fallback.py +++ b/numba_dppy/tests/test_dppy_fallback.py @@ -2,8 +2,8 @@ import numba import unittest -from numba.tests.support import captured_stderr import dpctl +import warnings @unittest.skipUnless(dpctl.has_gpu_queues(), "test only on GPU system") @@ -22,14 +22,16 @@ def inner_call_fallback(): return a - with captured_stderr() as msg, dpctl.device_context("opencl:gpu"): + with warnings.catch_warnings(record=True) as w, dpctl.device_context( + "opencl:gpu" + ): dppy = numba.njit(inner_call_fallback) dppy_result = dppy() ref_result = inner_call_fallback() np.testing.assert_array_equal(dppy_result, ref_result) - self.assertTrue("Failed to lower parfor on DPPY-device" in msg.getvalue()) + self.assertIn("Failed to lower parfor on DPPY-device", str(w[-1].message)) def test_dppy_fallback_reductions(self): def reduction(a): @@ -39,14 +41,16 @@ def reduction(a): return b a = np.ones(10) - with captured_stderr() as msg, dpctl.device_context("opencl:gpu"): + with warnings.catch_warnings(record=True) as w, dpctl.device_context( + "opencl:gpu" + ): dppy = numba.njit(reduction) dppy_result = dppy(a) ref_result = reduction(a) np.testing.assert_array_equal(dppy_result, ref_result) - self.assertTrue("Failed to lower parfor on DPPY-device" in msg.getvalue()) + self.assertIn("Failed to lower parfor on DPPY-device", str(w[-1].message)) if __name__ == "__main__": diff --git a/numba_dppy/tests/test_math_functions.py b/numba_dppy/tests/test_math_functions.py index e09202c6a3..73b92951db 100644 --- a/numba_dppy/tests/test_math_functions.py +++ b/numba_dppy/tests/test_math_functions.py @@ -61,7 +61,7 @@ def driver(a, jitfunc): return b -def test_driver(input_arr, device_ty, jitfunc): +def check_driver(input_arr, device_ty, jitfunc): out_actual = None if device_ty == "GPU": with dpctl.device_context("opencl:gpu") as gpu_queue: @@ -79,32 +79,32 @@ def test_driver(input_arr, device_ty, jitfunc): @unittest.skipUnless(dpctl.has_cpu_queues(), "test only on CPU system") class TestDPPYMathFunctionsCPU(unittest.TestCase): def test_fabs_cpu(self): - b_actual = test_driver(a, "CPU", dppy_fabs) + b_actual = check_driver(a, "CPU", dppy_fabs) b_expected = np.fabs(a) self.assertTrue(np.all(b_actual == b_expected)) def test_sin_cpu(self): - b_actual = test_driver(a, "CPU", dppy_sin) + b_actual = check_driver(a, "CPU", dppy_sin) b_expected = np.sin(a) self.assertTrue(np.allclose(b_actual, b_expected)) def test_cos_cpu(self): - b_actual = test_driver(a, "CPU", dppy_cos) + b_actual = check_driver(a, "CPU", dppy_cos) b_expected = np.cos(a) self.assertTrue(np.allclose(b_actual, b_expected)) def test_exp_cpu(self): - b_actual = test_driver(a, "CPU", dppy_exp) + b_actual = check_driver(a, "CPU", dppy_exp) b_expected = np.exp(a) self.assertTrue(np.allclose(b_actual, b_expected)) def test_sqrt_cpu(self): - b_actual = test_driver(a, "CPU", dppy_sqrt) + b_actual = check_driver(a, "CPU", dppy_sqrt) b_expected = np.sqrt(a) self.assertTrue(np.allclose(b_actual, b_expected)) def test_log_cpu(self): - b_actual = test_driver(a, "CPU", dppy_log) + b_actual = check_driver(a, "CPU", dppy_log) b_expected = np.log(a) self.assertTrue(np.allclose(b_actual, b_expected)) @@ -112,32 +112,32 @@ def test_log_cpu(self): @unittest.skipUnless(dpctl.has_gpu_queues(), "test only on GPU system") class TestDPPYMathFunctionsGPU(unittest.TestCase): def test_fabs_gpu(self): - b_actual = test_driver(a, "GPU", dppy_fabs) + b_actual = check_driver(a, "GPU", dppy_fabs) b_expected = np.fabs(a) self.assertTrue(np.all(b_actual == b_expected)) def test_sin_gpu(self): - b_actual = test_driver(a, "GPU", dppy_sin) + b_actual = check_driver(a, "GPU", dppy_sin) b_expected = np.sin(a) self.assertTrue(np.allclose(b_actual, b_expected)) def test_cos_gpu(self): - b_actual = test_driver(a, "GPU", dppy_cos) + b_actual = check_driver(a, "GPU", dppy_cos) b_expected = np.cos(a) self.assertTrue(np.allclose(b_actual, b_expected)) def test_exp_gpu(self): - b_actual = test_driver(a, "GPU", dppy_exp) + b_actual = check_driver(a, "GPU", dppy_exp) b_expected = np.exp(a) self.assertTrue(np.allclose(b_actual, b_expected)) def test_sqrt_gpu(self): - b_actual = test_driver(a, "GPU", dppy_sqrt) + b_actual = check_driver(a, "GPU", dppy_sqrt) b_expected = np.sqrt(a) self.assertTrue(np.allclose(b_actual, b_expected)) def test_log_gpu(self): - b_actual = test_driver(a, "GPU", dppy_log) + b_actual = check_driver(a, "GPU", dppy_log) b_expected = np.log(a) self.assertTrue(np.allclose(b_actual, b_expected))