Skip to content

Commit

Permalink
Created conftest.py and moved two fixtures into conftest (#57)
Browse files Browse the repository at this point in the history
* created conftest.py and moved two fixtures into conftest

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
norlandrhagen and pre-commit-ci[bot] authored Mar 27, 2024
1 parent 5f03e6e commit 2c83531
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
31 changes: 31 additions & 0 deletions virtualizarr/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
28 changes: 0 additions & 28 deletions virtualizarr/tests/test_xarray.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Mapping

import numpy as np
import pytest
import xarray as xr
from xarray.core.indexes import Index

Expand Down Expand Up @@ -225,34 +224,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:
Expand Down

0 comments on commit 2c83531

Please sign in to comment.