class Test__make_content(tests.IrisTest):
    def setUp(self):
        self.cube = stock.simple_3d()
        self.representer = CubeRepresentation(self.cube)
        self.representer._get_bits(self.representer._get_lines())
        self.result = self.representer._make_content()

    def test_included(self):
        included = 'Dimension coordinates'
        self.assertIn(included, self.result)
        dim_coord_names = [c.name() for c in self.cube.dim_coords]
        for coord_name in dim_coord_names:
            self.assertIn(coord_name, self.result)

    def test_not_included(self):
        # `stock.simple_3d()` only contains the `Dimension coordinates` attr.
        not_included = list(self.representer.str_headings.keys())
        not_included.pop(not_included.index('Dimension coordinates:'))
        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)
Beispiel #2
0
class Test__make_header(tests.IrisTest):
    def setUp(self):
        self.cube = stock.simple_3d()
        self.representer = CubeRepresentation(self.cube)
        self.representer._get_bits(self.representer._get_lines())
        self.header_emts = self.representer._make_header().split('\n')

    def test_name_and_units(self):
        # Check the correct name and units are being written into the top-left
        # table cell.
        # This is found in the first cell after the `<th>` is defined.
        name_and_units_cell = self.header_emts[1]
        expected = '{name} ({units})'.format(name=self.cube.name(),
                                             units=self.cube.units)
        self.assertIn(expected.lower(), name_and_units_cell.lower())

    def test_number_of_columns(self):
        # There should be one headings column, plus a column per dimension.
        # Ignore opening and closing <tr> tags.
        result_cols = self.header_emts[1:-1]
        expected = self.cube.ndim + 1
        self.assertEqual(len(result_cols), expected)

    def test_row_headings(self):
        # Get only the dimension heading cells and not the headings column.
        dim_coord_names = [c.name() for c in self.cube.coords(dim_coords=True)]
        dim_col_headings = self.header_emts[2:-1]
        for coord_name, col_heading in zip(dim_coord_names, dim_col_headings):
            self.assertIn(coord_name, col_heading)
class Test__get_dim_names(tests.IrisTest):
    def setUp(self):
        self.cube = stock.realistic_4d()
        self.dim_names = [c.name() for c in self.cube.coords(dim_coords=True)]
        self.representer = CubeRepresentation(self.cube)

    def test_basic(self):
        result_names = self.representer._get_dim_names()
        self.assertEqual(result_names, self.dim_names)

    def test_one_anonymous_dim(self):
        self.cube.remove_coord('time')
        expected_names = ['--']
        expected_names.extend(self.dim_names[1:])
        result_names = self.representer._get_dim_names()
        self.assertEqual(result_names, expected_names)

    def test_anonymous_dims(self):
        target_dims = [1, 3]
        # Replicate this here as we're about to modify it.
        expected_names = [c.name() for c in self.cube.coords(dim_coords=True)]
        for dim in target_dims:
            this_dim_coord, = self.cube.coords(contains_dimension=dim,
                                               dim_coords=True)
            self.cube.remove_coord(this_dim_coord)
            expected_names[dim] = '--'
        result_names = self.representer._get_dim_names()
        self.assertEqual(result_names, expected_names)
class TestNoMetadata(tests.IrisTest):
    # Test the situation where we have a cube with no metadata at all.
    def setUp(self):
        self.shape = (2, 3, 4)
        self.cube = Cube(np.arange(24).reshape(self.shape))
        self.representer = CubeRepresentation(self.cube)
        self.representer.repr_html()

    def test_cube_name(self):
        expected = 'Unknown'  # This cube has no metadata.
        result = self.representer.name
        self.assertEqual(expected, result)

    def test_cube_units(self):
        expected = 'unknown'  # This cube has no metadata.
        result = self.representer.units
        self.assertEqual(expected, result)

    def test_dim_names(self):
        expected = ['--'] * len(self.shape)
        result = self.representer.names
        self.assertEqual(expected, result)

    def test_shape(self):
        result = self.representer.shapes
        self.assertEqual(result, self.shape)
