Skip to content

Commit

Permalink
Change test fixture is_otf into util function (#404)
Browse files Browse the repository at this point in the history
Change test fixture is_otf into utility function.
  • Loading branch information
edopao authored Mar 5, 2024
1 parent 05e6adb commit 6818f84
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
12 changes: 12 additions & 0 deletions model/common/src/icon4py/model/common/test_utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ def backend(request):
return request.param


def is_otf(backend) -> bool:
# want to exclude python backends:
# - cannot run on embedded: because of slicing
# - roundtrip is very slow on large grid
if hasattr(backend, "executor"):
if isinstance(
backend.executor, gt4py.next.program_processors.modular_executor.ModularExecutor
):
return True
return False


def _shape(
grid,
*dims: gt_common.Dimension,
Expand Down
16 changes: 0 additions & 16 deletions model/common/tests/metric_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
# distribution for a copy of the license or check <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
import gt4py.next.program_processors.modular_executor
import pytest

from icon4py.model.common.test_utils.datatest_fixtures import ( # noqa: F401 # import fixtures from test_utils package
data_provider,
Expand All @@ -28,17 +26,3 @@
from icon4py.model.common.test_utils.helpers import ( # noqa : F401 # fixtures from test_utils
backend,
)


@pytest.fixture
def is_otf(backend) -> bool: # noqa : F811 # fixture is used in the test
# not reusing the `uses_local_area_icon_grid_with_otf` fixture because it also checks for the grid
# want to exclude python backends:
# - cannot run on embedded: because of slicing
# - roundtrip is very slow on large grid
if hasattr(backend, "executor"):
if isinstance(
backend.executor, gt4py.next.program_processors.modular_executor.ModularExecutor
):
return True
return False
16 changes: 11 additions & 5 deletions model/common/tests/metric_tests/test_metric_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@
compute_ddqz_z_half,
compute_z_mc,
)
from icon4py.model.common.test_utils.helpers import StencilTest, dallclose, random_field, zero_field
from icon4py.model.common.test_utils.helpers import (
StencilTest,
dallclose,
is_otf,
random_field,
zero_field,
)


class TestComputeZMc(StencilTest):
Expand Down Expand Up @@ -58,8 +64,8 @@ def input_data(self, grid) -> dict:
)


def test_compute_ddq_z_half(icon_grid, metrics_savepoint, backend, is_otf):
if not is_otf:
def test_compute_ddq_z_half(icon_grid, metrics_savepoint, backend):
if not is_otf(backend):
pytest.skip("skipping: unsupported backend")
ddq_z_half_ref = metrics_savepoint.ddqz_z_half()
z_ifc = metrics_savepoint.z_ifc()
Expand Down Expand Up @@ -93,8 +99,8 @@ def test_compute_ddq_z_half(icon_grid, metrics_savepoint, backend, is_otf):
assert dallclose(ddq_z_half.asnumpy(), ddq_z_half_ref.asnumpy())


def test_compute_ddqz_z_full(icon_grid, metrics_savepoint, backend, is_otf):
if not is_otf:
def test_compute_ddqz_z_full(icon_grid, metrics_savepoint, backend):
if not is_otf(backend):
pytest.skip("skipping: unsupported backend")
z_ifc = metrics_savepoint.z_ifc()
inv_ddqz_full_ref = metrics_savepoint.inv_ddqz_z_full()
Expand Down
10 changes: 5 additions & 5 deletions model/common/tests/metric_tests/test_reference_atmosphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
compute_reference_atmosphere_cell_fields,
compute_reference_atmosphere_edge_fields,
)
from icon4py.model.common.test_utils.helpers import dallclose, zero_field
from icon4py.model.common.test_utils.helpers import dallclose, is_otf, zero_field
from icon4py.model.common.type_alias import wpfloat


Expand Down Expand Up @@ -123,8 +123,8 @@ def test_compute_reference_atmsophere_on_half_level_mass_points(


@pytest.mark.datatest
def test_compute_d_exner_dz_ref_ic(icon_grid, metrics_savepoint, backend, is_otf):
if not is_otf:
def test_compute_d_exner_dz_ref_ic(icon_grid, metrics_savepoint, backend):
if not is_otf(backend):
pytest.skip("skipping: unsupported backend")
theta_ref_ic = metrics_savepoint.theta_ref_ic()
d_exner_dz_ref_ic_ref = metrics_savepoint.d_exner_dz_ref_ic()
Expand All @@ -142,9 +142,9 @@ def test_compute_d_exner_dz_ref_ic(icon_grid, metrics_savepoint, backend, is_otf

@pytest.mark.datatest
def test_compute_reference_atmosphere_on_full_level_edge_fields(
icon_grid, interpolation_savepoint, metrics_savepoint, backend, is_otf
icon_grid, interpolation_savepoint, metrics_savepoint, backend
):
if not is_otf:
if not is_otf(backend):
pytest.skip("skipping: unsupported backend")
rho_ref_me_ref = metrics_savepoint.rho_ref_me()
theta_ref_me_ref = metrics_savepoint.theta_ref_me()
Expand Down

0 comments on commit 6818f84

Please sign in to comment.