diff --git a/lib/iris/cube.py b/lib/iris/cube.py index aa234ea71d..26604ac0e6 100644 --- a/lib/iris/cube.py +++ b/lib/iris/cube.py @@ -1835,6 +1835,9 @@ def summary(self, shorten=False, name_padding=35): nameunit = '{name} / ({units})'.format(name=self.name(), units=self.units) + # If all unknown and a STASH attribute exists, use it. + if nameunit == 'unknown / (unknown)' and 'STASH' in self.attributes: + nameunit = '{}'.format(self.attributes['STASH']) cube_header = '{nameunit!s:{length}} ({dimension})'.format( length=name_padding, nameunit=nameunit, diff --git a/lib/iris/tests/unit/cube/test_CubeList.py b/lib/iris/tests/unit/cube/test_CubeList.py index 16ad9815c6..260da07c33 100644 --- a/lib/iris/tests/unit/cube/test_CubeList.py +++ b/lib/iris/tests/unit/cube/test_CubeList.py @@ -1,4 +1,4 @@ -# (C) British Crown Copyright 2014 - 2015, Met Office +# (C) British Crown Copyright 2014 - 2016, Met Office # # This file is part of Iris. # @@ -22,6 +22,7 @@ # Import iris.tests first so that some things can be initialised before # importing anything else. import iris.tests as tests +import iris.tests.stock from cf_units import Unit import numpy as np @@ -30,6 +31,7 @@ from iris.coords import AuxCoord, DimCoord import iris.coord_systems import iris.exceptions +from iris.fileformats.pp import STASH class Test_concatenate_cube(tests.IrisTest): @@ -276,5 +278,28 @@ def test_scalar_cube_data_constraint(self): self.assertEqual(res, expected) +class TestPrint(tests.IrisTest): + def setUp(self): + self.cubes = CubeList([iris.tests.stock.lat_lon_cube()]) + + def test_summary(self): + expected = ('0: unknown / (unknown) ' + ' (latitude: 3; longitude: 4)') + self.assertEqual(str(self.cubes), expected) + + def test_summary_name_unit(self): + self.cubes[0].long_name = 'aname' + self.cubes[0].units = '1' + expected = ('0: aname / (1) ' + ' (latitude: 3; longitude: 4)') + self.assertEqual(str(self.cubes), expected) + + def test_summary_stash(self): + self.cubes[0].attributes['STASH'] = STASH.from_msi('m01s00i004') + expected = ('0: m01s00i004 ' + ' (latitude: 3; longitude: 4)') + self.assertEqual(str(self.cubes), expected) + + if __name__ == "__main__": tests.main()