From ba05a2de7a20c5c6ae3465d7764be1ad3c6822ed Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Tue, 22 Jan 2013 03:40:45 -0500
Subject: [PATCH] A few test fixes.

---
 doc/source/tools.rst   |  2 +-
 pyopencl/algorithm.py  |  5 ++++-
 test/test_algorithm.py | 43 ++++++++++++++++++++++++++++++++++++++++--
 test/test_array.py     |  6 ++----
 test/test_clmath.py    |  6 +++---
 test/test_wrapper.py   | 16 ++++++++--------
 6 files changed, 59 insertions(+), 19 deletions(-)

diff --git a/doc/source/tools.rst b/doc/source/tools.rst
index e8418912..47620252 100644
--- a/doc/source/tools.rst
+++ b/doc/source/tools.rst
@@ -117,7 +117,7 @@ Testing
         from pyopencl.tools import pytest_generate_tests_for_pyopencl \
                 as pytest_generate_tests
 
-    in your `py.test <http://pytest.org>`_ test scripts allows you to use the
+    in your `pytest <http://pytest.org>`_ test scripts allows you to use the
     arguments *ctx_factory*, *device*, or *platform* in your test functions,
     and they will automatically be run for each OpenCL device/platform in the
     system, as appropriate.
diff --git a/pyopencl/algorithm.py b/pyopencl/algorithm.py
index 88c297e1..40c358df 100644
--- a/pyopencl/algorithm.py
+++ b/pyopencl/algorithm.py
@@ -80,7 +80,10 @@ def copy_if(ary, predicate, extra_args=[], queue=None, preamble=""):
             more_preamble=preamble, more_arguments=extra_args_types)
     out = cl.array.empty_like(ary)
     count = ary._new_with_changes(data=None, shape=(), strides=(), dtype=scan_dtype)
-    knl(ary, out, count, *extra_args_values, queue=queue)
+
+    # **dict is a Py2.5 workaround
+    knl(ary, out, count, *extra_args_values, **dict(queue=queue))
+
     return out, count
 
 # }}}
diff --git a/test/test_algorithm.py b/test/test_algorithm.py
index 3d49b23f..0f7563c6 100644
--- a/test/test_algorithm.py
+++ b/test/test_algorithm.py
@@ -216,7 +216,7 @@ def test_astype(ctx_factory):
     from pyopencl.clrandom import rand as clrand
 
     if not has_double_support(context.devices[0]):
-        from py.test import skip
+        from pytest import skip
         skip("double precision not supported on %s" % context.devices[0])
 
     a_gpu = clrand(queue, (2000,), dtype=np.float32)
@@ -241,6 +241,9 @@ def test_astype(ctx_factory):
 
 @pytools.test.mark_test.opencl
 def test_sum(ctx_factory):
+    from pytest import importorskip
+    importorskip("mako")
+
     context = ctx_factory()
     queue = cl.CommandQueue(context)
 
@@ -258,6 +261,9 @@ def test_sum(ctx_factory):
 
 @pytools.test.mark_test.opencl
 def test_minmax(ctx_factory):
+    from pytest import importorskip
+    importorskip("mako")
+
     context = ctx_factory()
     queue = cl.CommandQueue(context)
 
@@ -281,6 +287,9 @@ def test_minmax(ctx_factory):
 
 @pytools.test.mark_test.opencl
 def test_subset_minmax(ctx_factory):
+    from pytest import importorskip
+    importorskip("mako")
+
     context = ctx_factory()
     queue = cl.CommandQueue(context)
 
@@ -321,6 +330,9 @@ def test_subset_minmax(ctx_factory):
 
 @pytools.test.mark_test.opencl
 def test_dot(ctx_factory):
+    from pytest import importorskip
+    importorskip("mako")
+
     context = ctx_factory()
     queue = cl.CommandQueue(context)
 