class TestNoMetadata(tests.IrisTest):
    # Test the situation where we have a cube with no metadata at all.
    def setUp(self):
        self.shape = (2, 3, 4)
        self.cube = Cube(np.arange(24).reshape(self.shape))
        self.representer = CubeRepresentation(self.cube)
        self.representer.repr_html()

    def test_cube_name(self):
        expected = 'Unknown'  # This cube has no metadata.
        result = self.representer.name
        self.assertEqual(expected, result)

    def test_cube_units(self):
        expected = 'unknown'  # This cube has no metadata.
        result = self.representer.units
        self.assertEqual(expected, result)

    def test_dim_names(self):
        expected = ['--'] * len(self.shape)
        result = self.representer.names
        self.assertEqual(expected, result)

    def test_shape(self):
        result = self.representer.shapes
        self.assertEqual(result, self.shape)
Beispiel #6
0
class Test__get_dim_names(tests.IrisTest):
    def setUp(self):
        self.cube = stock.realistic_4d()
        self.dim_names = [c.name() for c in self.cube.coords(dim_coords=True)]
        self.representer = CubeRepresentation(self.cube)

    def test_basic(self):
        result_names = self.representer._get_dim_names()
        self.assertEqual(result_names, self.dim_names)

    def test_one_anonymous_dim(self):
        self.cube.remove_coord('time')
        expected_names = ['--']
        expected_names.extend(self.dim_names[1:])
        result_names = self.representer._get_dim_names()
        self.assertEqual(result_names, expected_names)

    def test_anonymous_dims(self):
        target_dims = [1, 3]
        # Replicate this here as we're about to modify it.
        expected_names = [c.name() for c in self.cube.coords(dim_coords=True)]
        for dim in target_dims:
            this_dim_coord, = self.cube.coords(contains_dimension=dim,
                                               dim_coords=True)
            self.cube.remove_coord(this_dim_coord)
            expected_names[dim] = '--'
        result_names = self.representer._get_dim_names()
        self.assertEqual(result_names, expected_names)
Beispiel #7
0
 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)
class Test__make_header(tests.IrisTest):
    def setUp(self):
        self.cube = stock.simple_3d()
        self.representer = CubeRepresentation(self.cube)
        self.representer._get_bits(self.representer._get_lines())
        self.header_emts = self.representer._make_header().split('\n')

    def test_name_and_units(self):
        # Check the correct name and units are being written into the top-left
        # table cell.
        # This is found in the first cell after the `<th>` is defined.
        name_and_units_cell = self.header_emts[1]
        expected = '{name} ({units})'.format(name=self.cube.name(),
                                             units=self.cube.units)
        self.assertIn(expected.lower(), name_and_units_cell.lower())

    def test_number_of_columns(self):
        # There should be one headings column, plus a column per dimension.
        # Ignore opening and closing <tr> tags.
        result_cols = self.header_emts[1:-1]
        expected = self.cube.ndim + 1
        self.assertEqual(len(result_cols), expected)

    def test_row_headings(self):
        # Get only the dimension heading cells and not the headings column.
        dim_coord_names = [c.name() for c in self.cube.coords(dim_coords=True)]
        dim_col_headings = self.header_emts[2:-1]
        for coord_name, col_heading in zip(dim_coord_names, dim_col_headings):
            self.assertIn(coord_name, col_heading)
 def test_no_attrs(self):
     self.cube.attributes = {}
     representer = CubeRepresentation(self.cube)
     result = representer.repr_html().lower()
     self.assertIn('dimension coordinates', result)
     self.assertIn('auxiliary coordinates', result)
     self.assertIn('scalar coordinates', result)
     self.assertNotIn('attributes', result)
 def test_no_attrs(self):
     self.cube.attributes = {}
     representer = CubeRepresentation(self.cube)
     result = representer.repr_html().lower()
     self.assertIn('dimension coordinates', result)
     self.assertIn('auxiliary coordinates', result)
     self.assertIn('scalar coordinates', result)
     self.assertNotIn('attributes', result)
