88data-variables, auxiliary coordinates, ancillary variables and -possibly?- cell measures.
99"""
1010
11+ from contextlib import contextmanager
1112from dataclasses import dataclass
1213from pathlib import Path
1314
1718import iris
1819from iris .fileformats .netcdf import _thread_safe_nc
1920
20- iris .fileformats .netcdf .loader ._LAZYVAR_MIN_BYTES = 0
21+
22+ @pytest .fixture (scope = "module" )
23+ def all_lazy_auxcoords ():
24+ """Ensure that *all* aux-coords are loaded lazily, even really small ones."""
25+ old_minlazybytes = iris .fileformats .netcdf .loader ._LAZYVAR_MIN_BYTES
26+ iris .fileformats .netcdf .loader ._LAZYVAR_MIN_BYTES = 0
27+ yield
28+ iris .fileformats .netcdf .loader ._LAZYVAR_MIN_BYTES = old_minlazybytes
29+
2130
2231N_XDIM = 3
2332N_CHARS_DIM = 64
24- # COORD_ON_SEPARATE_DIM = True
25- COORD_ON_SEPARATE_DIM = False
2633PERSIST_TESTFILES = "~/chararray_testfiles"
2734
2835
@@ -78,16 +85,22 @@ def convert_bytearray_to_strings(
7885
7986@dataclass
8087class SamplefileDetails :
88+ """Convenience container for information about a sample file."""
89+
8190 filepath : Path
8291 datavar_data : np .ndarray
8392 stringcoord_data : np .ndarray
8493 numericcoord_data : np .ndarray
8594
8695
87- def make_testfile (testfile_path : Path , encoding_str : str ):
96+ def make_testfile (
97+ testfile_path : Path ,
98+ encoding_str : str ,
99+ coords_on_separate_dim : bool ,
100+ ) -> SamplefileDetails :
88101 """Create a test netcdf file.
89102
90- Also returns content strings (unicode or ascii versions) .
103+ Also returns content information for checking loaded results .
91104 """
92105 if encoding_str == NO_ENCODING_STR :
93106 encoding = None
@@ -115,7 +128,7 @@ def make_testfile(testfile_path: Path, encoding_str: str):
115128 try :
116129 ds .createDimension ("x" , N_XDIM )
117130 ds .createDimension ("nstr" , N_CHARS_DIM )
118- if COORD_ON_SEPARATE_DIM :
131+ if coords_on_separate_dim :
119132 ds .createDimension ("nstr2" , N_CHARS_DIM )
120133 v_xdim = ds .createVariable ("x" , int , dimensions = ("x" ))
121134 v_xdim [:] = np .arange (N_XDIM )
@@ -125,7 +138,7 @@ def make_testfile(testfile_path: Path, encoding_str: str):
125138 "S1" ,
126139 dimensions = (
127140 "x" ,
128- "nstr2" if COORD_ON_SEPARATE_DIM else "nstr" ,
141+ "nstr2" if coords_on_separate_dim else "nstr" ,
129142 ),
130143 )
131144 v_co [:] = coordvar_bytearray
@@ -177,17 +190,31 @@ def load_problems_list():
177190class TestReadEncodings :
178191 """Test loading of testfiles with encoded string data."""
179192
193+ @pytest .fixture (params = ["coordsSameDim" , "coordsOwnDim" ])
194+ def use_separate_dims (self , request ):
195+ yield request .param == "coordsOwnDim"
196+
180197 @pytest .fixture ()
181- def testdata (self , encoding , tmp_path ):
198+ def testdata (
199+ self ,
200+ encoding ,
201+ tmp_path ,
202+ use_separate_dims ,
203+ ):
182204 """Create a suitable valid testfile, and return expected string content."""
183205 if PERSIST_TESTFILES :
184206 tmp_path = Path (PERSIST_TESTFILES ).expanduser ()
185207 if encoding == "<noencoding>" :
186208 filetag = "noencoding"
187209 else :
188210 filetag = encoding
189- tempfile_path = tmp_path / f"sample_read_{ filetag } .nc"
190- testdata = make_testfile (testfile_path = tempfile_path , encoding_str = encoding )
211+ dimtag = "diffdims" if use_separate_dims else "samedims"
212+ tempfile_path = tmp_path / f"sample_read_{ filetag } _{ dimtag } .nc"
213+ testdata = make_testfile (
214+ testfile_path = tempfile_path ,
215+ encoding_str = encoding ,
216+ coords_on_separate_dim = use_separate_dims ,
217+ )
191218 from iris .tests .integration .netcdf .test_chararrays import ncdump
192219
193220 # TODO: temporary for debug -- TO REMOVE
0 commit comments