コード例 #1
0
    def test_text(self):
        """Tests Text messages are rendered correctly in plain text/html.
        """
        t1 = Text('FOO')
        t2 = Text('BAR')
        expected_res = 'FOO'

        res = t1.to_text()
        self.assertEqual(expected_res, res)

        t1.add(t2)
        expected_res = 'FOO BAR'
        res = t1.to_html()
        self.assertEqual(expected_res, res)

        t1 = Text('FOO', ImportantText('BAR'), 'function')
        expected_res = 'FOO <strong>BAR</strong> function'
        res = t1.to_html()
        self.assertEqual(expected_res, res)
コード例 #2
0
    def test_table_html(self):
        """Tests cells are rendered correctly in html.
        """
        c1 = Cell('FOO')
        expected_res = '<td>FOO</td>\n'
        res = c1.to_html()
        self.assertEqual(expected_res, res)

        c2 = Cell('FOO', ImportantText('BAR'), 'function')
        expected_res = '<td>FOO <strong>BAR</strong> function</td>\n'
        res = c2.to_html()
        self.assertEqual(expected_res, res)

        r1 = Row(c1, c2, '3a')
        expected_res = (
            '<tr>\n<td>FOO</td>\n<td>FOO <strong>BAR</strong> function</td>\n'
            '<td>3a</td>\n</tr>\n')
        res = r1.to_html()
        self.assertEqual(expected_res, res)

        t1 = Table(r1, Row('1', '2', '3'), ['a', 'b', 'c'])
        expected_res = (
            '<table>\n<tbody>\n<tr>\n<td>FOO</td>\n<td>FOO '
            '<strong>BAR</strong> function</td>\n<td>3a</td>\n</tr>\n<tr>\n'
            '<td>1</td>\n<td>2</td>\n'
            '<td>3</td>\n</tr>\n<tr>\n<td>a</td>\n<td>b</td>\n<td>c</td>\n'
            '</tr>\n</tbody>\n</table>\n')
        res = t1.to_html()
        self.assertEqual(expected_res, res)

        t1.caption = 'Test Caption'
        expected_res = (
            '<table>\n<caption>Test Caption</caption>\n<tbody>\n<tr>\n'
            '<td>FOO</td>\n<td>FOO <strong>BAR</strong> function</td>\n'
            '<td>3a</td>\n</tr>\n<tr>\n<td>1</td>\n<td>2</td>\n<td>3</td>\n'
            '</tr>\n<tr>\n<td>a</td>\n<td>b</td>\n<td>c</td>\n</tr>\n'
            '</tbody>\n</table>\n')
        res = t1.to_html()
        self.assertEqual(expected_res, res)