Beispiel #11
0
class Test__get_bits(tests.IrisTest):
    def setUp(self):
        self.cube = stock.realistic_4d()
        cm = CellMethod('mean', 'time', '6hr')
        self.cube.add_cell_method(cm)
        self.representer = CubeRepresentation(self.cube)
        self.representer._get_bits(self.representer._get_lines())

    def test_population(self):
        for v in self.representer.str_headings.values():
            self.assertIsNotNone(v)

    def test_headings__dimcoords(self):
        contents = self.representer.str_headings['Dimension coordinates:']
        content_str = ','.join(content for content in contents)
        dim_coords = [c.name() for c in self.cube.dim_coords]
        for coord in dim_coords:
            self.assertIn(coord, content_str)

    def test_headings__auxcoords(self):
        contents = self.representer.str_headings['Auxiliary coordinates:']
        content_str = ','.join(content for content in contents)
        aux_coords = [
            c.name() for c in self.cube.aux_coords if c.shape != (1, )
        ]
        for coord in aux_coords:
            self.assertIn(coord, content_str)

    def test_headings__derivedcoords(self):
        contents = self.representer.str_headings['Auxiliary coordinates:']
        content_str = ','.join(content for content in contents)
        derived_coords = [c.name() for c in self.cube.derived_coords]
        for coord in derived_coords:
            self.assertIn(coord, content_str)

    def test_headings__scalarcoords(self):
        contents = self.representer.str_headings['Scalar coordinates:']
        content_str = ','.join(content for content in contents)
        scalar_coords = [
            c.name() for c in self.cube.coords() if c.shape == (1, )
        ]
        for coord in scalar_coords:
            self.assertIn(coord, content_str)

    def test_headings__attributes(self):
        contents = self.representer.str_headings['Attributes:']
        content_str = ','.join(content for content in contents)
        for attr_name, attr_value in self.cube.attributes.items():
            self.assertIn(attr_name, content_str)
            self.assertIn(attr_value, content_str)

    def test_headings__cellmethods(self):
        contents = self.representer.str_headings['Cell methods:']
        content_str = ','.join(content for content in contents)
        for cell_method in self.cube.cell_methods:
            self.assertIn(str(cell_method), content_str)
Beispiel #12
0
 def test_no_coords(self):
     all_coords = [coord.name() for coord in self.cube.coords()]
     for coord in all_coords:
         self.cube.remove_coord(coord)
     representer = CubeRepresentation(self.cube)
     result = representer.repr_html().lower()
     self.assertNotIn("dimension coordinates", result)
     self.assertNotIn("auxiliary coordinates", result)
     self.assertNotIn("scalar coordinates", result)
     self.assertIn("attributes", result)
 def test_no_dim_coords(self):
     dim_coords = [c.name() for c in self.cube.coords(dim_coords=True)]
     for coord in dim_coords:
         self.cube.remove_coord(coord)
     representer = CubeRepresentation(self.cube)
     result = representer.repr_html().lower()
     self.assertNotIn('dimension coordinates', result)
     self.assertIn('auxiliary coordinates', result)
     self.assertIn('scalar coordinates', result)
     self.assertIn('attributes', result)
 def test_no_dim_coords(self):
     dim_coords = [c.name() for c in self.cube.coords(dim_coords=True)]
     for coord in dim_coords:
         self.cube.remove_coord(coord)
     representer = CubeRepresentation(self.cube)
     result = representer.repr_html().lower()
     self.assertNotIn('dimension coordinates', result)
     self.assertIn('auxiliary coordinates', result)
     self.assertIn('scalar coordinates', result)
     self.assertIn('attributes', result)
 def test_no_scalar_coords(self):
     aux_coords = ['air_pressure']
     for coord in aux_coords:
         self.cube.remove_coord(coord)
     representer = CubeRepresentation(self.cube)
     result = representer.repr_html().lower()
     self.assertIn('dimension coordinates', result)
     self.assertIn('auxiliary coordinates', result)
     self.assertNotIn('scalar coordinates', result)
     self.assertIn('attributes', result)
 def test_no_scalar_coords(self):
     aux_coords = ['air_pressure']
     for coord in aux_coords:
         self.cube.remove_coord(coord)
     representer = CubeRepresentation(self.cube)
     result = representer.repr_html().lower()
     self.assertIn('dimension coordinates', result)
     self.assertIn('auxiliary coordinates', result)
     self.assertNotIn('scalar coordinates', result)
     self.assertIn('attributes', result)
Beispiel #17
0
 def test_no_aux_coords(self):
     aux_coords = ["forecast_period"]
     for coord in aux_coords:
         self.cube.remove_coord(coord)
     representer = CubeRepresentation(self.cube)
     result = representer.repr_html().lower()
     self.assertIn("dimension coordinates", result)
     self.assertNotIn("auxiliary coordinates", result)
     self.assertIn("scalar coordinates", result)
     self.assertIn("attributes", result)
