Example #1
0
    def test_display_type_delimiter_a(self):

        x, y, z = Display.type_attributes(np.dtype('int8'),
                                          DisplayConfigs.DEFAULT)
        self.assertEqual(x, '<int8>')
        self.assertEqual(y, 6)

        x, y, z = Display.type_attributes(np.dtype('int8'),
                                          DisplayConfigs.HTML_PRE)
        self.assertEqual(x, '&lt;int8&gt;')
        self.assertEqual(y, 6)
Example #2
0
    def test_display_type_color_markup_a(self) -> None:

        config1 = DisplayConfig(display_format=DisplayFormats.TERMINAL)
        post1 = Display.type_color_markup(DisplayTypeInt, config1)

        if terminal_ansi():
            self.assertEqual(post1, '\x1b[38;5;239m{}\x1b[0m')
        else:
            self.assertEqual(post1, '{}')

        config2 = DisplayConfig(display_format=DisplayFormats.HTML_TABLE)
        post2 = Display.type_color_markup(DisplayTypeInt, config2)
        self.assertEqual(post2, '<span style="color: #505050">{}</span>')
Example #3
0
    def test_display_repr_a(self) -> None:

        row1 = [
            DisplayCell(FORMAT_EMPTY, 'foo'),
            DisplayCell(FORMAT_EMPTY, 'bar')
        ]
        row2 = [
            DisplayCell(FORMAT_EMPTY, 'foo'),
            DisplayCell(FORMAT_EMPTY, 'bar')
        ]

        post = Display(
            rows=[row1, row2],
            outermost=False,
        )
        self.assertEqual(post.__repr__(), 'foo bar\nfoo bar')
Example #4
0
    def test_display_flatten_a(self) -> None:
        config = DisplayConfig.from_default(type_color=False)

        d1 = Display.from_values(np.array([1, 2, 3, 4], dtype=np.int64),
                                 'header',
                                 config=config)
        self.assertEqual(d1.flatten().to_rows(), ['header 1 2 3 4 <int64>'])

        d2 = Display.from_values(np.array([5, 6, 7, 8], dtype=np.int64),
                                 'header',
                                 config=config)

        # mutates in place
        d1.extend_display(d2)
        self.assertEqual(d1.to_rows(), [
            'header  header', '1       5', '2       6', '3       7',
            '4       8', '<int64> <int64>'
        ])

        self.assertEqual(d1.flatten().to_rows(),
                         ['header header 1 5 2 6 3 7 4 8 <int64> <int64>'])

        self.assertEqual(d1.transform().to_rows(),
                         ['header 1 2 3 4 <int64>', 'header 5 6 7 8 <int64>'])
Example #5
0
    def test_display_get_max_width_pad_width_a(self) -> None:

        row1 = [
            DisplayCell(FORMAT_EMPTY, 'foo'),
            DisplayCell(FORMAT_EMPTY, 'bar')
        ]
        row2 = [DisplayCell(FORMAT_EMPTY, 'foo')]

        post = Display._get_max_width_pad_width(
            rows=[row1, row2],
            col_idx_src=1,
            col_last_src=1,
            row_indices=range(2),
        )
        self.assertEqual(post, (3, 3))
Example #6
0
    def test_display_type_attributes_b(self) -> None:

        with self.assertRaises(NotImplementedError):
            x, z = Display.type_attributes(None, DisplayConfigs.DEFAULT)
Example #7
0
    def test_display_type_attributes_a(self) -> None:

        x, z = Display.type_attributes(np.dtype('int8'),
                                       DisplayConfigs.DEFAULT)
        self.assertEqual(x, '<int8>')
Example #8
0
 def test_display_config_a(self) -> None:
     config = DisplayConfig.from_default(type_color=False)
     d = Display.from_values(np.array([[1, 2], [3, 4]], dtype=np.int64),
                             'header',
                             config=config)
     self.assertEqual(d.to_rows(), ['header', '1 2', '3 4', '<int64>'])