Example #1
0
def test_default_table():
    table = Table([
        Header('Header'),
        Line('row_1', 'key_1'),
        Spacer(),
        Line('row_2', 'key_2'),
        Line('row_3', 'key_3'),
        Header('Subheader'),
        Line('row_4', 'key_4'),
    ], header_color=None)
    assert table.construct() == _EXPECTED_DEFAULT_RENDER
Example #2
0
def test_custom_table_2():
    table = Table(
        [
            Header('Header'),
            Line('row_1', 'key_1'),
            Spacer(),
            Line('row_2', 'key_2'),
            Line('row_3', 'key_3'),
            Header('Subheader'),
        ],
        header_color=None,
        vertical_separator='o',
        horizontal_separator='o',
        horizontal_hinges=('o', 'o', 'o'),
        vertical_hinges=('o', 'o'),
        corners=('o', 'o', 'o', 'o'),
    )
    assert table.construct() == _EXPECTED_CUSTOM_TABLE_2
Example #3
0
 def _print_test_suites_summary(self, test_suites: TestSuites):
     tests_color = Colors.GREEN if test_suites.tests else Colors.RED
     fails_color = Colors.RED if test_suites.failures else Colors.GREEN
     errors_color = Colors.RED if test_suites.errors else Colors.GREEN
     table = Table([
         Header('Test run summary'),
         Line('Test suites', len(test_suites.test_suites)),
         Line('Total tests ran', test_suites.tests, value_color=tests_color),
         Line('Total tests failed', test_suites.failures, value_color=fails_color),
         Line('Total tests errored', test_suites.errors, value_color=errors_color),
         Line('Total tests skipped', test_suites.skipped)
     ], align_values_left=False)
     self.print(table.construct())
Example #4
0
def test_custom_table_1():
    table = Table(
        [
            Header('Header'),
            Line('row_1', 'key_1'),
            Spacer(),
            Line('row_2', 'key_2'),
            Line('row_3', 'key_3'),
            Header('Subheader'),
            Line('row_4', 'key_4'),
        ],
        header_color=None,
        vertical_separator='|',
        horizontal_separator='-',
        horizontal_hinges=('+', '+', '+'),
        vertical_hinges=('+', '+'),
        corners=('+', '+', '+', '+'),
        left_padding=' < ',
        right_padding=' > ',
    )
    rendered = table.construct()
    assert rendered == _EXPECTED_CUSTOM_TABLE_1
Example #5
0
    def _print_test_suite(self, test_suite: TestSuite):
        tests_color = Colors.GREEN if test_suite.tests else Colors.RED
        fails_color = Colors.RED if test_suite.failures else Colors.GREEN
        errors_color = Colors.RED if test_suite.errors else Colors.GREEN

        table = Table([
            Header('Testsuite summary'),
            Line('Name', test_suite.name),
            *(Line(p.name.replace('_', ' ').title(), p.value) for p in test_suite.properties),
            Spacer(),
            Line('Total tests ran', test_suite.tests or 0, value_color=tests_color),
            Line('Total tests failed', test_suite.failures or 0, value_color=fails_color),
            Line('Total tests errored', test_suite.errors or 0, value_color=errors_color),
            Line('Total tests skipped', test_suite.skipped or 0),
            *self._get_test_suite_errored_lines(test_suite),
            *self._get_test_suite_failed_lines(test_suite),
            *self._get_test_suite_skipped_lines(test_suite)
        ])

        self.print(table.construct())
Example #6
0
    def _get_test_suite_skipped_lines(self, test_suite: TestSuite) -> List[Line]:
        def to_line(tc):
            return Line(f'{tc.classname}.{tc.name}', self._truncate(tc.skipped.message))

        skipped_tests = test_suite.get_skipped_test_cases()
        return [Header('Skipped tests'), *map(to_line, skipped_tests)] if skipped_tests else []
Example #7
0
    def _get_test_suite_failed_lines(self, test_suite: TestSuite) -> List[Line]:
        def to_line(tc):
            return Line(f'{tc.classname}.{tc.name}', self._truncate(tc.failure.message))

        failed_tests = test_suite.get_failed_test_cases()
        return [Header('Failed tests'), *map(to_line, failed_tests)] if failed_tests else []
Example #8
0
    def _get_test_suite_errored_lines(self, test_suite: TestSuite) -> List[Line]:
        def to_line(tc):
            return Line(f'{tc.classname}.{tc.name}', self._truncate(tc.error.message))

        errored_tests = test_suite.get_errored_test_cases()
        return [Header('Errored tests'), *map(to_line, errored_tests)] if errored_tests else []