class Test__get_bits(tests.IrisTest):
    def setUp(self):
        self.cube = stock.realistic_4d()
        cm = CellMethod('mean', 'time', '6hr')
        self.cube.add_cell_method(cm)
        self.representer = CubeRepresentation(self.cube)
        self.representer._get_bits(self.representer._get_lines())

    def test_population(self):
        for v in self.representer.str_headings.values():
            self.assertIsNotNone(v)

    def test_headings__dimcoords(self):
        contents = self.representer.str_headings['Dimension coordinates:']
        content_str = ','.join(content for content in contents)
        dim_coords = [c.name() for c in self.cube.dim_coords]
        for coord in dim_coords:
            self.assertIn(coord, content_str)

    def test_headings__auxcoords(self):
        contents = self.representer.str_headings['Auxiliary coordinates:']
        content_str = ','.join(content for content in contents)
        aux_coords = [c.name() for c in self.cube.aux_coords
                      if c.shape != (1,)]
        for coord in aux_coords:
            self.assertIn(coord, content_str)

    def test_headings__derivedcoords(self):
        contents = self.representer.str_headings['Auxiliary coordinates:']
        content_str = ','.join(content for content in contents)
        derived_coords = [c.name() for c in self.cube.derived_coords]
        for coord in derived_coords:
            self.assertIn(coord, content_str)

    def test_headings__scalarcoords(self):
        contents = self.representer.str_headings['Scalar coordinates:']
        content_str = ','.join(content for content in contents)
        scalar_coords = [c.name() for c in self.cube.coords()
                         if c.shape == (1,)]
        for coord in scalar_coords:
            self.assertIn(coord, content_str)

    def test_headings__attributes(self):
        contents = self.representer.str_headings['Attributes:']
        content_str = ','.join(content for content in contents)
        for attr_name, attr_value in self.cube.attributes.items():
            self.assertIn(attr_name, content_str)
            self.assertIn(attr_value, content_str)

    def test_headings__cellmethods(self):
        contents = self.representer.str_headings['Cell methods:']
        content_str = ','.join(content for content in contents)
        for cell_method in self.cube.cell_methods:
            self.assertIn(str(cell_method), content_str)
 def setUp(self):
     self.cube = stock.realistic_4d()
     cmth = CellMethod("mean", "time", "6hr")
     self.cube.add_cell_method(cmth)
     cms = CellMeasure([0, 1, 2, 3, 4, 5], long_name="foo")
     self.cube.add_cell_measure(cms, 0)
     avr = AncillaryVariable([0, 1, 2, 3, 4, 5], long_name="bar")
     self.cube.add_ancillary_variable(avr, 0)
     scms = CellMeasure([0], long_name="baz")
     self.cube.add_cell_measure(scms)
     self.representer = CubeRepresentation(self.cube)
     self.representer._get_bits(self.representer._get_lines())
Beispiel #20
0
 def setUp(self):
     self.cube = stock.realistic_4d()
     cmth = CellMethod('mean', 'time', '6hr')
     self.cube.add_cell_method(cmth)
     cms = CellMeasure([0, 1, 2, 3, 4, 5], measure='area', long_name='foo')
     self.cube.add_cell_measure(cms, 0)
     avr = AncillaryVariable([0, 1, 2, 3, 4, 5], long_name='bar')
     self.cube.add_ancillary_variable(avr, 0)
     scms = CellMeasure([0], measure='area', long_name='baz')
     self.cube.add_cell_measure(scms)
     self.representer = CubeRepresentation(self.cube)
     self.representer._get_bits(self.representer._get_lines())
Beispiel #21
0
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)
Beispiel #22
0
class Test__make_shapes_row(tests.IrisTest):
    def setUp(self):
        self.cube = stock.simple_3d()
        self.representer = CubeRepresentation(self.cube)
        self.representer._get_bits(self.representer._get_lines())
        self.result = self.representer._make_shapes_row().split('\n')

    def test_row_title(self):
        title_cell = self.result[1]
        self.assertIn('Shape', title_cell)

    def test_shapes(self):
        expected_shapes = self.cube.shape
        result_shapes = self.result[2:-1]
        for expected, result in zip(expected_shapes, result_shapes):
            self.assertIn(str(expected), result)
class Test__make_shapes_row(tests.IrisTest):
    def setUp(self):
        self.cube = stock.simple_3d()
        self.representer = CubeRepresentation(self.cube)
        self.representer._get_bits(self.representer._get_lines())
        self.result = self.representer._make_shapes_row().split('\n')

    def test_row_title(self):
        title_cell = self.result[1]
        self.assertIn('Shape', title_cell)

    def test_shapes(self):
        expected_shapes = self.cube.shape
        result_shapes = self.result[2:-1]
        for expected, result in zip(expected_shapes, result_shapes):
            self.assertIn(str(expected), result)
