def test_row(inner_column_border, outer_border): """Test inner borders. :param bool inner_column_border: Passed to table class. :param bool outer_border: Passed to table class. """ table = BaseTable(SINGLE_LINE) table.inner_column_border = inner_column_border table.outer_border = outer_border outer_widths = max_dimensions(table.table_data, table.padding_left, table.padding_right)[2] # Determine expected. if inner_column_border and outer_border: expected = '+---------+-------+-----------+' elif inner_column_border: expected = '---------+-------+-----------' elif outer_border: expected = '+---------------------------+' else: expected = '---------------------------' # Test. actual = ''.join(table.horizontal_border('row', outer_widths)) assert actual == expected
def test_outer_borders(outer_border): """Test left/right/top/bottom table borders. :param bool outer_border: Passed to table. """ table_data = [ ['Name', 'Color', 'Type'], ['Avocado', 'green', 'nut'], ['Tomato', 'red', 'fruit'], ['Lettuce', 'green', 'vegetable'], ] table = BaseTable(table_data, 'Example Table') table.outer_border = outer_border inner_widths, inner_heights, outer_widths = max_dimensions( table_data, table.padding_left, table.padding_right)[:3] actual = flatten(table.gen_table(inner_widths, inner_heights, outer_widths)) # Determine expected. if outer_border: expected = ('+Example Table----+-----------+\n' '| Name | Color | Type |\n' '+---------+-------+-----------+\n' '| Avocado | green | nut |\n' '| Tomato | red | fruit |\n' '| Lettuce | green | vegetable |\n' '+---------+-------+-----------+') else: expected = (' Name | Color | Type \n' '---------+-------+-----------\n' ' Avocado | green | nut \n' ' Tomato | red | fruit \n' ' Lettuce | green | vegetable ') assert actual == expected
def test_heading_footing(inner_column_border, outer_border, style): """Test heading and footing borders. :param bool inner_column_border: Passed to table class. :param bool outer_border: Passed to table class. :param str style: Passed to method. """ table = BaseTable(SINGLE_LINE) table.inner_column_border = inner_column_border table.outer_border = outer_border outer_widths = max_dimensions(table.table_data, table.padding_left, table.padding_right)[2] # Determine expected. if style == 'heading' and outer_border: expected = '+---------+-------+-----------+' if inner_column_border else '+---------------------------+' elif style == 'heading': expected = '---------+-------+-----------' if inner_column_border else '---------------------------' elif style == 'footing' and outer_border: expected = '+---------+-------+-----------+' if inner_column_border else '+---------------------------+' else: expected = '---------+-------+-----------' if inner_column_border else '---------------------------' # Test. actual = ''.join(table.horizontal_border(style, outer_widths)) assert actual == expected
def test_no_padding_no_borders(): """Test without padding or borders.""" row = ['Row One\nColumn One', 'Two', 'Three'] table = BaseTable([row]) table.inner_column_border = False table.outer_border = False table.padding_left = 0 table.padding_right = 0 actual = list(table.gen_cell_lines(row, [10, 3, 5], 2)) expected = [ ('Row One ', 'Two', 'Three'), ('Column One', ' ', ' '), ] assert actual == expected
def test_no_padding_no_borders(style): """Test without padding or borders. :param str style: Passed to method. """ row = ['Row One\nColumn One', 'Two', 'Three'] table = BaseTable([row]) table.inner_column_border = False table.outer_border = False table.padding_left = 0 table.padding_right = 0 actual = [tuple(i) for i in table.gen_row_lines(row, style, [10, 3, 5], 2)] expected = [ ('Row One ', 'Two', 'Three'), ('Column One', ' ', ' '), ] assert actual == expected
def test_outer_borders(outer_border): """Test left/right/top/bottom table borders. :param bool outer_border: Passed to table. """ table_data = [ ['Name', 'Color', 'Type'], ['Avocado', 'green', 'nut'], ['Tomato', 'red', 'fruit'], ['Lettuce', 'green', 'vegetable'], ] table = BaseTable(table_data, 'Example Table') table.outer_border = outer_border inner_widths, inner_heights, outer_widths = max_dimensions(table_data, table.padding_left, table.padding_right)[:3] actual = flatten(table.gen_table(inner_widths, inner_heights, outer_widths)) # Determine expected. if outer_border: expected = ( '+Example Table----+-----------+\n' '| Name | Color | Type |\n' '+---------+-------+-----------+\n' '| Avocado | green | nut |\n' '| Tomato | red | fruit |\n' '| Lettuce | green | vegetable |\n' '+---------+-------+-----------+' ) else: expected = ( ' Name | Color | Type \n' '---------+-------+-----------\n' ' Avocado | green | nut \n' ' Tomato | red | fruit \n' ' Lettuce | green | vegetable ' ) assert actual == expected
def test_one_no_rows(mode, bare): """Test with one or no rows. :param str mode: Type of table contents to test. :param bool bare: Disable padding/borders. """ if mode == 'row': table_data = [ ['Avocado', 'green', 'nut'], ] elif mode == 'one': table_data = [ ['Avocado'], ] elif mode == 'blank': table_data = [ [''], ] elif mode == 'empty': table_data = [ [], ] else: table_data = [] table = BaseTable(table_data) if bare: table.inner_column_border = False table.inner_footing_row_border = False table.inner_heading_row_border = False table.inner_row_border = False table.outer_border = False table.padding_left = 0 table.padding_right = 0 inner_widths, inner_heights, outer_widths = max_dimensions( table_data, table.padding_left, table.padding_right)[:3] actual = flatten(table.gen_table(inner_widths, inner_heights, outer_widths)) # Determine expected. if mode == 'row': if bare: expected = ('Avocadogreennut') else: expected = ('+---------+-------+-----+\n' '| Avocado | green | nut |\n' '+---------+-------+-----+') elif mode == 'one': if bare: expected = ('Avocado') else: expected = ('+---------+\n' '| Avocado |\n' '+---------+') elif mode == 'blank': # Remember there's still padding. if bare: expected = ('') else: expected = ('+--+\n' '| |\n' '+--+') elif mode == 'empty': if bare: expected = ('') else: expected = ('++\n' '||\n' '++') else: if bare: expected = ('') else: expected = ('++\n' '++') assert actual == expected
def test_one_no_rows(mode, bare): """Test with one or no rows. :param str mode: Type of table contents to test. :param bool bare: Disable padding/borders. """ if mode == 'row': table_data = [ ['Avocado', 'green', 'nut'], ] elif mode == 'one': table_data = [ ['Avocado'], ] elif mode == 'blank': table_data = [ [''], ] elif mode == 'empty': table_data = [ [], ] else: table_data = [ ] table = BaseTable(table_data) if bare: table.inner_column_border = False table.inner_footing_row_border = False table.inner_heading_row_border = False table.inner_row_border = False table.outer_border = False table.padding_left = 0 table.padding_right = 0 inner_widths, inner_heights, outer_widths = max_dimensions(table_data, table.padding_left, table.padding_right)[:3] actual = flatten(table.gen_table(inner_widths, inner_heights, outer_widths)) # Determine expected. if mode == 'row': if bare: expected = ( 'Avocadogreennut' ) else: expected = ( '+---------+-------+-----+\n' '| Avocado | green | nut |\n' '+---------+-------+-----+' ) elif mode == 'one': if bare: expected = ( 'Avocado' ) else: expected = ( '+---------+\n' '| Avocado |\n' '+---------+' ) elif mode == 'blank': # Remember there's still padding. if bare: expected = ( '' ) else: expected = ( '+--+\n' '| |\n' '+--+' ) elif mode == 'empty': if bare: expected = ( '' ) else: expected = ( '++\n' '||\n' '++' ) else: if bare: expected = ( '' ) else: expected = ( '++\n' '++' ) assert actual == expected