示例#1
0
 def table_width(self):
     """Return the width of the table including padding and borders."""
     outer_border = 2 if self.outer_border else 0
     inner_border = 1 if self.inner_column_border else 0
     padding = self.padding_left + self.padding_right
     return width_and_alignment.table_width(self.table_data, outer_border,
                                            inner_border, padding)
示例#2
0
 def table_width(self):
     """Return the width of the table including padding and borders."""
     outer_widths = max_dimensions(self.table_data, self.padding_left,
                                   self.padding_right)[2]
     outer_border = 2 if self.outer_border else 0
     inner_border = 1 if self.inner_column_border else 0
     return table_width(outer_widths, outer_border, inner_border)
def test_multi_line():
    """Test with multi-line cells."""
    table_data = [
        ['Show', 'Characters'],
        ['Rugrats', ('Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille, Angelica Pickles,\n'
                     'Susie Carmichael, Dil Pickles, Kimi Finster, Spike')],
        ['South Park', 'Stan Marsh, Kyle Broflovski, Eric Cartman, Kenny McCormick']
    ]
    outer, inner, padding = 2, 1, 2
    assert table_width(table_data, outer, inner, padding) == 100
def test_multi_line():
    """Test with multi-line cells."""
    table_data = [
        ['Show', 'Characters'],
        ['Rugrats', ('Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille, Angelica Pickles,\n'
                     'Susie Carmichael, Dil Pickles, Kimi Finster, Spike')],
        ['South Park', 'Stan Marsh, Kyle Broflovski, Eric Cartman, Kenny McCormick']
    ]
    outer, inner, outer_widths = 2, 1, max_dimensions(table_data, 1, 1)[2]
    assert table_width(outer_widths, outer, inner) == 100
def test_empty():
    """Test with zero-length cells."""
    assert table_width(max_dimensions([['']])[2], 0, 0) == 0
    assert table_width(max_dimensions([['', '', '']])[2], 0, 0) == 0
    assert table_width(max_dimensions([['', '', ''], ['', '', '']])[2], 0, 0) == 0

    assert table_width(max_dimensions([['']], 1, 1)[2], 2, 1) == 4
    assert table_width(max_dimensions([['', '', '']], 1, 1)[2], 2, 1) == 10
    assert table_width(max_dimensions([['', '', ''], ['', '', '']], 1, 1)[2], 2, 1) == 10
def test_empty():
    """Test with zero-length cells."""
    assert table_width([['']], 0, 0, 0) == 0
    assert table_width([['', '', '']], 0, 0, 0) == 0
    assert table_width([['', '', ''], ['', '', '']], 0, 0, 0) == 0

    assert table_width([['']], 2, 1, 2) == 4
    assert table_width([['', '', '']], 2, 1, 2) == 10
    assert table_width([['', '', ''], ['', '', '']], 2, 1, 2) == 10
def test_empty():
    """Test with zero-length cells."""
    assert table_width(max_dimensions([['']])[2], 0, 0) == 0
    assert table_width(max_dimensions([['', '', '']])[2], 0, 0) == 0
    assert table_width(max_dimensions([['', '', ''], ['', '', '']])[2], 0,
                       0) == 0

    assert table_width(max_dimensions([['']], 1, 1)[2], 2, 1) == 4
    assert table_width(max_dimensions([['', '', '']], 1, 1)[2], 2, 1) == 10
    assert table_width(
        max_dimensions([['', '', ''], ['', '', '']], 1, 1)[2], 2, 1) == 10
def test_single_line():
    """Test with single-line cells."""
    table_data = [
        ['Name', 'Color', 'Type'],
        ['Avocado', 'green', 'nut'],
        ['Tomato', 'red', 'fruit'],
        ['Lettuce', 'green', 'vegetable'],
    ]

    # '| Lettuce | green | vegetable |'
    outer, inner, outer_widths = 2, 1, max_dimensions(table_data, 1, 1)[2]
    assert table_width(outer_widths, outer, inner) == 31

    # ' Lettuce | green | vegetable '
    outer = 0
    assert table_width(outer_widths, outer, inner) == 29

    # '| Lettuce  green  vegetable |'
    outer, inner = 2, 0
    assert table_width(outer_widths, outer, inner) == 29

    # ' Lettuce  green  vegetable '
    outer = 0
    assert table_width(outer_widths, outer, inner) == 27

    # '|Lettuce |green |vegetable |'
    outer, inner, outer_widths = 2, 1, max_dimensions(table_data, 1)[2]
    assert table_width(outer_widths, outer, inner) == 28

    # '|Lettuce     |green     |vegetable     |'
    outer_widths = max_dimensions(table_data, 3, 2)[2]
    assert table_width(outer_widths, outer, inner) == 40

    table_data = [
        ['Name', 'Color', 'Type'],
        ['Avocado', 'green', 'nut'],
        ['Tomato', 'red', 'fruit'],
        ['Lettuce', 'green', 'vegetable'],
        ['Watermelon', 'green', 'fruit'],
    ]
    outer, inner, outer_widths = 2, 1, max_dimensions(table_data, 1, 1)[2]
    assert table_width(outer_widths, outer, inner) == 34