class Test__make_content(tests.IrisTest):
    def setUp(self):
        self.cube = stock.simple_3d()
        self.representer = CubeRepresentation(self.cube)
        self.representer._get_bits(self.representer._get_lines())
        self.result = self.representer._make_content()

    def test_included(self):
        included = 'Dimension coordinates'
        self.assertIn(included, self.result)
        dim_coord_names = [c.name() for c in self.cube.dim_coords]
        for coord_name in dim_coord_names:
            self.assertIn(coord_name, self.result)

    def test_not_included(self):
        # `stock.simple_3d()` only contains the `Dimension coordinates` attr.
        not_included = list(self.representer.str_headings.keys())
        not_included.pop(not_included.index('Dimension coordinates:'))
        for heading in not_included:
            self.assertNotIn(heading, self.result)
class Test__make_content(tests.IrisTest):
    def setUp(self):
        self.cube = stock.simple_3d()
        self.representer = CubeRepresentation(self.cube)
        self.representer._get_bits(self.representer._get_lines())
        self.result = self.representer._make_content()

    def test_included(self):
        included = "Dimension coordinates"
        self.assertIn(included, self.result)
        dim_coord_names = [c.name() for c in self.cube.dim_coords]
        for coord_name in dim_coord_names:
            self.assertIn(coord_name, self.result)

    def test_not_included(self):
        # `stock.simple_3d()` only contains the `Dimension coordinates` attr.
        not_included = list(self.representer.str_headings.keys())
        not_included.pop(not_included.index("Dimension coordinates:"))
        for heading in not_included:
            self.assertNotIn(heading, self.result)
class Test__make_row(tests.IrisTest):
    def setUp(self):
        self.cube = stock.simple_3d()
        cm = CellMethod('mean', 'time', '6hr')
        self.cube.add_cell_method(cm)
        self.representer = CubeRepresentation(self.cube)
        self.representer._get_bits(self.representer._get_lines())

    def test__title_row(self):
        title = 'Wibble:'
        row = self.representer._make_row(title)
        # A cell for the title, an empty cell for each cube dimension, plus row
        # opening and closing tags.
        expected_len = self.cube.ndim + 3
        self.assertEqual(len(row), expected_len)
        # Check for specific content.
        row_str = '\n'.join(element for element in row)
        self.assertIn(title.strip(':'), row_str)
        expected_html_class = 'iris-title'
        self.assertIn(expected_html_class, row_str)

    def test__inclusion_row(self):
        # An inclusion row has x/- to indicate whether a coordinate describes
        # a dimension.
        title = 'time'
        body = ['x', '-', '-', '-']
        row = self.representer._make_row(title, body)
        # A cell for the title, a cell for each cube dimension, plus row
        # opening and closing tags.
        expected_len = len(body) + 3
        self.assertEqual(len(row), expected_len)
        # Check for specific content.
        row_str = '\n'.join(element for element in row)
        self.assertIn(title, row_str)
        self.assertIn('x', row_str)
        self.assertIn('-', row_str)
        expected_html_class_1 = 'iris-word-cell'
        expected_html_class_2 = 'iris-inclusion-cell'
        self.assertIn(expected_html_class_1, row_str)
        self.assertIn(expected_html_class_2, row_str)
        # We do not expect a colspan to be set.
        self.assertNotIn('colspan', row_str)

    def test__attribute_row(self):
        # An attribute row does not contain inclusion indicators.
        title = 'source'
        body = 'Iris test case'
        colspan = 5
        row = self.representer._make_row(title, body, colspan)
        # We only expect two cells here: the row title cell and one other cell
        # that spans a number of columns. We also need to open and close the
        # tr html element, giving 4 bits making up the row.
        self.assertEqual(len(row), 4)
        # Check for specific content.
        row_str = '\n'.join(element for element in row)
        self.assertIn(title, row_str)
        self.assertIn(body, row_str)
        # We expect a colspan to be set.
        colspan_str = 'colspan="{}"'.format(colspan)
        self.assertIn(colspan_str, row_str)
