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
28 changes: 24 additions & 4 deletions lib/iris/experimental/representation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2018, Met Office
# (C) British Crown Copyright 2018 - 2019, Met Office
#
# This file is part of Iris.
#
Expand Down Expand Up @@ -258,6 +258,12 @@ def _make_row(self, title, body=None, col_span=0):
row.append('</tr>')
return row

def _expand_last_cell(self, element, body):
'''Expand an element containing a cell by adding a new line.'''
split_point = element.index('</td>')
element = element[:split_point] + '<br>' + body + element[split_point:]
return element

def _make_content(self):
elements = []
for k, v in self.str_headings.items():
Expand All @@ -271,9 +277,23 @@ def _make_content(self):
title = body.pop(0)
colspan = 0
else:
split_point = line.index(':')
title = line[:split_point].strip()
body = line[split_point + 2:].strip()
try:
split_point = line.index(':')
except ValueError:
# When a line exists in v without a ':', we expect
# that this is due to the value of some attribute
# containing multiple lines. We collect all these
# lines in the same cell.
body = line.strip()
# We choose the element containing the last cell
# in the last row.
element = elements[-2]
element = self._expand_last_cell(element, body)
elements[-2] = element
continue
else:
title = line[:split_point].strip()
body = line[split_point + 2:].strip()
colspan = self.ndims
elements.extend(
self._make_row(title, body=body, col_span=colspan))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2017 - 2018, Met Office
# (C) British Crown Copyright 2017 - 2019, Met Office
#
# This file is part of Iris.
#
Expand Down Expand Up @@ -290,6 +290,21 @@ def test__attribute_row(self):
self.assertIn(colspan_str, row_str)


@tests.skip_data
class Test__expand_last_cell(tests.IrisTest):
def setUp(self):
self.cube = stock.simple_3d()
self.representer = CubeRepresentation(self.cube)
self.representer._get_bits(self.representer._get_lines())
col_span = self.representer.ndims
self.row = self.representer._make_row('title', body='first',
col_span=col_span)

def test_add_line(self):
cell = self.representer._expand_last_cell(self.row[-2], 'second')
self.assertIn('first<br>second', cell)


@tests.skip_data
class Test__make_content(tests.IrisTest):
def setUp(self):
Expand All @@ -312,6 +327,14 @@ def test_not_included(self):
for heading in not_included:
self.assertNotIn(heading, self.result)

def test_handle_newline(self):
cube = self.cube
cube.attributes['lines'] = 'first\nsecond'
representer = CubeRepresentation(cube)
representer._get_bits(representer._get_lines())
result = representer._make_content()
self.assertIn('first<br>second', result)


@tests.skip_data
class Test_repr_html(tests.IrisTest):
Expand Down