1111from os .path import join as path_join
1212import shutil
1313import tempfile
14+ import warnings
15+
16+ import pytest
1417
1518import iris
1619from iris .coords import DimCoord
@@ -135,15 +138,25 @@ def test_load_datum_wkt(self):
135138 cube = iris .load_cube (nc_path )
136139 test_crs = cube .coord ("projection_y_coordinate" ).coord_system
137140 actual = str (test_crs .as_cartopy_crs ().datum )
138- self . assertMultiLineEqual ( expected , actual )
141+ assert actual == expected
139142
140143 def test_no_load_datum_wkt (self ):
141144 nc_path = tlc .cdl_to_nc (self .datum_wkt_cdl )
142- with self . assertWarnsRegex (FutureWarning , "iris.FUTURE.datum_support" ):
145+ with pytest . warns (FutureWarning , match = "iris.FUTURE.datum_support" ):
143146 cube = iris .load_cube (nc_path )
144147 test_crs = cube .coord ("projection_y_coordinate" ).coord_system
145148 actual = str (test_crs .as_cartopy_crs ().datum )
146- self .assertMultiLineEqual (actual , "unknown" )
149+ assert actual == "unknown"
150+
151+ def test_no_datum_no_warn (self ):
152+ new_cdl = self .datum_wkt_cdl .splitlines ()
153+ new_cdl = [line for line in new_cdl if "DATUM" not in line ]
154+ new_cdl = "\n " .join (new_cdl )
155+ nc_path = tlc .cdl_to_nc (new_cdl )
156+ with warnings .catch_warnings ():
157+ # pytest's recommended way to assert for no warnings.
158+ warnings .simplefilter ("error" , FutureWarning )
159+ _ = iris .load_cube (nc_path )
147160
148161 def test_load_datum_cf_var (self ):
149162 expected = "OSGB 1936"
@@ -152,15 +165,15 @@ def test_load_datum_cf_var(self):
152165 cube = iris .load_cube (nc_path )
153166 test_crs = cube .coord ("projection_y_coordinate" ).coord_system
154167 actual = str (test_crs .as_cartopy_crs ().datum )
155- self . assertMultiLineEqual ( expected , actual )
168+ assert actual == expected
156169
157170 def test_no_load_datum_cf_var (self ):
158171 nc_path = tlc .cdl_to_nc (self .datum_cf_var_cdl )
159- with self . assertWarnsRegex (FutureWarning , "iris.FUTURE.datum_support" ):
172+ with pytest . warns (FutureWarning , match = "iris.FUTURE.datum_support" ):
160173 cube = iris .load_cube (nc_path )
161174 test_crs = cube .coord ("projection_y_coordinate" ).coord_system
162175 actual = str (test_crs .as_cartopy_crs ().datum )
163- self . assertMultiLineEqual ( actual , "unknown" )
176+ assert actual == "unknown"
164177
165178 def test_save_datum (self ):
166179 expected = "OSGB 1936"
@@ -199,7 +212,7 @@ def test_save_datum(self):
199212
200213 test_crs = cube .coord ("projection_y_coordinate" ).coord_system
201214 actual = str (test_crs .as_cartopy_crs ().datum )
202- self . assertMultiLineEqual ( expected , actual )
215+ assert actual == expected
203216
204217
205218class TestLoadMinimalGeostationary (tests .IrisTest ):
@@ -270,9 +283,9 @@ def test_geostationary_no_false_offsets(self):
270283 cube = iris .load_cube (self .path_test_nc )
271284 # Check the coordinate system properties has the correct default properties.
272285 cs = cube .coord_system ()
273- self . assertIsInstance (cs , iris .coord_systems .Geostationary )
274- self . assertEqual ( cs .false_easting , 0.0 )
275- self . assertEqual ( cs .false_northing , 0.0 )
286+ assert isinstance (cs , iris .coord_systems .Geostationary )
287+ assert cs .false_easting == 0.0
288+ assert cs .false_northing == 0.0
276289
277290
278291if __name__ == "__main__" :
0 commit comments