Beispiel #27
0
class Test__make_row(tests.IrisTest):
    def setUp(self):
        self.cube = stock.simple_3d()
        cm = CellMethod('mean', 'time', '6hr')
        self.cube.add_cell_method(cm)
        self.representer = CubeRepresentation(self.cube)
        self.representer._get_bits(self.representer._get_lines())

    def test__title_row(self):
        title = 'Wibble:'
        row = self.representer._make_row(title)
        # A cell for the title, an empty cell for each cube dimension, plus row
        # opening and closing tags.
        expected_len = self.cube.ndim + 3
        self.assertEqual(len(row), expected_len)
        # Check for specific content.
        row_str = '\n'.join(element for element in row)
        self.assertIn(title.strip(':'), row_str)
        expected_html_class = 'iris-title'
        self.assertIn(expected_html_class, row_str)

    def test__inclusion_row(self):
        # An inclusion row has x/- to indicate whether a coordinate describes
        # a dimension.
        title = 'time'
        body = ['x', '-', '-', '-']
        row = self.representer._make_row(title, body)
        # A cell for the title, a cell for each cube dimension, plus row
        # opening and closing tags.
        expected_len = len(body) + 3
        self.assertEqual(len(row), expected_len)
        # Check for specific content.
        row_str = '\n'.join(element for element in row)
        self.assertIn(title, row_str)
        self.assertIn('x', row_str)
        self.assertIn('-', row_str)
        expected_html_class_1 = 'iris-word-cell'
        expected_html_class_2 = 'iris-inclusion-cell'
        self.assertIn(expected_html_class_1, row_str)
        self.assertIn(expected_html_class_2, row_str)
        # We do not expect a colspan to be set.
        self.assertNotIn('colspan', row_str)

    def test__attribute_row(self):
        # An attribute row does not contain inclusion indicators.
        title = 'source'
        body = 'Iris test case'
        colspan = 5
        row = self.representer._make_row(title, body, colspan)
        # We only expect two cells here: the row title cell and one other cell
        # that spans a number of columns. We also need to open and close the
        # tr html element, giving 4 bits making up the row.
        self.assertEqual(len(row), 4)
        # Check for specific content.
        row_str = '\n'.join(element for element in row)
        self.assertIn(title, row_str)
        self.assertIn(body, row_str)
        # We expect a colspan to be set.
        colspan_str = 'colspan="{}"'.format(colspan)
        self.assertIn(colspan_str, row_str)
 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)
class TestScalarCube(tests.IrisTest):
    def setUp(self):
        self.cube = stock.realistic_3d()[0, 0, 0]
        self.representer = CubeRepresentation(self.cube)
        self.representer.repr_html()

    def test_identfication(self):
        # Is this scalar cube accurately identified?
        self.assertTrue(self.representer.scalar_cube)

    def test_header__name(self):
        header = self.representer._make_header()
        expected_name = self.cube.name().title().replace('_', ' ')
        self.assertIn(expected_name, header)

    def test_header__units(self):
        header = self.representer._make_header()
        expected_units = self.cube.units.symbol
        self.assertIn(expected_units, header)

    def test_header__scalar_str(self):
        # Check that 'scalar cube' is placed in the header.
        header = self.representer._make_header()
        expected_str = '(scalar cube)'
        self.assertIn(expected_str, header)

    def test_content__scalars(self):
        # Check an element "Scalar coordinates" is present in the main content.
        content = self.representer._make_content()
        expected_str = 'Scalar coordinates'
        self.assertIn(expected_str, content)

    def test_content__specific_scalar_coord(self):
        # Check a specific scalar coord is present in the main content.
        content = self.representer._make_content()
        expected_coord = self.cube.coords()[0]
        expected_coord_name = expected_coord.name()
        self.assertIn(expected_coord_name, content)
        expected_coord_val = str(expected_coord.points[0])
        self.assertIn(expected_coord_val, content)

    def test_content__attributes(self):
        # Check an element "attributes" is present in the main content.
        content = self.representer._make_content()
        expected_str = 'Attributes'
        self.assertIn(expected_str, content)
