Skip to content

Commit

Permalink
Fix mergeback PR SciTools#4035 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bjlittle committed Aug 9, 2021
1 parent e7cb050 commit 611a575
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
8 changes: 6 additions & 2 deletions lib/iris/fileformats/_nc_load_rules/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions lib/iris/tests/test_netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 611a575

Please sign in to comment.