diff --git a/src/earthkit/data/utils/testing.py b/src/earthkit/data/utils/testing.py index 0214ec074..6c2062849 100644 --- a/src/earthkit/data/utils/testing.py +++ b/src/earthkit/data/utils/testing.py @@ -134,6 +134,7 @@ def modules_installed(*modules): fdb_home = os.environ.get("FDB_HOME", None) NO_PROD_FDB = fdb_home is None +NO_ODC = not modules_installed("pyodc") and not modules_installed("codc") NO_GRIBJUMP = NO_FDB or not modules_installed("pygribjump") NO_POLYTOPE = not os.path.exists(os.path.expanduser("~/.polytopeapirc")) NO_COVJSONKIT = not modules_installed("covjsonkit") @@ -141,6 +142,8 @@ def modules_installed(*modules): NO_S3_AUTH = not modules_installed("aws_requests_auth") NO_GEO = not modules_installed("earthkit-geo") +NO_GEOPANDAS = not modules_installed("geopandas") + try: NO_ECFS = not os.path.exists(shutil.which("ecp")) except Exception: diff --git a/tests/high_level_object/test_hl_geojson_core.py b/tests/high_level_object/test_hl_geojson_core.py index b3f95f185..685334a24 100644 --- a/tests/high_level_object/test_hl_geojson_core.py +++ b/tests/high_level_object/test_hl_geojson_core.py @@ -9,10 +9,13 @@ # nor does it submit to any jurisdiction. # +import pytest + from earthkit.data import from_source -from earthkit.data.utils.testing import earthkit_test_data_file +from earthkit.data.utils.testing import NO_GEOPANDAS, earthkit_test_data_file +@pytest.mark.skipif(NO_GEOPANDAS, reason="geopandas is not installed") def test_hl_geojson_single_core(): ds = from_source("file", earthkit_test_data_file("NUTS_RG_20M_2021_3035.geojson")) diff --git a/tests/high_level_object/test_hl_geopandas_core.py b/tests/high_level_object/test_hl_geopandas_core.py index 54ad9631f..1ddbfbdd8 100644 --- a/tests/high_level_object/test_hl_geopandas_core.py +++ b/tests/high_level_object/test_hl_geopandas_core.py @@ -9,6 +9,10 @@ # nor does it submit to any jurisdiction. # +import pytest + +pytest.importorskip("geopandas") + from earthkit.data import from_object from earthkit.data.utils.testing import earthkit_test_data_file diff --git a/tests/high_level_object/test_hl_odb_core.py b/tests/high_level_object/test_hl_odb_core.py index eb8321dcd..9de3c1490 100644 --- a/tests/high_level_object/test_hl_odb_core.py +++ b/tests/high_level_object/test_hl_odb_core.py @@ -9,8 +9,13 @@ # nor does it submit to any jurisdiction. # +import pytest + from earthkit.data import from_source -from earthkit.data.utils.testing import earthkit_examples_file +from earthkit.data.utils.testing import NO_ODC, earthkit_examples_file + +if NO_ODC: + pytest.skip("pyodc is not installed", allow_module_level=True) def test_hl_odb_single_core(): diff --git a/tests/high_level_object/test_hl_shapefile_core.py b/tests/high_level_object/test_hl_shapefile_core.py index 23c90e5df..a04f9aafb 100644 --- a/tests/high_level_object/test_hl_shapefile_core.py +++ b/tests/high_level_object/test_hl_shapefile_core.py @@ -9,10 +9,13 @@ # nor does it submit to any jurisdiction. # +import pytest + from earthkit.data import from_source -from earthkit.data.utils.testing import earthkit_test_data_file +from earthkit.data.utils.testing import NO_GEOPANDAS, earthkit_test_data_file +@pytest.mark.skipif(NO_GEOPANDAS, reason="geopandas is not installed") def test_hl_shapefile_single_core(): d = from_source("file", earthkit_test_data_file("NUTS_RG_20M_2021_3035.shp.zip")) diff --git a/tests/high_level_object/test_hl_target_file.py b/tests/high_level_object/test_hl_target_file.py index 253012f04..bcad8a2c1 100644 --- a/tests/high_level_object/test_hl_target_file.py +++ b/tests/high_level_object/test_hl_target_file.py @@ -17,7 +17,7 @@ from earthkit.data.core.temporary import temp_file from earthkit.data.encoders.grib import GribEncoder from earthkit.data.targets import to_target -from earthkit.data.utils.testing import NO_RIOXARRAY, earthkit_examples_file, earthkit_test_data_file +from earthkit.data.utils.testing import NO_ODC, NO_RIOXARRAY, earthkit_examples_file, earthkit_test_data_file @pytest.mark.parametrize( @@ -133,6 +133,7 @@ def test_hl_target_file_csv(): assert list(df1.columns) == ["h1", "h2", "h3", "name"] +@pytest.mark.skipif(NO_ODC, reason="pyodc is not installed") def test_hl_target_file_odb(): ds = from_source("file", earthkit_examples_file("test.odb")) assert ds._TYPE_NAME == "ODB" diff --git a/tests/odb/test_odb_pandas.py b/tests/odb/test_odb_pandas.py index c0cab358f..86979a6a1 100644 --- a/tests/odb/test_odb_pandas.py +++ b/tests/odb/test_odb_pandas.py @@ -10,9 +10,13 @@ # import numpy as np +import pytest from earthkit.data import from_source -from earthkit.data.utils.testing import earthkit_examples_file +from earthkit.data.utils.testing import NO_ODC, earthkit_examples_file + +if NO_ODC: + pytest.skip("pyodc is not installed", allow_module_level=True) def test_odb_to_pandas(): diff --git a/tests/odb/test_odb_url.py b/tests/odb/test_odb_url.py index 1cf754510..1c3b0f2aa 100644 --- a/tests/odb/test_odb_url.py +++ b/tests/odb/test_odb_url.py @@ -9,8 +9,13 @@ # nor does it submit to any jurisdiction. # +import pytest + from earthkit.data import from_source -from earthkit.data.utils.testing import earthkit_remote_examples_file +from earthkit.data.utils.testing import NO_ODC, earthkit_remote_examples_file + +if NO_ODC: + pytest.skip("pyodc is not installed", allow_module_level=True) def test_odb_url(): diff --git a/tests/readers/test_geojson_reader.py b/tests/readers/test_geojson_reader.py index 95465feee..e51ce8ea6 100644 --- a/tests/readers/test_geojson_reader.py +++ b/tests/readers/test_geojson_reader.py @@ -11,7 +11,10 @@ import pytest from earthkit.data import from_source -from earthkit.data.utils.testing import earthkit_test_data_file +from earthkit.data.utils.testing import NO_GEOPANDAS, earthkit_test_data_file + +if NO_GEOPANDAS: + pytest.skip("geopandas is not installed", allow_module_level=True) def test_geojson(): diff --git a/tests/readers/test_shapefile_reader.py b/tests/readers/test_shapefile_reader.py index 218f35908..fe5de6065 100644 --- a/tests/readers/test_shapefile_reader.py +++ b/tests/readers/test_shapefile_reader.py @@ -9,10 +9,14 @@ # nor does it submit to any jurisdiction. # import numpy as np +import pytest from earthkit.data import from_source from earthkit.data.utils.bbox import BoundingBox -from earthkit.data.utils.testing import earthkit_test_data_file +from earthkit.data.utils.testing import NO_GEOPANDAS, earthkit_test_data_file + +if NO_GEOPANDAS: + pytest.skip("geopandas is not installed", allow_module_level=True) def test_shapefile(): diff --git a/tests/translators/test_pandas_translator.py b/tests/translators/test_pandas_translator.py index 477b17acf..a0496f61f 100644 --- a/tests/translators/test_pandas_translator.py +++ b/tests/translators/test_pandas_translator.py @@ -12,10 +12,11 @@ import logging -import geopandas as gpd import pandas as pd +import pytest from earthkit.data import from_object, transform +from earthkit.data.utils.testing import NO_GEOPANDAS LOG = logging.getLogger(__name__) @@ -42,7 +43,10 @@ def test_pd_dataframe_translator(): assert isinstance(transform(ds, pd.DataFrame), pd.DataFrame) +@pytest.mark.skipif(NO_GEOPANDAS, reason="geopandas is not installed") def test_gpd_dataframe_translator(): + import geopandas as gpd + val = gpd.GeoDataFrame() ds = from_object(val)