Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankrb committed Feb 24, 2025
1 parent b248ba3 commit 7f8cf21
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.

import os
import sys
from pathlib import Path

import earthkit.data as ekd
import numpy.testing as npt
import pytest
from pytest import approx

from anemoi.transform.filters.lambda_filters import EarthkitFieldLambdaFilter
Expand All @@ -20,6 +22,8 @@

sys.path.append(Path(__file__).parents[1].as_posix())

NO_MARS = not os.path.exists(os.path.expanduser("~/.ecmwfapirc"))


def fieldlist_fixture():
return ekd.from_source(
Expand All @@ -32,6 +36,7 @@ def fieldlist_fixture():
)


@pytest.mark.skipif(NO_MARS, reason="No access to MARS")
def test_rescale(fieldlist=None):
if fieldlist is None:
fieldlist = fieldlist_fixture()
Expand All @@ -46,6 +51,7 @@ def test_rescale(fieldlist=None):
npt.assert_allclose(rescaled_back[0].to_numpy(), fieldlist[0].to_numpy())


@pytest.mark.skipif(NO_MARS, reason="No access to MARS")
def test_convert(fieldlist=None):
if fieldlist is None:
fieldlist = fieldlist_fixture()
Expand All @@ -69,6 +75,7 @@ def _do_something(field, a):
return field.clone(values=field.values * a)


@pytest.mark.skipif(NO_MARS, reason="No access to MARS")
def test_singlefieldlambda(fieldlist=None):
if fieldlist is None:
fieldlist = fieldlist_fixture()
Expand Down
9 changes: 9 additions & 0 deletions tests/test_repeat_members.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.

import os

import earthkit.data as ekd
import numpy as np
import pytest

from anemoi.transform.filters.repeat_members import RepeatMembers

NO_MARS = not os.path.exists(os.path.expanduser("~/.ecmwfapirc"))


def _get_template():
temp = ekd.from_source("mars", {"param": "2t", "levtype": "sfc", "dates": ["2023-11-17 00:00:00"]})
fieldlist = temp.to_fieldlist()
return fieldlist, fieldlist[0].values, fieldlist[0].metadata


@pytest.mark.skipif(NO_MARS, reason="No access to MARS")
def test_repeat_members_using_numbers_1():
fieldlist, values, metadata = _get_template()

Expand All @@ -32,6 +38,7 @@ def test_repeat_members_using_numbers_1():
assert f.metadata("name") == metadata("name")


@pytest.mark.skipif(NO_MARS, reason="No access to MARS")
def test_repeat_members_using_numbers_2():
fieldlist, values, metadata = _get_template()

Expand All @@ -45,6 +52,7 @@ def test_repeat_members_using_numbers_2():
assert f.metadata("name") == metadata("name")


@pytest.mark.skipif(NO_MARS, reason="No access to MARS")
def test_repeat_members_using_members():
fieldlist, values, metadata = _get_template()

Expand All @@ -58,6 +66,7 @@ def test_repeat_members_using_members():
assert f.metadata("name") == metadata("name")


@pytest.mark.skipif(NO_MARS, reason="No access to MARS")
def test_repeat_members_using_count():
fieldlist, values, metadata = _get_template()

Expand Down

0 comments on commit 7f8cf21

Please sign in to comment.