Skip to content

Commit

Permalink
make test optional when adls is not installed (#110)
Browse files Browse the repository at this point in the history
* make test optional when adls is not installed

* changelog

* tests

* tests

* split tests
  • Loading branch information
floriankrb authored Oct 31, 2024
1 parent 65485a4 commit 88a8a27
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Keep it human-readable, your future self will thank you!

## [Unreleased](https://github.com/ecmwf/anemoi-datasets/compare/0.5.8...HEAD)

### Changed
- make test optional when adls is not installed Pull request #110

## [0.5.8](https://github.com/ecmwf/anemoi-datasets/compare/0.5.7...0.5.8) - 2024-10-26

### Changed
Expand Down
20 changes: 20 additions & 0 deletions tests/create/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import hashlib
import json
import os
import sys
from functools import wraps
from unittest.mock import patch

Expand All @@ -37,6 +38,24 @@
assert NAMES, "No yaml files found in " + HERE


def is_ubuntu():
if os.path.isfile("/etc/os-release"):
with open("/etc/os-release") as f:
return "Ubuntu" in f.read()
return False


def is_darwin():
if os.path.isfile("/etc/os-release"):
with open("/etc/os-release") as f:
return "Darwin" in f.read()
return False


# run extensive tests only on Ubuntu and Darwin, and not on Python 3.9 and 3.11
extensive_tests = (sys.version_info[:2] not in [(3, 9), (3, 11)]) and (is_ubuntu() or is_darwin())


def mockup_from_source(func):
@wraps(func)
def wrapper(*args, **kwargs):
Expand Down Expand Up @@ -233,6 +252,7 @@ def compare(self):


@pytest.mark.parametrize("name", NAMES)
@pytest.mark.skipif(not extensive_tests, reason="Skipping to run the test faster")
@mockup_from_source
def test_run(name):
config = os.path.join(HERE, name + ".yaml")
Expand Down
9 changes: 9 additions & 0 deletions tests/xarray/test_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@
# nor does it submit to any jurisdiction.


import pytest
import xarray as xr

from anemoi.datasets.create.functions.sources.xarray import XarrayFieldList
from anemoi.datasets.data.stores import name_to_zarr_store
from anemoi.datasets.testing import assert_field_list

try:
import adlfs # noqa: F401

HAS_ADLS = True
except ImportError:
HAS_ADLS = False


def test_arco_era5_1():

Expand Down Expand Up @@ -118,6 +126,7 @@ def test_noaa_replay():
)


@pytest.mark.skipif(not HAS_ADLS, reason="package adlfs not installed")
def test_planetary_computer_conus404():
url = "https://planetarycomputer.microsoft.com/api/stac/v1/collections/conus404"
ds = xr.open_zarr(**name_to_zarr_store(url))
Expand Down

0 comments on commit 88a8a27

Please sign in to comment.