(self, recwarn)
| 2140 | |
| 2141 | @requires_netCDF4 |
| 2142 | def test_encoding_enum__no_fill_value(self, recwarn): |
| 2143 | with create_tmp_file() as tmp_file: |
| 2144 | cloud_type_dict = {"clear": 0, "cloudy": 1} |
| 2145 | with nc4.Dataset(tmp_file, mode="w") as nc: |
| 2146 | nc.createDimension("time", size=2) |
| 2147 | cloud_type = nc.createEnumType(np.uint8, "cloud_type", cloud_type_dict) |
| 2148 | v = nc.createVariable( |
| 2149 | "clouds", |
| 2150 | cloud_type, |
| 2151 | "time", |
| 2152 | fill_value=None, |
| 2153 | ) |
| 2154 | v[:] = 1 |
| 2155 | with open_dataset(tmp_file, engine="netcdf4") as original: |
| 2156 | # We don't expect any errors. |
| 2157 | # This is effectively a void context manager |
| 2158 | expected_warnings = 0 |
| 2159 | if self.engine == "h5netcdf": |
| 2160 | expected_warnings = 1 |
| 2161 | expected_msg = "Creating variable with default fill_value 0 which IS defined in enum type" |
| 2162 | |
| 2163 | with self.roundtrip(original) as actual: |
| 2164 | assert len(recwarn) == expected_warnings |
| 2165 | if expected_warnings: |
| 2166 | assert issubclass(recwarn[0].category, UserWarning) |
| 2167 | assert str(recwarn[0].message).startswith(expected_msg) |
| 2168 | assert_equal(original, actual) |
| 2169 | assert ( |
| 2170 | actual.clouds.encoding["dtype"].metadata["enum"] |
| 2171 | == cloud_type_dict |
| 2172 | ) |
| 2173 | |
| 2174 | @requires_netCDF4 |
| 2175 | def test_encoding_enum__multiple_variable_with_enum(self): |
nothing calls this directly
no test coverage detected