Skip to content

Commit afa11e5

Browse files
committed
Use thread-save nc.Dataset wrappers for tests.
1 parent 2724b2d commit afa11e5

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/iris/tests/integration/netcdf/test_load_managed_attributes.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@
66

77
import warnings
88

9+
# Annoyingly, this import is *not* redundant, as pytest import fails without it.
10+
import iris_grib # noqa: F401
911
from iris_grib.grib_phenom_translation._gribcode import (
1012
GenericConcreteGRIBCode,
1113
GRIBCode,
1214
)
13-
import netCDF4 as nc
1415
import numpy as np
1516
import pytest
1617

1718
import iris
1819
from iris.cube import Cube
20+
from iris.fileformats.netcdf._thread_safe_nc import DatasetWrapper as NcDataset
1921
from iris.fileformats.pp import STASH
2022

2123

@@ -38,7 +40,7 @@ def _check_load_inner(self, iris_name, nc_name, value):
3840
# Save : NB can fail
3941
iris.save(cube, self.tmp_ncpath)
4042
# Reopen for updating with netcdf
41-
ds = nc.Dataset(self.tmp_ncpath, "r+")
43+
ds = NcDataset(self.tmp_ncpath, "r+")
4244
# Add the test attribute content.
4345
ds.variables["x"].setncattr(nc_name, value)
4446
ds.close()
@@ -75,10 +77,11 @@ def test_dual_names(self):
7577
# Test the highly unusual case where both names occur.
7678
result = self._check_load(value="xxx")
7779
# Modify the file variable to have *both* attributes
78-
with nc.Dataset(self.tmp_ncpath, "r+") as ds:
79-
var = ds.variables["x"]
80-
var.um_stash_source = "x1"
81-
var.ukmo__um_stash_source = "x2"
80+
ds = NcDataset(self.tmp_ncpath, "r+")
81+
var = ds.variables["x"]
82+
var.um_stash_source = "x1"
83+
var.ukmo__um_stash_source = "x2"
84+
ds.close()
8285

8386
# When re-loaded, this should raise a warning.
8487
msg = "Multiple file attributes would set .*STASH"

0 commit comments

Comments
 (0)