From 7173c0357f2c2519203a71ea4ec8da099ff5e3ab Mon Sep 17 00:00:00 2001 From: Robpol86 Date: Sun, 29 May 2016 18:06:22 -0700 Subject: [PATCH] nevermind --- tests/__init__.py | 13 ----------- tests/test_ascii_table.py | 14 +++++++++++- .../test_column_max_width.py | 17 +++++++++++--- .../test_max_dimensions.py | 9 ++++++-- .../test_table_width.py | 22 ++++++++++++++----- 5 files changed, 51 insertions(+), 24 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index b1d3f99..b91337b 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -2,17 +2,4 @@ import py -MULTI_LINE = ( - ('Show', 'Characters'), - ('Rugrats', 'Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille, Angelica Pickles,\nDil Pickles'), - ('South Park', 'Stan Marsh, Kyle Broflovski, Eric Cartman, Kenny McCormick'), -) - PROJECT_ROOT = py.path.local(__file__).dirpath().join('..') - -SINGLE_LINE = ( - ('Name', 'Color', 'Type'), - ('Avocado', 'green', 'nut'), - ('Tomato', 'red', 'fruit'), - ('Lettuce', 'green', 'vegetable'), -) diff --git a/tests/test_ascii_table.py b/tests/test_ascii_table.py index 45e305a..020a443 100644 --- a/tests/test_ascii_table.py +++ b/tests/test_ascii_table.py @@ -3,7 +3,19 @@ import pytest from terminaltables.other_tables import AsciiTable -from tests import MULTI_LINE, SINGLE_LINE + +SINGLE_LINE = ( + ('Name', 'Color', 'Type'), + ('Avocado', 'green', 'nut'), + ('Tomato', 'red', 'fruit'), + ('Lettuce', 'green', 'vegetable'), +) + +MULTI_LINE = ( + ('Show', 'Characters'), + ('Rugrats', 'Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille, Angelica Pickles,\nDil Pickles'), + ('South Park', 'Stan Marsh, Kyle Broflovski, Eric Cartman, Kenny McCormick'), +) @pytest.fixture(autouse=True) diff --git a/tests/test_width_and_alignment/test_column_max_width.py b/tests/test_width_and_alignment/test_column_max_width.py index 0097ae9..696c9bf 100644 --- a/tests/test_width_and_alignment/test_column_max_width.py +++ b/tests/test_width_and_alignment/test_column_max_width.py @@ -3,7 +3,6 @@ import pytest from terminaltables.width_and_alignment import column_max_width, max_dimensions -from tests import MULTI_LINE, SINGLE_LINE @pytest.fixture(autouse=True) @@ -28,7 +27,13 @@ def test_empty(): def test_single_line(): """Test with single-line cells.""" - inner_widths = max_dimensions(SINGLE_LINE)[0] + table_data = [ + ['Name', 'Color', 'Type'], + ['Avocado', 'green', 'nut'], + ['Tomato', 'red', 'fruit'], + ['Lettuce', 'green', 'vegetable'], + ] + inner_widths = max_dimensions(table_data)[0] # '| Lettuce | green | vegetable |' outer, inner, padding = 2, 1, 2 @@ -85,7 +90,13 @@ def test_multi_line(monkeypatch): :param monkeypatch: pytest fixture. """ - inner_widths = max_dimensions(MULTI_LINE)[0] + 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'] + ] + inner_widths = max_dimensions(table_data)[0] outer, inner, padding = 2, 1, 2 assert column_max_width(inner_widths, 0, outer, inner, padding) == -11 diff --git a/tests/test_width_and_alignment/test_max_dimensions.py b/tests/test_width_and_alignment/test_max_dimensions.py index c2f3f34..dccbf07 100644 --- a/tests/test_width_and_alignment/test_max_dimensions.py +++ b/tests/test_width_and_alignment/test_max_dimensions.py @@ -7,7 +7,6 @@ from termcolor import colored from terminaltables.width_and_alignment import max_dimensions -from tests import MULTI_LINE @pytest.mark.parametrize('table_data,expected_w,expected_h', [ @@ -51,7 +50,13 @@ def test_multi_line(): ] assert max_dimensions(table_data, 0, 0, 1, 1) == ([3, 6], [3], [3, 6], [5]) - assert max_dimensions(MULTI_LINE, 0, 0, 2, 2) == ([10, 83], [1, 2, 1], [10, 83], [5, 6, 5]) + 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'] + ] + assert max_dimensions(table_data, 0, 0, 2, 2) == ([10, 83], [1, 2, 1], [10, 83], [5, 6, 5]) def test_trailing_newline(): diff --git a/tests/test_width_and_alignment/test_table_width.py b/tests/test_width_and_alignment/test_table_width.py index 59cb2a1..5818789 100644 --- a/tests/test_width_and_alignment/test_table_width.py +++ b/tests/test_width_and_alignment/test_table_width.py @@ -1,7 +1,6 @@ """Test function in module.""" from terminaltables.width_and_alignment import max_dimensions, table_width -from tests import MULTI_LINE, SINGLE_LINE def test_empty(): @@ -17,8 +16,15 @@ def test_empty(): 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(SINGLE_LINE, 1, 1)[2] + outer, inner, outer_widths = 2, 1, max_dimensions(table_data, 1, 1)[2] assert table_width(outer_widths, outer, inner) == 31 # ' Lettuce | green | vegetable ' @@ -34,11 +40,11 @@ def test_single_line(): assert table_width(outer_widths, outer, inner) == 27 # '|Lettuce |green |vegetable |' - outer, inner, outer_widths = 2, 1, max_dimensions(SINGLE_LINE, 1)[2] + 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(SINGLE_LINE, 3, 2)[2] + outer_widths = max_dimensions(table_data, 3, 2)[2] assert table_width(outer_widths, outer, inner) == 40 table_data = [ @@ -54,5 +60,11 @@ def test_single_line(): def test_multi_line(): """Test with multi-line cells.""" - outer, inner, outer_widths = 2, 1, max_dimensions(MULTI_LINE, 1, 1)[2] + 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