Skip to content

Commit 4996be2

Browse files
committed
Test fixes.
1 parent 2c6cb0c commit 4996be2

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

lib/iris/fileformats/netcdf/saver.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import iris.fileformats.cf
5757
from iris.fileformats.netcdf import _bytecoding_datasets as bytecoding_datasets
5858
from iris.fileformats.netcdf import _dask_locks
59+
from iris.fileformats.netcdf import _thread_safe_nc as threadsafe_nc
5960
from iris.fileformats.netcdf._attribute_handlers import ATTRIBUTE_HANDLERS
6061
import iris.io
6162
import iris.util
@@ -2523,7 +2524,7 @@ def _increment_name(self, varname):
25232524
def _lazy_stream_data(
25242525
self,
25252526
data: np.typing.ArrayLike,
2526-
cf_var: CFVariable,
2527+
cf_var: threadsafe_nc.VariableWrapper,
25272528
) -> None:
25282529
if hasattr(data, "shape") and data.shape == (1,) + cf_var.shape:
25292530
# (Don't do this check for string data).
@@ -2550,7 +2551,7 @@ def _lazy_stream_data(
25502551
# later by a call to delayed_completion().
25512552
def store(
25522553
data: np.typing.ArrayLike,
2553-
cf_var: CFVariable,
2554+
cf_var: threadsafe_nc.VariableWrapper,
25542555
) -> None:
25552556
# Create a data-writeable object that we can stream into, which
25562557
# encapsulates the file to be opened + variable to be written.
@@ -2564,7 +2565,7 @@ def store(
25642565
# Real data is always written directly, i.e. not via lazy save.
25652566
def store(
25662567
data: np.typing.ArrayLike,
2567-
cf_var: CFVariable,
2568+
cf_var: threadsafe_nc.VariableWrapper,
25682569
) -> None:
25692570
cf_var[:] = data # type: ignore[index]
25702571

lib/iris/tests/unit/fileformats/netcdf/saver/test_Saver__lazy_stream_data.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import numpy as np
1717
import pytest
1818

19+
import iris.fileformats.netcdf._bytecoding_datasets as bytecoding_datasets
1920
import iris.fileformats.netcdf._thread_safe_nc as threadsafe_nc
2021
from iris.fileformats.netcdf.saver import Saver
2122

@@ -52,9 +53,10 @@ def data_form(request) -> Iterator[bool]:
5253
return request.param
5354

5455
@staticmethod
55-
def saver(compute) -> Saver:
56+
def saver(compute, data_form, tmp_path) -> Saver:
5657
# Create a test Saver object
57-
return Saver(filename="<dummy>", netcdf_format="NETCDF4", compute=compute)
58+
filepath = tmp_path / f"tmp_{compute}_{data_form}.nc"
59+
return Saver(filename=filepath, netcdf_format="NETCDF4", compute=compute)
5860

5961
@staticmethod
6062
def mock_var(shape, with_data_array, mocker):
@@ -68,6 +70,7 @@ def mock_var(shape, with_data_array, mocker):
6870
spec=threadsafe_nc.VariableWrapper,
6971
shape=tuple(shape),
7072
dtype=np.dtype(np.float32),
73+
_contained_instance=mocker.Mock(dtype="f4"),
7174
**extra_properties,
7275
)
7376
# Give the mock cf-var a name property, as required by '_lazy_stream_data'.
@@ -76,9 +79,9 @@ def mock_var(shape, with_data_array, mocker):
7679
mock_cfvar.name = "<mock_cfvar>"
7780
return mock_cfvar
7881

79-
def test_data_save(self, compute, data_form, mocker):
82+
def test_data_save(self, compute, data_form, mocker, tmp_path):
8083
"""Real data is transferred immediately, lazy data creates a delayed write."""
81-
saver = self.saver(compute=compute)
84+
saver = self.saver(compute, data_form, tmp_path)
8285

8386
data = np.arange(5.0)
8487
if data_form == "lazydata":

0 commit comments

Comments
 (0)