示例#1
0
    def setUp(self):
        self.heading = ['ID', 'Name', 'Severity']
        self.rows = [
            ['1', 'foobar', 'high'],
            ['2', 'bla', 'low'],
            ['3', 'blub', 'medium'],
        ]
        self.divider = ' - '

        self.table = Table(heading=self.heading,
                           rows=self.rows,
                           divider=self.divider)
示例#2
0
def main(gmp, args):
    response_xml = gmp.get_tasks()
    tasks_xml = response_xml.xpath('task')

    heading = ['ID', 'Name', 'Severity']

    rows = []

    for task in tasks_xml:
        name = ''.join(task.xpath('name/text()'))
        task_id = task.get('id')
        severity = ''.join(task.xpath('last_report/report/severity/text()'))

        rows.append([task_id, name, severity])

    print(Table(heading=heading, rows=rows))
示例#3
0
    def test_init_no_args(self):
        table = Table()

        self.assertListEqual(table.heading, [])
        self.assertListEqual(table.rows, [])
        self.assertEqual(table.divider, ' | ')
示例#4
0
class TableTestCase(unittest.TestCase):
    def setUp(self):
        self.heading = ['ID', 'Name', 'Severity']
        self.rows = [
            ['1', 'foobar', 'high'],
            ['2', 'bla', 'low'],
            ['3', 'blub', 'medium'],
        ]
        self.divider = ' - '

        self.table = Table(heading=self.heading,
                           rows=self.rows,
                           divider=self.divider)

    def test_init_no_args(self):
        table = Table()

        self.assertListEqual(table.heading, [])
        self.assertListEqual(table.rows, [])
        self.assertEqual(table.divider, ' | ')

    def test_init_with_args(self):
        self.assertListEqual(self.table.heading, self.heading)
        self.assertListEqual(self.table.rows, self.rows)
        self.assertEqual(self.table.divider, self.divider)

    def test_calculate_dimensions(self):
        expected_result = [
            len(self.heading[0]),
            len(self.rows[0][1]),
            len(self.heading[2]),
        ]

        column_sizes = (
            self.table._calculate_dimensions()  # pylint: disable=protected-access
        )

        self.assertEqual(column_sizes, expected_result)

    def test_create_column(self):
        column = 'foobar'
        size = 20
        expected = 'foobar              '

        result = self.table._create_column(  # pylint: disable=protected-access
            column, size)

        self.assertEqual(result, expected)

    def test_create_row(self):
        columns = ['foo', 'bar', 'blub']
        expected = self.divider.join(columns)

        result = self.table._create_row(columns)  # pylint: disable=W0212

        self.assertEqual(result, expected)

    def test_str(self):
        expected = ('ID - Name   - Severity\n' + '-- - ------ - --------\n' +
                    '1  - foobar - high    \n' + '2  - bla    - low     \n' +
                    '3  - blub   - medium  ')

        self.assertEqual(str(self.table), expected)