From e1957dcd201799fc59a5bba518ad6c3d4270f4b5 Mon Sep 17 00:00:00 2001 From: Raphael Hagen Date: Wed, 27 Mar 2024 13:18:20 -0600 Subject: [PATCH 1/2] created conftest.py and moved two fixtures into conftest --- virtualizarr/tests/conftest.py | 31 +++++++++++++++++++++++++++++++ virtualizarr/tests/test_xarray.py | 27 --------------------------- 2 files changed, 31 insertions(+), 27 deletions(-) create mode 100644 virtualizarr/tests/conftest.py diff --git a/virtualizarr/tests/conftest.py b/virtualizarr/tests/conftest.py new file mode 100644 index 00000000..2e69d720 --- /dev/null +++ b/virtualizarr/tests/conftest.py @@ -0,0 +1,31 @@ +import pytest +import xarray as xr + +@pytest.fixture +def netcdf4_file(tmpdir): + # Set up example xarray dataset + ds = xr.tutorial.open_dataset("air_temperature") + + # Save it to disk as netCDF (in temporary directory) + filepath = f"{tmpdir}/air.nc" + ds.to_netcdf(filepath) + + return filepath + + +@pytest.fixture +def netcdf4_files(tmpdir): + # Set up example xarray dataset + ds = xr.tutorial.open_dataset("air_temperature") + + # split inrto equal chunks so we can concatenate them back together later + ds1 = ds.isel(time=slice(None, 1460)) + ds2 = ds.isel(time=slice(1460, None)) + + # Save it to disk as netCDF (in temporary directory) + filepath1 = f"{tmpdir}/air1.nc" + filepath2 = f"{tmpdir}/air2.nc" + ds1.to_netcdf(filepath1) + ds2.to_netcdf(filepath2) + + return filepath1, filepath2 diff --git a/virtualizarr/tests/test_xarray.py b/virtualizarr/tests/test_xarray.py index 4951d36c..a629b19b 100644 --- a/virtualizarr/tests/test_xarray.py +++ b/virtualizarr/tests/test_xarray.py @@ -225,34 +225,7 @@ def test_concat_dim_coords_along_existing_dim(self): assert result.data.zarray.zarr_format == zarray.zarr_format -@pytest.fixture -def netcdf4_file(tmpdir): - # Set up example xarray dataset - ds = xr.tutorial.open_dataset("air_temperature") - # Save it to disk as netCDF (in temporary directory) - filepath = f"{tmpdir}/air.nc" - ds.to_netcdf(filepath) - - return filepath - - -@pytest.fixture -def netcdf4_files(tmpdir): - # Set up example xarray dataset - ds = xr.tutorial.open_dataset("air_temperature") - - # split inrto equal chunks so we can concatenate them back together later - ds1 = ds.isel(time=slice(None, 1460)) - ds2 = ds.isel(time=slice(1460, None)) - - # Save it to disk as netCDF (in temporary directory) - filepath1 = f"{tmpdir}/air1.nc" - filepath2 = f"{tmpdir}/air2.nc" - ds1.to_netcdf(filepath1) - ds2.to_netcdf(filepath2) - - return filepath1, filepath2 class TestOpenVirtualDatasetIndexes: From 8f3a88316846954c64189f8ce58dc0f79a7089de Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:18:56 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- virtualizarr/tests/conftest.py | 2 +- virtualizarr/tests/test_xarray.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/virtualizarr/tests/conftest.py b/virtualizarr/tests/conftest.py index 2e69d720..1ffa50e1 100644 --- a/virtualizarr/tests/conftest.py +++ b/virtualizarr/tests/conftest.py @@ -1,5 +1,5 @@ import pytest -import xarray as xr +import xarray as xr @pytest.fixture def netcdf4_file(tmpdir): diff --git a/virtualizarr/tests/test_xarray.py b/virtualizarr/tests/test_xarray.py index a629b19b..db406ada 100644 --- a/virtualizarr/tests/test_xarray.py +++ b/virtualizarr/tests/test_xarray.py @@ -1,7 +1,6 @@ from typing import Mapping import numpy as np -import pytest import xarray as xr from xarray.core.indexes import Index