From d27613b73af1d4fcb6212103c5faa00c3f7b08ca Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 28 Jul 2019 16:34:30 -0500 Subject: [PATCH 1/5] Suggested style fixes for data fixtures --- setup.cfg | 3 ++- test.py | 36 +++++++++++++++++++++++++++--------- input.py => test_data.py | 4 +++- 3 files changed, 32 insertions(+), 11 deletions(-) rename input.py => test_data.py (99%) diff --git a/setup.cfg b/setup.cfg index f812af5..7963e68 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,3 +1,4 @@ [flake8] -ignore = E126,E127,E128,E123,E226,E241,E242,E265,N802,N803,N806,W503,E402,N814,W504,F401,F811 +ignore = E126,E127,E128,E123,E226,E241,E242,E265,N802,N803,N806,W503,E402,N814,W504 max-line-length=85 +per-file-ignores = test.py:F811 diff --git a/test.py b/test.py index 75fabad..543abaf 100644 --- a/test.py +++ b/test.py @@ -15,10 +15,12 @@ from pyopencl.tools import ( # noqa as pytest_generate_tests) import utilities as u -from input import data +from test_data import test_flux_data_fixture # noqa: F401 -def test_weno_flux_uniform_grid(ctx_factory, data): +def test_weno_flux_uniform_grid(ctx_factory, test_flux_data_fixture): + data = test_flux_data_fixture + prg = u.get_weno_program_with_root_kernel("weno_flux") queue = u.get_queue(ctx_factory) @@ -35,7 +37,9 @@ def test_weno_flux_uniform_grid(ctx_factory, data): u.compare_arrays(flux_dev.get(), data.weno_flux) -def test_consistent_part_uniform_grid(ctx_factory, data): +def test_consistent_part_uniform_grid(ctx_factory, test_flux_data_fixture): + data = test_flux_data_fixture + prg = u.get_weno_program_with_root_kernel("consistent_part") queue = u.get_queue(ctx_factory) @@ -48,7 +52,9 @@ def test_consistent_part_uniform_grid(ctx_factory, data): u.compare_arrays(consistent_dev.get(), data.consistent) -def test_dissipation_part_pos_uniform_grid(ctx_factory, data): +def test_dissipation_part_pos_uniform_grid(ctx_factory, test_flux_data_fixture): + data = test_flux_data_fixture + prg = u.get_weno_program_with_root_kernel("dissipation_part_pos") queue = u.get_queue(ctx_factory) @@ -63,7 +69,9 @@ def test_dissipation_part_pos_uniform_grid(ctx_factory, data): u.compare_arrays(dissipation_dev.get(), data.dissipation_pos) -def test_dissipation_part_neg_uniform_grid(ctx_factory, data): +def test_dissipation_part_neg_uniform_grid(ctx_factory, test_flux_data_fixture): + data = test_flux_data_fixture + prg = u.get_weno_program_with_root_kernel("dissipation_part_neg") queue = u.get_queue(ctx_factory) @@ -78,7 +86,9 @@ def test_dissipation_part_neg_uniform_grid(ctx_factory, data): u.compare_arrays(dissipation_dev.get(), data.dissipation_neg) -def test_weno_weights_pos_uniform_grid(ctx_factory, data): +def test_weno_weights_pos_uniform_grid(ctx_factory, test_flux_data_fixture): + data = test_flux_data_fixture + prg = u.get_weno_program_with_root_kernel("weno_weights_pos") queue = u.get_queue(ctx_factory) @@ -92,7 +102,9 @@ def test_weno_weights_pos_uniform_grid(ctx_factory, data): u.compare_arrays(weights_dev.get(), data.weno_weights_pos) -def test_weno_weights_neg_uniform_grid(ctx_factory, data): +def test_weno_weights_neg_uniform_grid(ctx_factory, test_flux_data_fixture): + data = test_flux_data_fixture + prg = u.get_weno_program_with_root_kernel("weno_weights_neg") queue = u.get_queue(ctx_factory) @@ -106,7 +118,9 @@ def test_weno_weights_neg_uniform_grid(ctx_factory, data): u.compare_arrays(weights_dev.get(), data.weno_weights_neg) -def test_flux_splitting_uniform_grid(ctx_factory, data): +def test_flux_splitting_uniform_grid(ctx_factory, test_flux_data_fixture): + data = test_flux_data_fixture + prg = u.get_weno_program_with_root_kernel("split_characteristic_fluxes") queue = u.get_queue(ctx_factory) @@ -126,6 +140,8 @@ def test_flux_splitting_uniform_grid(ctx_factory, data): def test_pointwise_eigenvalues_ideal_gas(ctx_factory, data): + data = test_flux_data_fixture + prg = u.get_weno_program_with_root_kernel("pointwise_eigenvalues") queue = u.get_queue(ctx_factory) @@ -137,7 +153,9 @@ def test_pointwise_eigenvalues_ideal_gas(ctx_factory, data): u.compare_arrays(lam_dev.get(), data.lam_pointwise) -def test_roe_uniform_grid_ideal_gas(ctx_factory, data): +def test_roe_uniform_grid_ideal_gas(ctx_factory, test_flux_data_fixture): + data = test_flux_data_fixture + def identity_matrix(n): return np.identity(n).astype(np.float32).copy(order="F") diff --git a/input.py b/test_data.py similarity index 99% rename from input.py rename to test_data.py index f29c026..5319930 100644 --- a/input.py +++ b/test_data.py @@ -1,6 +1,7 @@ import pytest import utilities as u + # {{{ FluxDataSingle class FluxDataSingle: @@ -72,6 +73,7 @@ class FluxDataSingle: # }}} + single_data = {} # {{{ Input data: Case (a) @@ -703,7 +705,7 @@ single_data["Case d:z"] = FluxDataSingle( "Case b:x", "Case b:y", "Case b:z", "Case c:x", "Case c:y", "Case c:z", "Case d:x", "Case d:y", "Case d:z"]) -def data(request): +def test_flux_data_fixture(request): return single_data[request.param] -- GitLab From 55a528e67a744084a2689b4eeff2e85adc328180 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 28 Jul 2019 17:12:04 -0500 Subject: [PATCH 2/5] Rename test_data to avoid pytest confusion --- test_data.py => data_for_test.py | 0 test.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename test_data.py => data_for_test.py (100%) diff --git a/test_data.py b/data_for_test.py similarity index 100% rename from test_data.py rename to data_for_test.py diff --git a/test.py b/test.py index 543abaf..be05de0 100644 --- a/test.py +++ b/test.py @@ -15,7 +15,7 @@ from pyopencl.tools import ( # noqa as pytest_generate_tests) import utilities as u -from test_data import test_flux_data_fixture # noqa: F401 +from data_for_test import test_flux_data_fixture # noqa: F401 def test_weno_flux_uniform_grid(ctx_factory, test_flux_data_fixture): -- GitLab From 266f95dc04484bf4b6a58c2af7c0ad911b1f4233 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 28 Jul 2019 17:12:13 -0500 Subject: [PATCH 3/5] Flake8 fixes --- data_for_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/data_for_test.py b/data_for_test.py index 5319930..8390952 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -55,21 +55,21 @@ class FluxDataSingle: def swap_array(self, arr, d): p = self.permutation(d) - arr[p] = arr[[1,2,3]] + arr[p] = arr[[1, 2, 3]] return arr def swap_array_rows(self, arr, d): p = self.permutation(d) - arr[p,:] = arr[[1,2,3],:] + arr[p, :] = arr[[1, 2, 3], :] return arr def swap_array_cols(self, arr, d): p = self.permutation(d) - arr[:,p] = arr[:,[1,2,3]] + arr[:, p] = arr[:, [1, 2, 3]] return arr def permutation(self, d): - return [(d-1+i)%3 + 1 for i in range(3)] + return [(d-1+i) % 3 + 1 for i in range(3)] # }}} -- GitLab From e98686197ebd49a4f33990dc5871768d251b6874 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 28 Jul 2019 17:18:15 -0500 Subject: [PATCH 4/5] Rename test_flux_data_fixture -> flux_test_data_fixture to avoid pytest confusion --- data_for_test.py | 2 +- test.py | 36 ++++++++++++++++++------------------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/data_for_test.py b/data_for_test.py index 8390952..c83dd53 100644 --- a/data_for_test.py +++ b/data_for_test.py @@ -705,7 +705,7 @@ single_data["Case d:z"] = FluxDataSingle( "Case b:x", "Case b:y", "Case b:z", "Case c:x", "Case c:y", "Case c:z", "Case d:x", "Case d:y", "Case d:z"]) -def test_flux_data_fixture(request): +def flux_test_data_fixture(request): return single_data[request.param] diff --git a/test.py b/test.py index be05de0..8ee0e49 100644 --- a/test.py +++ b/test.py @@ -15,11 +15,11 @@ from pyopencl.tools import ( # noqa as pytest_generate_tests) import utilities as u -from data_for_test import test_flux_data_fixture # noqa: F401 +from data_for_test import flux_test_data_fixture # noqa: F401 -def test_weno_flux_uniform_grid(ctx_factory, test_flux_data_fixture): - data = test_flux_data_fixture +def test_weno_flux_uniform_grid(ctx_factory, flux_test_data_fixture): + data = flux_test_data_fixture prg = u.get_weno_program_with_root_kernel("weno_flux") queue = u.get_queue(ctx_factory) @@ -37,8 +37,8 @@ def test_weno_flux_uniform_grid(ctx_factory, test_flux_data_fixture): u.compare_arrays(flux_dev.get(), data.weno_flux) -def test_consistent_part_uniform_grid(ctx_factory, test_flux_data_fixture): - data = test_flux_data_fixture +def test_consistent_part_uniform_grid(ctx_factory, flux_test_data_fixture): + data = flux_test_data_fixture prg = u.get_weno_program_with_root_kernel("consistent_part") queue = u.get_queue(ctx_factory) @@ -52,8 +52,8 @@ def test_consistent_part_uniform_grid(ctx_factory, test_flux_data_fixture): u.compare_arrays(consistent_dev.get(), data.consistent) -def test_dissipation_part_pos_uniform_grid(ctx_factory, test_flux_data_fixture): - data = test_flux_data_fixture +def test_dissipation_part_pos_uniform_grid(ctx_factory, flux_test_data_fixture): + data = flux_test_data_fixture prg = u.get_weno_program_with_root_kernel("dissipation_part_pos") queue = u.get_queue(ctx_factory) @@ -69,8 +69,8 @@ def test_dissipation_part_pos_uniform_grid(ctx_factory, test_flux_data_fixture): u.compare_arrays(dissipation_dev.get(), data.dissipation_pos) -def test_dissipation_part_neg_uniform_grid(ctx_factory, test_flux_data_fixture): - data = test_flux_data_fixture +def test_dissipation_part_neg_uniform_grid(ctx_factory, flux_test_data_fixture): + data = flux_test_data_fixture prg = u.get_weno_program_with_root_kernel("dissipation_part_neg") queue = u.get_queue(ctx_factory) @@ -86,8 +86,8 @@ def test_dissipation_part_neg_uniform_grid(ctx_factory, test_flux_data_fixture): u.compare_arrays(dissipation_dev.get(), data.dissipation_neg) -def test_weno_weights_pos_uniform_grid(ctx_factory, test_flux_data_fixture): - data = test_flux_data_fixture +def test_weno_weights_pos_uniform_grid(ctx_factory, flux_test_data_fixture): + data = flux_test_data_fixture prg = u.get_weno_program_with_root_kernel("weno_weights_pos") queue = u.get_queue(ctx_factory) @@ -102,8 +102,8 @@ def test_weno_weights_pos_uniform_grid(ctx_factory, test_flux_data_fixture): u.compare_arrays(weights_dev.get(), data.weno_weights_pos) -def test_weno_weights_neg_uniform_grid(ctx_factory, test_flux_data_fixture): - data = test_flux_data_fixture +def test_weno_weights_neg_uniform_grid(ctx_factory, flux_test_data_fixture): + data = flux_test_data_fixture prg = u.get_weno_program_with_root_kernel("weno_weights_neg") queue = u.get_queue(ctx_factory) @@ -118,8 +118,8 @@ def test_weno_weights_neg_uniform_grid(ctx_factory, test_flux_data_fixture): u.compare_arrays(weights_dev.get(), data.weno_weights_neg) -def test_flux_splitting_uniform_grid(ctx_factory, test_flux_data_fixture): - data = test_flux_data_fixture +def test_flux_splitting_uniform_grid(ctx_factory, flux_test_data_fixture): + data = flux_test_data_fixture prg = u.get_weno_program_with_root_kernel("split_characteristic_fluxes") queue = u.get_queue(ctx_factory) @@ -140,7 +140,7 @@ def test_flux_splitting_uniform_grid(ctx_factory, test_flux_data_fixture): def test_pointwise_eigenvalues_ideal_gas(ctx_factory, data): - data = test_flux_data_fixture + data = flux_test_data_fixture prg = u.get_weno_program_with_root_kernel("pointwise_eigenvalues") queue = u.get_queue(ctx_factory) @@ -153,8 +153,8 @@ def test_pointwise_eigenvalues_ideal_gas(ctx_factory, data): u.compare_arrays(lam_dev.get(), data.lam_pointwise) -def test_roe_uniform_grid_ideal_gas(ctx_factory, test_flux_data_fixture): - data = test_flux_data_fixture +def test_roe_uniform_grid_ideal_gas(ctx_factory, flux_test_data_fixture): + data = flux_test_data_fixture def identity_matrix(n): return np.identity(n).astype(np.float32).copy(order="F") -- GitLab From 7f1e91319ca04091f0c94899d884f623d21c8294 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 28 Jul 2019 18:52:34 -0500 Subject: [PATCH 5/5] Fix an incorrect fixture argument --- test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.py b/test.py index 8ee0e49..ab1c138 100644 --- a/test.py +++ b/test.py @@ -139,7 +139,7 @@ def test_flux_splitting_uniform_grid(ctx_factory, flux_test_data_fixture): u.compare_arrays(fluxes_neg_dev.get(), data.char_fluxes_neg) -def test_pointwise_eigenvalues_ideal_gas(ctx_factory, data): +def test_pointwise_eigenvalues_ideal_gas(ctx_factory, flux_test_data_fixture): data = flux_test_data_fixture prg = u.get_weno_program_with_root_kernel("pointwise_eigenvalues") -- GitLab