From 40468d609d71ef97acc8c6774e99ee74ff4d5eda Mon Sep 17 00:00:00 2001 From: Or Carmi Date: Tue, 2 Aug 2016 13:58:58 +0300 Subject: [PATCH 1/5] Created PorcelainTable class --- terminaltables/other_tables.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/terminaltables/other_tables.py b/terminaltables/other_tables.py index 8aa5c14..1dffa22 100644 --- a/terminaltables/other_tables.py +++ b/terminaltables/other_tables.py @@ -153,3 +153,20 @@ class DoubleTable(WindowsTableDouble): """ pass + + +class PorcelainTable(AsciiTable): + """ An AsciiTable stripped to a minimum, meant to be machine passable and roughly follow format set by git + --porcelain option (hence the name) + """ + + def __init__(self, table_data): + """ + :param iter table_data: List (empty or list of lists of strings) representing the table. + """ + super(PorcelainTable, self).__init__(table_data) + + # Removes outer border, and inner footing and header row borders. + self.inner_footing_row_border = False + self.inner_heading_row_border = False + self.outer_border = False From d1ef101e64423e79766d9d306e2a464b2a31f5d2 Mon Sep 17 00:00:00 2001 From: Or Carmi Date: Tue, 2 Aug 2016 15:39:31 +0300 Subject: [PATCH 2/5] Fixed doc issues --- terminaltables/other_tables.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/terminaltables/other_tables.py b/terminaltables/other_tables.py index 1dffa22..280ddb8 100644 --- a/terminaltables/other_tables.py +++ b/terminaltables/other_tables.py @@ -156,14 +156,19 @@ class DoubleTable(WindowsTableDouble): class PorcelainTable(AsciiTable): - """ An AsciiTable stripped to a minimum, meant to be machine passable and roughly follow format set by git - --porcelain option (hence the name) - """ + """ An AsciiTable stripped to a minimum. + + Meant to be machine passable and roughly follow format set by git --porcelain option (hence the name). + + :ivar iter table_data: List (empty or list of lists of strings) representing the table. + """ def __init__(self, table_data): - """ + """Constructor. + :param iter table_data: List (empty or list of lists of strings) representing the table. """ + # Porcelain table won't support title since it has no outer birders. super(PorcelainTable, self).__init__(table_data) # Removes outer border, and inner footing and header row borders. From 16b2b59d9d87bb7c1c3ec60500d78db8fe395f50 Mon Sep 17 00:00:00 2001 From: Or Carmi Date: Tue, 2 Aug 2016 16:38:18 +0300 Subject: [PATCH 3/5] Hopefully fixed another doc issue --- terminaltables/other_tables.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terminaltables/other_tables.py b/terminaltables/other_tables.py index 280ddb8..50c0bcd 100644 --- a/terminaltables/other_tables.py +++ b/terminaltables/other_tables.py @@ -156,7 +156,7 @@ class DoubleTable(WindowsTableDouble): class PorcelainTable(AsciiTable): - """ An AsciiTable stripped to a minimum. + """An AsciiTable stripped to a minimum. Meant to be machine passable and roughly follow format set by git --porcelain option (hence the name). From bff160e7ed7e141a038be86689f9f64d882685e6 Mon Sep 17 00:00:00 2001 From: Or Carmi Date: Wed, 3 Aug 2016 11:23:23 +0300 Subject: [PATCH 4/5] Created test --- terminaltables/__init__.py | 1 + .../test_porcelain_table.py | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 tests/test_all_tables_e2e/test_porcelain_table.py diff --git a/terminaltables/__init__.py b/terminaltables/__init__.py index 66b9295..3856d60 100644 --- a/terminaltables/__init__.py +++ b/terminaltables/__init__.py @@ -10,6 +10,7 @@ from terminaltables.github_table import GithubFlavoredMarkdownTable # noqa from terminaltables.other_tables import DoubleTable # noqa from terminaltables.other_tables import SingleTable # noqa +from terminaltables.other_tables import PorcelainTable # noqa __author__ = '@Robpol86' __license__ = 'MIT' diff --git a/tests/test_all_tables_e2e/test_porcelain_table.py b/tests/test_all_tables_e2e/test_porcelain_table.py new file mode 100644 index 0000000..c060df8 --- /dev/null +++ b/tests/test_all_tables_e2e/test_porcelain_table.py @@ -0,0 +1,60 @@ +"""PorcelainTable end to end testing.""" + +from terminaltables import PorcelainTable + + +def test_single_line(): + """Test single-lined cells.""" + table_data = [ + ['Name', 'Color', 'Type'], + ['Avocado', 'green', 'nut'], + ['Tomato', 'red', 'fruit'], + ['Lettuce', 'green', 'vegetable'], + ['Watermelon', 'green'] + ] + table = PorcelainTable(table_data) + table.justify_columns[0] = 'left' + table.justify_columns[1] = 'center' + table.justify_columns[2] = 'right' + actual = table.table + + expected = ( + ' Name | Color | Type \n' + ' Avocado | green | nut \n' + ' Tomato | red | fruit \n' + ' Lettuce | green | vegetable \n' + ' Watermelon | green | ' + ) + assert actual == expected + + +def test_multi_line(): + """Test multi-lined cells.""" + table_data = [ + ['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'] + ] + table = PorcelainTable(table_data) + + # Test defaults. + actual = table.table + expected = ( + ' Show | Characters \n' + ' Rugrats | Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille, Angelica Pickles, \n' + ' | Dil Pickles \n' + ' South Park | Stan Marsh, Kyle Broflovski, Eric Cartman, Kenny McCormick ' + ) + assert actual == expected + + + # Justify right. + table.justify_columns = {1: 'right'} + actual = table.table + expected = ( + ' Show | Characters \n' + ' Rugrats | Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille, Angelica Pickles, \n' + ' | Dil Pickles \n' + ' South Park | Stan Marsh, Kyle Broflovski, Eric Cartman, Kenny McCormick ' + ) + assert actual == expected From 8dc71ccade8fa7fd1ee1d7e0c949ecd4532bcb64 Mon Sep 17 00:00:00 2001 From: Or Carmi Date: Wed, 3 Aug 2016 11:30:36 +0300 Subject: [PATCH 5/5] Fixed styling --- tests/test_all_tables_e2e/test_porcelain_table.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_all_tables_e2e/test_porcelain_table.py b/tests/test_all_tables_e2e/test_porcelain_table.py index c060df8..7677188 100644 --- a/tests/test_all_tables_e2e/test_porcelain_table.py +++ b/tests/test_all_tables_e2e/test_porcelain_table.py @@ -24,7 +24,7 @@ def test_single_line(): ' Tomato | red | fruit \n' ' Lettuce | green | vegetable \n' ' Watermelon | green | ' - ) + ) assert actual == expected @@ -47,7 +47,6 @@ def test_multi_line(): ) assert actual == expected - # Justify right. table.justify_columns = {1: 'right'} actual = table.table