From 2d6d6245b2157d32406a1ad43024d4a0f064f6eb Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 11 Jan 2018 17:06:32 -0600 Subject: [PATCH 1/3] pytest_generate_tests_for_pyopencl(): Remove use of deprecated method Metafunc.addcall(), in favor of Metafunc.parametrize(). --- pyopencl/tools.py | 64 +++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/pyopencl/tools.py b/pyopencl/tools.py index 6a72ee97..7304cfc7 100644 --- a/pyopencl/tools.py +++ b/pyopencl/tools.py @@ -249,38 +249,38 @@ def pytest_generate_tests_for_pyopencl(metafunc): test_plat_and_dev = get_test_platforms_and_devices() - if ("device" in metafunc.funcargnames - or "ctx_factory" in metafunc.funcargnames - or "ctx_getter" in metafunc.funcargnames): - arg_dict = {} - - for platform, plat_devs in test_plat_and_dev: - if "platform" in metafunc.funcargnames: - arg_dict["platform"] = platform - - for device in plat_devs: - if "device" in metafunc.funcargnames: - arg_dict["device"] = device - - if "ctx_factory" in metafunc.funcargnames: - arg_dict["ctx_factory"] = ContextFactory(device) - - if "ctx_getter" in metafunc.funcargnames: - from warnings import warn - warn("The 'ctx_getter' arg is deprecated in " - "favor of 'ctx_factory'.", - DeprecationWarning) - arg_dict["ctx_getter"] = ContextFactory(device) - - metafunc.addcall(funcargs=arg_dict.copy(), - id=", ".join("%s=%s" % (arg, value) - for arg, value in six.iteritems(arg_dict))) - - elif "platform" in metafunc.funcargnames: - for platform, plat_devs in test_plat_and_dev: - metafunc.addcall( - funcargs=dict(platform=platform), - id=str(platform)) + arg_names = [] + + for arg in ("platform", "device", "ctx_factory", "ctx_getter"): + if arg not in metafunc.funcargnames: + continue + + if arg == "ctx_getter": + from warnings import warn + warn("The 'ctx_getter' arg is deprecated in " + "favor of 'ctx_factory'.", + DeprecationWarning) + + arg_names.append(arg) + + arg_values = [] + + for platform, plat_devs in test_plat_and_dev: + if arg_names == ["platform"]: + arg_values.append((platform,)) + continue + + arg_dict = {"platform": platform} + + for device in plat_devs: + arg_dict["device"] = device + arg_dict["ctx_factory"] = ContextFactory(device) + arg_dict["ctx_getter"] = ContextFactory(device) + + arg_values.append(tuple(arg_dict[name] for name in arg_names)) + + if arg_names: + metafunc.parametrize(arg_names, arg_values, ids=str) # {{{ C argument lists -- GitLab From 93c6398408c9fbb4e3a8b251b7f440fb88beceae Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 11 Jan 2018 17:29:24 -0600 Subject: [PATCH 2/3] Add NORMALIZE_WHITESPACE option to a failing doctest --- doc/howto.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/howto.rst b/doc/howto.rst index 92244c43..3f1c5b05 100644 --- a/doc/howto.rst +++ b/doc/howto.rst @@ -64,7 +64,7 @@ the device: >>> ary_host["field1"].fill(217) >>> ary_host["field2"].fill(1000) >>> ary_host[13]["field2"] = 12 - >>> print(ary_host) + >>> print(ary_host) #doctest: +NORMALIZE_WHITESPACE [(217, 1000.) (217, 1000.) (217, 1000.) (217, 1000.) (217, 1000.) (217, 1000.) (217, 1000.) (217, 1000.) (217, 1000.) (217, 1000.) (217, 1000.) (217, 1000.) (217, 1000.) (217, 12.) (217, 1000.) @@ -98,7 +98,7 @@ as well as with PyOpenCL's built-in operations: >>> elwise = ElementwiseKernel(ctx, "my_struct *a", "a[i].field1 = 2;", ... preamble=my_struct_c_decl) >>> evt = elwise(ary) - >>> print(ary) + >>> print(ary) #doctest: +NORMALIZE_WHITESPACE [(2, 1000.) (2, 1000.) (2, 1000.) (2, 1000.) (2, 1000.) (2, 1000.) (2, 1000.) (2, 1000.) (2, 1000.) (2, 1000.) (2, 1000.) (2, 1000.) (2, 1000.) (2, 12.) (2, 1000.) (2, 1000.) (2, 1000.) (2, 1000.) -- GitLab From aa8311f297306741e5a9d4fff40b26dc26b96d8e Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 11 Jan 2018 17:41:42 -0600 Subject: [PATCH 3/3] Add NORMALIZE_WHITESPACE to another spot --- doc/howto.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/howto.rst b/doc/howto.rst index 3f1c5b05..5c5b04d2 100644 --- a/doc/howto.rst +++ b/doc/howto.rst @@ -84,7 +84,7 @@ We can then operate on the array with our own kernels: ... """).build() >>> evt = prg.set_to_1(queue, ary.shape, None, ary.data) - >>> print(ary) + >>> print(ary) #doctest: +NORMALIZE_WHITESPACE [(1, 1000.) (1, 1000.) (1, 1000.) (1, 1000.) (1, 1000.) (1, 1000.) (1, 1000.) (1, 1000.) (1, 1000.) (1, 1000.) (1, 1000.) (1, 1000.) (1, 1000.) (1, 12.) (1, 1000.) (1, 1000.) (1, 1000.) (1, 1000.) -- GitLab