Skip to content
Merged
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
8 changes: 6 additions & 2 deletions lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -2424,7 +2424,7 @@ def vector_summary(
delta = max_line_offset - min_alignment + 5
cube_header = "%-*s (%s)" % (
int(name_padding + delta),
self.name() or "unknown",
nameunit,
dimension_header,
)
alignment += delta
Expand Down Expand Up @@ -2481,7 +2481,11 @@ def vector_summary(

# Calculate the maximum line offset.
max_line_offset = 0
for coord in all_coords:
for coord in (
list(all_coords)
+ self.ancillary_variables()
+ self.cell_measures()
):
max_line_offset = max(
max_line_offset,
len(
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/tests/results/cdm/str_repr/simple.__str__.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
thingness (foo: 11)
thingness / (1) (foo: 11)
Dimension coordinates:
foo x
Auxiliary coordinates:
Expand Down
52 changes: 52 additions & 0 deletions lib/iris/tests/unit/cube/test_Cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,58 @@ def test_similar_coords(self):
self.cube.add_aux_coord(coord)
self.assertIn("baz", self.cube.summary())

def test_long_components(self):
# Check that components with long names 'stretch' the printout correctly.
cube = Cube(np.zeros((20, 20, 20)), units=1)
dimco = DimCoord(np.arange(20), long_name="dimco")
auxco = AuxCoord(np.zeros(20), long_name="auxco")
ancil = AncillaryVariable(np.zeros(20), long_name="ancil")
cellm = CellMeasure(np.zeros(20), long_name="cellm")
cube.add_dim_coord(dimco, 0)
cube.add_aux_coord(auxco, 0)
cube.add_cell_measure(cellm, 1)
cube.add_ancillary_variable(ancil, 2)

original_summary = cube.summary()
long_name = "long_name______________________________________"
for component in (dimco, auxco, ancil, cellm):
# For each (type of) component, set a long name so the header columns get shifted.
old_name = component.name()
component.rename(long_name)
new_summary = cube.summary()
component.rename(
old_name
) # Put each back the way it was afterwards

# Check that the resulting 'stretched' output has dimension columns aligned correctly.
lines = new_summary.split("\n")
header = lines[0]
colon_inds = [
i_char for i_char, char in enumerate(header) if char == ":"
]
for line in lines[1:]:
# Replace all '-' with 'x' to make checking easier, and add a final buffer space.
line = line.replace("-", "x") + " "
if " x " in line:
# For lines with any columns : check that columns are where expected
for col_ind in colon_inds:
# Chop out chars before+after each expected column.
self.assertEqual(
line[col_ind - 1 : col_ind + 2], " x "
)

# Finally also: compare old with new, but replacing new name and ignoring spacing differences
def collapse_space(string):
# Replace all multiple spaces with a single space.
while " " in string:
string = string.replace(" ", " ")
return string

self.assertEqual(
collapse_space(new_summary).replace(long_name, old_name),
collapse_space(original_summary),
)


class Test_is_compatible(tests.IrisTest):
def setUp(self):
Expand Down