Skip to content
This repository was archived by the owner on Oct 24, 2024. It is now read-only.

Skips tests if it doesn't have the correct dependency #34

Merged
merged 1 commit into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions datatree/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import importlib
from distutils import version

import pytest


def _importorskip(modname, minversion=None):
try:
mod = importlib.import_module(modname)
has = True
if minversion is not None:
if LooseVersion(mod.__version__) < LooseVersion(minversion):
raise ImportError("Minimum version not satisfied")
except ImportError:
has = False
func = pytest.mark.skipif(not has, reason=f"requires {modname}")
return has, func


def LooseVersion(vstring):
# Our development version is something like '0.10.9+aac7bfc'
# This function just ignores the git commit id.
vstring = vstring.split("+")[0]
return version.LooseVersion(vstring)


has_zarr, requires_zarr = _importorskip("zarr")
has_netCDF4, requires_netCDF4 = _importorskip("netCDF4")
3 changes: 3 additions & 0 deletions datatree/tests/test_datatree.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from datatree import DataNode, DataTree
from datatree.io import open_datatree
from datatree.tests import requires_netCDF4, requires_zarr


def assert_tree_equal(dt_a, dt_b):
Expand Down Expand Up @@ -311,6 +312,7 @@ def test_repr_of_node_with_data(self):


class TestIO:
@requires_netCDF4
def test_to_netcdf(self, tmpdir):
filepath = str(
tmpdir / "test.nc"
Expand All @@ -321,6 +323,7 @@ def test_to_netcdf(self, tmpdir):
roundtrip_dt = open_datatree(filepath)
assert_tree_equal(original_dt, roundtrip_dt)

@requires_zarr
def test_to_zarr(self, tmpdir):
filepath = str(
tmpdir / "test.zarr"
Expand Down
3 changes: 2 additions & 1 deletion datatree/tests/test_mapping.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import pytest
import xarray as xr
from test_datatree import assert_tree_equal, create_test_datatree

from datatree.datatree import DataTree
from datatree.mapping import TreeIsomorphismError, _check_isomorphic, map_over_subtree
from datatree.treenode import TreeNode

from .test_datatree import assert_tree_equal, create_test_datatree

empty = xr.Dataset()


Expand Down