Skip to content

Commit

Permalink
simplify last failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeitsperre committed Aug 21, 2024
1 parent c50d1d7 commit ea891f4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 34 deletions.
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ def threadsafe_data_dir(tmp_path_factory):


@pytest.fixture(scope="session")
def nimbus(threadsafe_data_dir):
def nimbus(threadsafe_data_dir, worker_id):
return _nimbus(
data_dir=threadsafe_data_dir,
data_dir=default_cache_dir if worker_id == "master" else threadsafe_data_dir,
repo=helpers.TESTDATA_REPO_URL,
branch=helpers.TESTDATA_BRANCH,
)
Expand Down
10 changes: 2 additions & 8 deletions tests/test_ensembles.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

from xclim import ensembles
from xclim.indices.stats import get_dist
from xclim.testing.helpers import TESTDATA_BRANCH


# sklearn's KMeans doesn't accept the standard numpy Generator, so we create a special fixture for these tests
Expand All @@ -38,9 +37,7 @@ def random_state():


class TestEnsembleStats:
def test_create_ensemble(
self, open_dataset, ensemble_dataset_objects, threadsafe_data_dir
):
def test_create_ensemble(self, open_dataset, ensemble_dataset_objects, nimbus):
ds_all = []
for n in ensemble_dataset_objects["nc_files_simple"]:
ds = open_dataset(n, decode_times=False)
Expand All @@ -62,10 +59,7 @@ def test_create_ensemble(
ens1 = ensembles.create_ensemble(ds_all, realizations=reals)

# Kinda a hack? Alternative is to open and rewrite in a temp folder.
files = [
threadsafe_data_dir / TESTDATA_BRANCH / "EnsembleStats" / Path(f).name
for f in ensemble_dataset_objects["nc_files_simple"]
]
files = [nimbus.fetch(f) for f in ensemble_dataset_objects["nc_files_simple"]]
ens2 = ensembles.create_ensemble(dict(zip(reals, files)))
xr.testing.assert_identical(ens1, ens2)

Expand Down
10 changes: 8 additions & 2 deletions tests/test_testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@ def file_md5_checksum(f_name):
return hash_md5.hexdigest()

@pytest.mark.requires_internet
def test_open_testdata(self):
def test_open_testdata(
self,
):
from xclim.testing.helpers import default_cache_dir, default_testdata_version

ds = helpers.open_dataset(
Path("cmip5/tas_Amon_CanESM2_rcp85_r1i1p1_200701-200712"), engine="h5netcdf"
Path("cmip5/tas_Amon_CanESM2_rcp85_r1i1p1_200701-200712.nc"),
cache_dir=default_cache_dir.joinpath(default_testdata_version),
engine="h5netcdf",
)
assert ds.lon.size == 128

Expand Down
25 changes: 3 additions & 22 deletions xclim/testing/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,6 @@
$ env XCLIM_TESTDATA_BRANCH="my_testing_branch" pytest
"""

PREFETCH_TESTING_DATA = bool(os.getenv("XCLIM_PREFETCH_TESTING_DATA"))
"""Indicates whether the testing data should be downloaded when running tests.
Notes
-----
When running tests multiple times, this flag allows developers to significantly speed up the pytest suite
by preventing sha256sum checks for all downloaded files. Proceed with caution.
This can be set for both `pytest` and `tox` by exporting the variable:
.. code-block:: console
$ export XCLIM_PREFETCH_TESTING_DATA=1
or setting the variable at runtime:
.. code-block:: console
$ env XCLIM_PREFETCH_TESTING_DATA=1 pytest
"""

CACHE_DIR = os.getenv("XCLIM_DATA_DIR", default_cache_dir)
"""Sets the directory to store the testing datasets.
Expand All @@ -128,11 +107,13 @@


__all__ = [
"PREFETCH_TESTING_DATA",
"CACHE_DIR",
"TESTDATA_BRANCH",
"TESTDATA_REPO_URL",
"add_example_file_paths",
"assert_lazy",
"default_cache_dir",
"default_testdata_version",
"generate_atmos",
"nimbus",
"open_dataset",
Expand Down

0 comments on commit ea891f4

Please sign in to comment.