def test_multi_line(): """Test on multi-lines.""" assert '\n' == join_row(['\n'], '', '', '') assert '\n' == join_row(['\n'], '', '|', '') assert '|\n|' == join_row(['\n'], '', '|', '|') assert '||\n||' == join_row(['\n'], '|', '|', '|') expected = dedent("""\ > Cars | Jetta < > | Camry <""") actual = join_row([' Cars \n ', ' Jetta \n Camry '], '>', '|', '<') assert expected == actual
def test_multi_line(): """Test on multi-lines.""" assert join_row(['\n'], '', '', '') == '\n' assert join_row(['\n'], '', '|', '') == '\n' assert join_row(['\n'], '', '|', '|') == '|\n|' assert join_row(['\n'], '|', '|', '|') == '||\n||' expected = dedent("""\ > Cars | Jetta < > | Camry <""") actual = join_row([' Cars \n ', ' Jetta \n Camry '], '>', '|', '<') assert actual == expected
def table(self): """Return a large string of the entire table ready to be printed to the terminal.""" padded_table_data = self.padded_table_data column_widths = [c + self.padding_left + self.padding_right for c in self.column_widths] final_table_data = list() for row_index, row_data in enumerate(padded_table_data): row = join_row( row_data, self.CHAR_VERTICAL, self.CHAR_VERTICAL, self.CHAR_VERTICAL ) final_table_data.append(row) if row_index != 0: continue # Header row separator. column_separators = [] for column_index, column_width in enumerate(column_widths): column_justify = self.justify_columns.get(column_index) if column_justify == 'left': separator = ':' + self.CHAR_HORIZONTAL * (column_width - 1) elif column_justify == 'right': separator = self.CHAR_HORIZONTAL * (column_width - 1) + ':' elif column_justify == 'center': separator = self.CHAR_HORIZONTAL * (column_width - 2) separator = ':' + separator + ':' else: separator = self.CHAR_HORIZONTAL * column_width column_separators.append(separator) row = join_row( column_separators, self.CHAR_VERTICAL, self.CHAR_VERTICAL, self.CHAR_VERTICAL ) final_table_data.append(row) return '\n'.join(final_table_data)
def test_single_line(): """Test on single lines.""" assert '' == join_row([], '', '', '') assert '' == join_row([], '', '|', '') assert '|' == join_row([], '', '|', '|') assert '||' == join_row([], '|', '|', '|') assert '' == join_row([''], '', '', '') assert '' == join_row([''], '', '|', '') assert '|' == join_row([''], '', '|', '|') assert '||' == join_row([''], '|', '|', '|') assert 'test' == join_row(['test'], '', '', '') assert 'test' == join_row(['test'], '', '|', '') assert '|test' == join_row(['test'], '|', '', '') assert 'test|' == join_row(['test'], '', '', '|') assert '|test|' == join_row(['test'], '|', '|', '|') assert 'testtest2' == join_row(['test', 'test2'], '', '', '') assert 'test+test2' == join_row(['test', 'test2'], '', '+', '') assert '|test+test2|' == join_row(['test', 'test2'], '|', '+', '|')
def test_single_line(): """Test on single lines.""" assert join_row([], '', '', '') == '' assert join_row([], '', '|', '') == '' assert join_row([], '', '|', '|') == '|' assert join_row([], '|', '|', '|') == '||' assert join_row([''], '', '', '') == '' assert join_row([''], '', '|', '') == '' assert join_row([''], '', '|', '|') == '|' assert join_row([''], '|', '|', '|') == '||' assert join_row(['test'], '', '', '') == 'test' assert join_row(['test'], '', '|', '') == 'test' assert join_row(['test'], '|', '', '') == '|test' assert join_row(['test'], '', '', '|') == 'test|' assert join_row(['test'], '|', '|', '|') == '|test|' assert join_row(['test', 'test2'], '', '', '') == 'testtest2' assert join_row(['test', 'test2'], '', '+', '') == 'test+test2' assert join_row(['test', 'test2'], '|', '+', '|') == '|test+test2|'