class TestScalarCube(tests.IrisTest):
    def setUp(self):
        self.cube = stock.realistic_3d()[0, 0, 0]
        self.representer = CubeRepresentation(self.cube)
        self.representer.repr_html()

    def test_identfication(self):
        # Is this scalar cube accurately identified?
        self.assertTrue(self.representer.scalar_cube)

    def test_header__name(self):
        header = self.representer._make_header()
        expected_name = escape(self.cube.name().title().replace('_', ' '))
        self.assertIn(expected_name, header)

    def test_header__units(self):
        header = self.representer._make_header()
        expected_units = escape(self.cube.units.symbol)
        self.assertIn(expected_units, header)

    def test_header__scalar_str(self):
        # Check that 'scalar cube' is placed in the header.
        header = self.representer._make_header()
        expected_str = '(scalar cube)'
        self.assertIn(expected_str, header)

    def test_content__scalars(self):
        # Check an element "Scalar coordinates" is present in the main content.
        content = self.representer._make_content()
        expected_str = 'Scalar coordinates'
        self.assertIn(expected_str, content)

    def test_content__specific_scalar_coord(self):
        # Check a specific scalar coord is present in the main content.
        content = self.representer._make_content()
        expected_coord = self.cube.coords()[0]
        expected_coord_name = escape(expected_coord.name())
        self.assertIn(expected_coord_name, content)
        expected_coord_val = escape(str(expected_coord.points[0]))
        self.assertIn(expected_coord_val, content)

    def test_content__attributes(self):
        # Check an element "attributes" is present in the main content.
        content = self.representer._make_content()
        expected_str = 'Attributes'
        self.assertIn(expected_str, content)
Beispiel #31
0
 def setUp(self):
     self.cube = stock.simple_3d()
     cm = CellMethod('mean', 'time', '6hr')
     self.cube.add_cell_method(cm)
     self.representer = CubeRepresentation(self.cube)
     self.representer._get_bits(self.representer._get_lines())
 def setUp(self):
     self.cube = stock.realistic_3d()[0, 0, 0]
     self.representer = CubeRepresentation(self.cube)
     self.representer.repr_html()
Beispiel #33
0
 def setUp(self):
     self.cube = stock.simple_3d()
     self.representer = CubeRepresentation(self.cube)
     self.representer._get_bits(self.representer._get_lines())
     self.result = self.representer._make_shapes_row().split('\n')
 def setUp(self):
     self.cube = stock.realistic_3d()[0, 0, 0]
     self.representer = CubeRepresentation(self.cube)
     self.representer.repr_html()
Beispiel #35
0
 def setUp(self):
     self.cube = stock.simple_3d()
     self.representer = CubeRepresentation(self.cube)
     self.representer._get_bits(self.representer._get_lines())
     self.header_emts = self.representer._make_header().split('\n')
 def setUp(self):
     self.cube = stock.simple_3d()
     representer = CubeRepresentation(self.cube)
     self.result = representer.repr_html()
Beispiel #37
0
 def setUp(self):
     self.cube = stock.simple_3d()
     self.representer = CubeRepresentation(self.cube)
Beispiel #38
0
 def setUp(self):
     self.cube = stock.realistic_4d()
     self.dim_names = [c.name() for c in self.cube.coords(dim_coords=True)]
     self.representer = CubeRepresentation(self.cube)
 def setUp(self):
     self.cube = stock.simple_3d()
     self.representer = CubeRepresentation(self.cube)
     self.representer._get_bits(self.representer._get_lines())
     self.result = self.representer._make_shapes_row().split('\n')
 def setUp(self):
     self.cube = stock.realistic_4d()
     self.dim_names = [c.name() for c in self.cube.coords(dim_coords=True)]
     self.representer = CubeRepresentation(self.cube)
