|
23 | 23 | from iris.coords import AuxCoord, Coord, DimCoord
|
24 | 24 | from iris.cube import Cube
|
25 | 25 | from iris.exceptions import UnitConversionError
|
| 26 | +from iris.tests import _shared_utils |
26 | 27 | from iris.tests.unit.coords import CoordTestMixin
|
27 | 28 | from iris.warnings import IrisVagueMetadataWarning
|
28 | 29 |
|
@@ -1177,16 +1178,35 @@ def test_coord_3d(self):
|
1177 | 1178 | coord._sanity_check_bounds()
|
1178 | 1179 |
|
1179 | 1180 |
|
1180 |
| -class Test_convert_units(tests.IrisTest): |
| 1181 | +class Test_convert_units: |
1181 | 1182 | def test_convert_unknown_units(self):
|
1182 | 1183 | coord = iris.coords.AuxCoord(1, units="unknown")
|
1183 | 1184 | emsg = (
|
1184 | 1185 | "Cannot convert from unknown units. "
|
1185 | 1186 | 'The "units" attribute may be set directly.'
|
1186 | 1187 | )
|
1187 |
| - with self.assertRaisesRegex(UnitConversionError, emsg): |
| 1188 | + with pytest.raises(UnitConversionError, match=emsg): |
1188 | 1189 | coord.convert_units("degrees")
|
1189 | 1190 |
|
| 1191 | + @pytest.mark.parametrize( |
| 1192 | + "attribute", |
| 1193 | + [ |
| 1194 | + "valid_min", |
| 1195 | + "valid_max", |
| 1196 | + "valid_range", |
| 1197 | + "actual_range", |
| 1198 | + ], |
| 1199 | + ) |
| 1200 | + def test_convert_attributes(self, attribute): |
| 1201 | + coord = iris.coords.AuxCoord(1, units="m") |
| 1202 | + value = np.array([0, 10]) if attribute.endswith("range") else 0 |
| 1203 | + coord.attributes[attribute] = value |
| 1204 | + coord.convert_units("ft") |
| 1205 | + converted_value = cf_units.Unit("m").convert(value, "ft") |
| 1206 | + _shared_utils.assert_array_all_close( |
| 1207 | + coord.attributes[attribute], converted_value |
| 1208 | + ) |
| 1209 | + |
1190 | 1210 |
|
1191 | 1211 | class Test___str__(tests.IrisTest):
|
1192 | 1212 | def test_short_time_interval(self):
|
|
0 commit comments