Skip to content

Commit

Permalink
Merge pull request #218 from dstansby/xarray-smoke
Browse files Browse the repository at this point in the history
Add some xarray smoke tests
  • Loading branch information
dstansby committed Jun 6, 2023
2 parents 0e14476 + dbe7ad7 commit ad3ed84
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pathlib

import pytest


@pytest.fixture(params=["psp_fld_l2_mag_rtn_1min_20200104_v02.cdf", "de2_ion2s_rpa_19830213_v01.cdf"])
def cdf_path(request):
"""
Returns a series of CDF file paths which can be used for smoke testing.
"""
return (pathlib.Path(__file__) / ".." / "testfiles" / request.param).resolve()
10 changes: 3 additions & 7 deletions tests/test_cdfread.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import pathlib

import pytest

from cdflib import CDF


@pytest.mark.parametrize("fname", ["psp_fld_l2_mag_rtn_1min_20200104_v02.cdf", "de2_ion2s_rpa_19830213_v01.cdf"])
def test_read(fname):
fname = (pathlib.Path(__file__) / ".." / "testfiles" / fname).resolve()
cdf = CDF(fname)
def test_read(cdf_path):
cdf = CDF(cdf_path)

info = cdf.cdf_info()

Expand All @@ -18,7 +14,7 @@ def test_read(fname):
cdf.varget(var)

# Smoke test context manager
with CDF(fname) as cdf:
with CDF(cdf_path) as cdf:
cdf.cdf_info()

# Smoke test global attributes
Expand Down
5 changes: 5 additions & 0 deletions tests/test_xarray_reader_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,8 @@ def test_build_from_scratch():
ds = xr.Dataset(data_vars={"data": data, "epoch": epoch, "direction": direction}, attrs=global_attributes)
xarray_to_cdf(ds, "hello.cdf")
os.remove("hello.cdf")


def test_smoke(cdf_path, tmp_path):
a = cdf_to_xarray(cdf_path, to_unixtime=True, fillval_to_nan=True)
xarray_to_cdf(a, tmp_path / cdf_path.name, from_unixtime=True)

0 comments on commit ad3ed84

Please sign in to comment.