class Test__get_bits(tests.IrisTest):
    def setUp(self):
        self.cube = stock.realistic_4d()
        cmth = CellMethod("mean", "time", "6hr")
        self.cube.add_cell_method(cmth)
        cms = CellMeasure([0, 1, 2, 3, 4, 5], long_name="foo")
        self.cube.add_cell_measure(cms, 0)
        avr = AncillaryVariable([0, 1, 2, 3, 4, 5], long_name="bar")
        self.cube.add_ancillary_variable(avr, 0)
        scms = CellMeasure([0], long_name="baz")
        self.cube.add_cell_measure(scms)
        self.representer = CubeRepresentation(self.cube)
        self.representer._get_bits(self.representer._get_lines())

    def test_population(self):
        for v in self.representer.str_headings.values():
            self.assertIsNotNone(v)

    def test_headings__dimcoords(self):
        contents = self.representer.str_headings["Dimension coordinates:"]
        content_str = ",".join(content for content in contents)
        dim_coords = [c.name() for c in self.cube.dim_coords]
        for coord in dim_coords:
            self.assertIn(coord, content_str)

    def test_headings__auxcoords(self):
        contents = self.representer.str_headings["Auxiliary coordinates:"]
        content_str = ",".join(content for content in contents)
        aux_coords = [
            c.name() for c in self.cube.aux_coords if c.shape != (1, )
        ]
        for coord in aux_coords:
            self.assertIn(coord, content_str)

    def test_headings__derivedcoords(self):
        contents = self.representer.str_headings["Derived coordinates:"]
        content_str = ",".join(content for content in contents)
        derived_coords = [c.name() for c in self.cube.derived_coords]
        for coord in derived_coords:
            self.assertIn(coord, content_str)

    def test_headings__cellmeasures(self):
        contents = self.representer.str_headings["Cell measures:"]
        content_str = ",".join(content for content in contents)
        cell_measures = [
            c.name() for c in self.cube.cell_measures() if c.shape != (1, )
        ]
        for coord in cell_measures:
            self.assertIn(coord, content_str)

    def test_headings__ancillaryvars(self):
        contents = self.representer.str_headings["Ancillary variables:"]
        content_str = ",".join(content for content in contents)
        ancillary_variables = [
            c.name() for c in self.cube.ancillary_variables()
        ]
        for coord in ancillary_variables:
            self.assertIn(coord, content_str)

    def test_headings__scalarcellmeasures(self):
        contents = self.representer.str_headings["Scalar cell measures:"]
        content_str = ",".join(content for content in contents)
        scalar_cell_measures = [
            c.name() for c in self.cube.cell_measures() if c.shape == (1, )
        ]
        for coord in scalar_cell_measures:
            self.assertIn(coord, content_str)

    def test_headings__scalarcoords(self):
        contents = self.representer.str_headings["Scalar coordinates:"]
        content_str = ",".join(content for content in contents)
        scalar_coords = [
            c.name() for c in self.cube.coords() if c.shape == (1, )
        ]
        for coord in scalar_coords:
            self.assertIn(coord, content_str)

    def test_headings__attributes(self):
        contents = self.representer.str_headings["Attributes:"]
        content_str = ",".join(content for content in contents)
        for attr_name, attr_value in self.cube.attributes.items():
            self.assertIn(attr_name, content_str)
            self.assertIn(attr_value, content_str)

    def test_headings__cellmethods(self):
        contents = self.representer.str_headings["Cell methods:"]
        content_str = ",".join(content for content in contents)
        for cell_method in self.cube.cell_methods:
            self.assertIn(str(cell_method), content_str)
 def setUp(self):
     self.cube = stock.simple_3d()
     cm = CellMethod('mean', 'time', '6hr')
     self.cube.add_cell_method(cm)
     self.representer = CubeRepresentation(self.cube)
     self.representer._get_bits(self.representer._get_lines())
 def setUp(self):
     self.cube = stock.simple_3d()
     self.representer = CubeRepresentation(self.cube)
     self.representer._get_bits(self.representer._get_lines())
     self.result = self.representer._make_content()
Beispiel #44
0
 def setUp(self):
     self.cube = stock.simple_3d()
     self.representer = CubeRepresentation(self.cube)
     self.representer._get_bits(self.representer._get_lines())
     self.result = self.representer._make_content()
Beispiel #45
0
 def setUp(self):
     self.cube = stock.simple_3d()
     representer = CubeRepresentation(self.cube)
     self.result = representer.repr_html()
 def setUp(self):
     self.shape = (2, 3, 4)
     self.cube = Cube(np.arange(24).reshape(self.shape))
     self.representer = CubeRepresentation(self.cube)
     self.representer.repr_html()
 def setUp(self):
     self.cube = stock.simple_3d()
     self.representer = CubeRepresentation(self.cube)
     self.representer._get_bits(self.representer._get_lines())
     self.header_emts = self.representer._make_header().split('\n')
 def setUp(self):
     self.shape = (2, 3, 4)
     self.cube = Cube(np.arange(24).reshape(self.shape))
     self.representer = CubeRepresentation(self.cube)
     self.representer.repr_html()
Beispiel #49
0
 def setUp(self):
     self.cube = stock.lat_lon_cube()
     # Check we're not tripped up by names containing spaces.
     self.cube.rename('Electron density')
     self.cube.units = '1e11 e/m^3'
     self.representer = CubeRepresentation(self.cube)
 def test_no_cell_methods(self):
     representer = CubeRepresentation(self.cube)
     result = representer.repr_html().lower()
     self.assertNotIn('cell methods', result)