def test_single_line():
    """Test with single-line cells."""
    table_data = [
        ['Name', 'Color', 'Type'],
        ['Avocado', 'green', 'nut'],
        ['Tomato', 'red', 'fruit'],
        ['Lettuce', 'green', 'vegetable'],
    ]

    # '| Lettuce | green | vegetable |'
    outer, inner, padding = 2, 1, 2
    assert table_width(table_data, outer, inner, padding) == 31

    # ' Lettuce | green | vegetable '
    outer = 0
    assert table_width(table_data, outer, inner, padding) == 29

    # '| Lettuce  green  vegetable |'
    outer, inner = 2, 0
    assert table_width(table_data, outer, inner, padding) == 29

    # ' Lettuce  green  vegetable '
    outer = 0
    assert table_width(table_data, outer, inner, padding) == 27

    # '|Lettuce |green |vegetable |'
    outer, inner, padding = 2, 1, 1
    assert table_width(table_data, outer, inner, padding) == 28

    # '|Lettuce     |green     |vegetable     |'
    padding = 5
    assert table_width(table_data, outer, inner, padding) == 40

    table_data = [
        ['Name', 'Color', 'Type'],
        ['Avocado', 'green', 'nut'],
        ['Tomato', 'red', 'fruit'],
        ['Lettuce', 'green', 'vegetable'],
        ['Watermelon', 'green', 'fruit'],
    ]
    outer, inner, padding = 2, 1, 2
    assert table_width(table_data, outer, inner, padding) == 34
示例#10
0
def test_single_line():
    """Test with single-line cells."""
    table_data = [
        ['Name', 'Color', 'Type'],
        ['Avocado', 'green', 'nut'],
        ['Tomato', 'red', 'fruit'],
        ['Lettuce', 'green', 'vegetable'],
    ]

    # '| Lettuce | green | vegetable |'
    outer, inner, outer_widths = 2, 1, max_dimensions(table_data, 1, 1)[2]
    assert table_width(outer_widths, outer, inner) == 31

    # ' Lettuce | green | vegetable '
    outer = 0
    assert table_width(outer_widths, outer, inner) == 29

    # '| Lettuce  green  vegetable |'
    outer, inner = 2, 0
    assert table_width(outer_widths, outer, inner) == 29

    # ' Lettuce  green  vegetable '
    outer = 0
    assert table_width(outer_widths, outer, inner) == 27

    # '|Lettuce |green |vegetable |'
    outer, inner, outer_widths = 2, 1, max_dimensions(table_data, 1)[2]
    assert table_width(outer_widths, outer, inner) == 28

    # '|Lettuce     |green     |vegetable     |'
    outer_widths = max_dimensions(table_data, 3, 2)[2]
    assert table_width(outer_widths, outer, inner) == 40

    table_data = [
        ['Name', 'Color', 'Type'],
        ['Avocado', 'green', 'nut'],
        ['Tomato', 'red', 'fruit'],
        ['Lettuce', 'green', 'vegetable'],
        ['Watermelon', 'green', 'fruit'],
    ]
    outer, inner, outer_widths = 2, 1, max_dimensions(table_data, 1, 1)[2]
    assert table_width(outer_widths, outer, inner) == 34
示例#11
0
 def table_width(self):
     """Return the width of the table including padding and borders."""
     outer_widths = max_dimensions(self.table_data, self.padding_left, self.padding_right)[2]
     outer_border = 2 if self.outer_border else 0
     inner_border = 1 if self.inner_column_border else 0
     return table_width(outer_widths, outer_border, inner_border)
示例#12
0
 def table_width(self):
     """Return the width of the table including padding and borders."""
     outer_border = 2 if self.outer_border else 0
     inner_border = 1 if self.inner_column_border else 0
     padding = self.padding_left + self.padding_right
     return width_and_alignment.table_width(self.table_data, outer_border, inner_border, padding)