From 5fbff9257c0f5f8237865b8773010c00c3e0102b Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Thu, 22 Aug 2019 16:31:10 +0100 Subject: [PATCH 1/7] Fix bug with html_repr --- lib/iris/experimental/representation.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/iris/experimental/representation.py b/lib/iris/experimental/representation.py index 5adef1f06e..75666022aa 100644 --- a/lib/iris/experimental/representation.py +++ b/lib/iris/experimental/representation.py @@ -271,9 +271,14 @@ 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: + title = '' + body = line.strip() + 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)) From f23b87ff4a6e2bbc9ab704bd81e3c513ae82dfdc Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Thu, 22 Aug 2019 17:28:10 +0100 Subject: [PATCH 2/7] Add new lines to existing cells --- lib/iris/experimental/representation.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/iris/experimental/representation.py b/lib/iris/experimental/representation.py index 75666022aa..2e333efa81 100644 --- a/lib/iris/experimental/representation.py +++ b/lib/iris/experimental/representation.py @@ -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. # @@ -258,6 +258,11 @@ def _make_row(self, title, body=None, col_span=0): row.append('') return row + def _expand_last_cell(self, element, body): + split_point = element.index('') + element = element[:split_point] + '
' + body + element[split_point:] + return element + def _make_content(self): elements = [] for k, v in self.str_headings.items(): @@ -274,8 +279,11 @@ def _make_content(self): try: split_point = line.index(':') except ValueError: - title = '' body = line.strip() + 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() From a85a499d637bf45df5b70741a1fe81336a6057ed Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Thu, 22 Aug 2019 17:32:45 +0100 Subject: [PATCH 3/7] Format license headers --- lib/iris/experimental/representation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/iris/experimental/representation.py b/lib/iris/experimental/representation.py index 2e333efa81..afca00c217 100644 --- a/lib/iris/experimental/representation.py +++ b/lib/iris/experimental/representation.py @@ -1,4 +1,4 @@ -# (C) British Crown Copyright 2018-2019, Met Office +# (C) British Crown Copyright 2018 - 2019, Met Office # # This file is part of Iris. # From 98e5201db68ae9d9f567e839e7e850ac8cac9c78 Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Fri, 23 Aug 2019 11:53:26 +0100 Subject: [PATCH 4/7] Added tests --- .../representation/test_CubeRepresentation.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/iris/tests/unit/experimental/representation/test_CubeRepresentation.py b/lib/iris/tests/unit/experimental/representation/test_CubeRepresentation.py index c94742a49a..e9ed5c34e0 100644 --- a/lib/iris/tests/unit/experimental/representation/test_CubeRepresentation.py +++ b/lib/iris/tests/unit/experimental/representation/test_CubeRepresentation.py @@ -290,6 +290,20 @@ 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
second', cell) + @tests.skip_data class Test__make_content(tests.IrisTest): def setUp(self): @@ -312,6 +326,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
second', result) + @tests.skip_data class Test_repr_html(tests.IrisTest): From d66611482987ad960f5065f3dba2714b9b667d44 Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Fri, 23 Aug 2019 12:35:01 +0100 Subject: [PATCH 5/7] Updated license --- .../unit/experimental/representation/test_CubeRepresentation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/iris/tests/unit/experimental/representation/test_CubeRepresentation.py b/lib/iris/tests/unit/experimental/representation/test_CubeRepresentation.py index e9ed5c34e0..027d699789 100644 --- a/lib/iris/tests/unit/experimental/representation/test_CubeRepresentation.py +++ b/lib/iris/tests/unit/experimental/representation/test_CubeRepresentation.py @@ -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. # From 8820f0e0a258b43e993b9723ffeab7e513e0dcb3 Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Wed, 4 Sep 2019 09:55:42 +0100 Subject: [PATCH 6/7] Add whitespace --- .../unit/experimental/representation/test_CubeRepresentation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/iris/tests/unit/experimental/representation/test_CubeRepresentation.py b/lib/iris/tests/unit/experimental/representation/test_CubeRepresentation.py index 027d699789..fa05c00abf 100644 --- a/lib/iris/tests/unit/experimental/representation/test_CubeRepresentation.py +++ b/lib/iris/tests/unit/experimental/representation/test_CubeRepresentation.py @@ -304,6 +304,7 @@ def test_add_line(self): cell = self.representer._expand_last_cell(self.row[-2], 'second') self.assertIn('first
second', cell) + @tests.skip_data class Test__make_content(tests.IrisTest): def setUp(self): From 76f502905fd5ec9c0cc4fef9bcfd44e49ad22d5b Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Wed, 4 Sep 2019 11:52:35 +0100 Subject: [PATCH 7/7] Added comments --- lib/iris/experimental/representation.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/iris/experimental/representation.py b/lib/iris/experimental/representation.py index afca00c217..ed431c29d6 100644 --- a/lib/iris/experimental/representation.py +++ b/lib/iris/experimental/representation.py @@ -259,6 +259,7 @@ def _make_row(self, title, body=None, col_span=0): return row def _expand_last_cell(self, element, body): + '''Expand an element containing a cell by adding a new line.''' split_point = element.index('') element = element[:split_point] + '
' + body + element[split_point:] return element @@ -279,7 +280,13 @@ def _make_content(self): 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