Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 26 additions & 1 deletion lib/iris/tests/unit/cube/test_CubeList.py
Original file line number Diff line number Diff line change
@@ -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.
#
Expand All @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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()