diff --git a/lib/iris/fileformats/_nc_load_rules/actions.py b/lib/iris/fileformats/_nc_load_rules/actions.py index 8351a7ea3b..e3b63d41d2 100644 --- a/lib/iris/fileformats/_nc_load_rules/actions.py +++ b/lib/iris/fileformats/_nc_load_rules/actions.py @@ -43,11 +43,15 @@ from functools import wraps import warnings +from iris.config import get_logger import iris.fileformats.cf import iris.fileformats.pp as pp from . import helpers as hh +# Configure the logger. +logger = get_logger(__name__, fmt="[%(funcName)s]") + def _default_rulenamesfunc(func_name): # A simple default function to deduce the rules-name from an action-name. @@ -397,9 +401,9 @@ def action_ukmo_stash(engine): engine.cube.attributes[attr_name] = attr_value msg = ( "Unable to set attribute STASH as not a valid MSI " - f'string "mXXsXXiXXX", got {attr_value}' + f'string "mXXsXXiXXX", got "{attr_value}"' ) - warnings.warn(msg) + logger.debug(msg) else: engine.cube.attributes["STASH"] = stash_code diff --git a/lib/iris/tests/test_netcdf.py b/lib/iris/tests/test_netcdf.py index 9348a66935..61dfc73580 100644 --- a/lib/iris/tests/test_netcdf.py +++ b/lib/iris/tests/test_netcdf.py @@ -632,8 +632,7 @@ def test_bad_um_stash_source(self): command = "ncgen -o {} {}".format(nc_path, cdl_path) check_call(command, shell=True) # Load with iris.fileformats.netcdf.load_cubes, and check expected content. - with self.assertWarns(UserWarning): - cubes = list(nc_load_cubes(nc_path)) + cubes = list(nc_load_cubes(nc_path)) self.assertEqual(len(cubes), 1) self.assertFalse(hasattr(cubes[0].attributes, "STASH")) self.assertEqual( diff --git a/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__miscellaneous.py b/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__miscellaneous.py index 4ed90fd79a..a8e44747dd 100644 --- a/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__miscellaneous.py +++ b/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__miscellaneous.py @@ -83,14 +83,16 @@ def test_stash_altname(self): self.check_result(cube, stashcode=self.stashcode) def test_stash_empty(self): - msg = "Expected STASH code MSI string" - with self.assertRaisesRegex(ValueError, msg): - self.run_testcase(ukmo__um_stash_source="") + value = "" + cube = self.run_testcase(ukmo__um_stash_source=value) + self.assertNotIn("STASH", cube.attributes) + self.assertEqual(cube.attributes["ukmo__um_stash_source"], value) def test_stash_invalid(self): - msg = "Expected STASH code MSI string" - with self.assertRaisesRegex(ValueError, msg): - self.run_testcase(ukmo__um_stash_source="XXX") + value = "XXX" + cube = self.run_testcase(ukmo__um_stash_source="XXX") + self.assertNotIn("STASH", cube.attributes) + self.assertEqual(cube.attributes["ukmo__um_stash_source"], value) def test_processflags_single(self): cube = self.run_testcase(ukmo__process_flags="this")