@@ -360,6 +372,9 @@ def make_mmc_dtype(device):
 
 @pytools.test.mark_test.opencl
 def test_struct_reduce(ctx_factory):
+    from pytest import importorskip
+    importorskip("mako")
+
     context = ctx_factory()
     queue = cl.CommandQueue(context)
 
@@ -418,6 +433,9 @@ def test_struct_reduce(ctx_factory):
 # {{{ scan-related
 
 def summarize_error(obtained, desired, orig, thresh=1e-5):
+    from pytest import importorskip
+    importorskip("mako")
+
     err = obtained - desired
     ok_count = 0
     bad_count = 0
@@ -475,6 +493,9 @@ scan_test_counts = [
 
 @pytools.test.mark_test.opencl
 def test_scan(ctx_factory):
+    from pytest import importorskip
+    importorskip("mako")
+
     context = ctx_factory()
     queue = cl.CommandQueue(context)
 
@@ -511,6 +532,9 @@ def test_scan(ctx_factory):
 
 @pytools.test.mark_test.opencl
 def test_copy_if(ctx_factory):
+    from pytest import importorskip
+    importorskip("mako")
+
     context = ctx_factory()
     queue = cl.CommandQueue(context)
 
@@ -578,6 +602,9 @@ def test_unique(ctx_factory):
 
 @pytools.test.mark_test.opencl
 def test_index_preservation(ctx_factory):
+    from pytest import importorskip
+    importorskip("mako")
+
     context = ctx_factory()
     queue = cl.CommandQueue(context)
 
@@ -608,6 +635,9 @@ def test_index_preservation(ctx_factory):
 
 @pytools.test.mark_test.opencl
 def test_segmented_scan(ctx_factory):
+    from pytest import importorskip
+    importorskip("mako")
+
     context = ctx_factory()
     queue = cl.CommandQueue(context)
 
@@ -702,6 +732,9 @@ def test_segmented_scan(ctx_factory):
 
 @pytools.test.mark_test.opencl
 def test_sort(ctx_factory):
+    from pytest import importorskip
+    importorskip("mako")
+
     context = ctx_factory()
     queue = cl.CommandQueue(context)
 
@@ -741,6 +774,9 @@ def test_sort(ctx_factory):
 
 @pytools.test.mark_test.opencl
 def test_list_builder(ctx_factory):
+    from pytest import importorskip
+    importorskip("mako")
+
     context = ctx_factory()
     queue = cl.CommandQueue(context)
 
@@ -764,6 +800,9 @@ def test_list_builder(ctx_factory):
 
 @pytools.test.mark_test.opencl
 def test_key_value_sorter(ctx_factory):
+    from pytest import importorskip
+    importorskip("mako")
+
     context = ctx_factory()
     queue = cl.CommandQueue(context)
 
@@ -804,7 +843,7 @@ if __name__ == "__main__":
     if len(sys.argv) > 1:
         exec(sys.argv[1])
     else:
-        from py.test.cmdline import main
+        from pytest.cmdline import main
         main([__file__])
 
 # vim: filetype=pyopencl:fdm=marker
diff --git a/test/test_array.py b/test/test_array.py
index 8e88f73d..c34c8752 100644
--- a/test/test_array.py
+++ b/test/test_array.py
@@ -174,7 +174,7 @@ def test_pow_neg1_vs_inv(ctx_factory):
 
     device = ctx.devices[0]
     if not has_double_support(device):
-        from py.test import skip
+        from pytest import skip
         skip("double precision not supported on %s" % device)
 
     a_dev = make_random_array(queue, np.complex128, 20000)
@@ -508,10 +508,8 @@ def test_mem_pool_with_arrays(ctx_factory):
     a_dev = cl_array.arange(queue, 2000, dtype=np.float32, allocator=mem_pool)
     b_dev = cl_array.to_device(queue, np.arange(2000), allocator=mem_pool) + 4000
 
-    result = cl_array.dot(a_dev, b_dev)
     assert a_dev.allocator is mem_pool
     assert b_dev.allocator is mem_pool
-    assert result.allocator is mem_pool
 
 @pytools.test.mark_test.opencl
 def test_view(ctx_factory):
@@ -569,7 +567,7 @@ if __name__ == "__main__":
     if len(sys.argv) > 1:
         exec(sys.argv[1])
     else:
-        from py.test.cmdline import main
+        from pytest.cmdline import main
         main([__file__])
 
 # vim: filetype=pyopencl:fdm=marker
diff --git a/test/test_clmath.py b/test/test_clmath.py
index 6ab66380..e502b051 100644
--- a/test/test_clmath.py
+++ b/test/test_clmath.py
@@ -206,7 +206,7 @@ def test_bessel(ctx_factory):
     try:
         import scipy.special as spec
     except ImportError:
-        from py.test import skip
+        from pytest import skip
         skip("scipy not present--cannot test Bessel function")
 
 
@@ -214,7 +214,7 @@ def test_bessel(ctx_factory):
     queue = cl.CommandQueue(ctx)
 
     if not has_double_support(ctx.devices[0]):
-        from py.test import skip
+        from pytest import skip
         skip("no double precision support--cannot test bessel function")
 
     nterms = 30
@@ -299,5 +299,5 @@ if __name__ == "__main__":
     if len(sys.argv) > 1:
         exec(sys.argv[1])
     else:
-        from py.test.cmdline import main
+        from pytest.cmdline import main
         main([__file__])
diff --git a/test/test_wrapper.py b/test/test_wrapper.py
index 56260557..0201b740 100644
--- a/test/test_wrapper.py
+++ b/test/test_wrapper.py
@@ -201,7 +201,7 @@ def test_nonempty_supported_image_formats(device, ctx_factory):
         assert len(cl.get_supported_image_formats(
                 context, cl.mem_flags.READ_ONLY, cl.mem_object_type.IMAGE2D)) > 0
     else:
-        from py.test import skip
+        from pytest import skip
         skip("images not supported on %s" % device.name)
 
 @pytools.test.mark_test.opencl
@@ -243,11 +243,11 @@ def test_image_2d(ctx_factory):
     device, = context.devices
 
     if not device.image_support:
-        from py.test import skip
+        from pytest import skip
         skip("images not supported on %s" % device)
 
     if "Intel" in device.vendor and "31360.31426" in device.version:
-        from py.test import skip
+        from pytest import skip
         skip("images crashy on %s" % device)
 
     prg = cl.Program(context, """
@@ -281,7 +281,7 @@ def test_image_2d(ctx_factory):
         import sys
         exc = sys.exc_info()[1]
         if exc.code == cl.status_code.IMAGE_FORMAT_NOT_SUPPORTED:
-            from py.test import skip
+            from pytest import skip
             skip("required image format not supported on %s" % device.name)
         else:
             raise
@@ -313,11 +313,11 @@ def test_image_3d(ctx_factory):
     device, = context.devices
 
     if not device.image_support:
-        from py.test import skip
+        from pytest import skip
         skip("images not supported on %s" % device)
 
     if device.platform.vendor == "Intel(R) Corporation":
-        from py.test import skip
+        from pytest import skip
         skip("images crashy on %s" % device)
 
     prg = cl.Program(context, """
@@ -352,7 +352,7 @@ def test_image_3d(ctx_factory):
         import sys
         exc = sys.exc_info()[1]
         if exc.code == cl.status_code.IMAGE_FORMAT_NOT_SUPPORTED:
-            from py.test import skip
+            from pytest import skip
             skip("required image format not supported on %s" % device.name)
         else:
             raise
@@ -516,5 +516,5 @@ if __name__ == "__main__":
     if len(sys.argv) > 1:
         exec(sys.argv[1])
     else:
-        from py.test.cmdline import main
+        from pytest.cmdline import main
         main([__file__])
-- 
GitLab