diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eaf6557..c999f1d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,7 @@ on: jobs: test: name: Set up python matrix for testing - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 strategy: matrix: python-version: [3.6, 3.7, 3.8, 3.9, '3.10', '3.x'] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f717030..713b28c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ on: jobs: test: name: Set up python matrix for testing - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 strategy: matrix: python-version: [3.6, 3.7, 3.8, 3.9, '3.10', '3.x'] diff --git a/markdownTable/__init__.py b/markdownTable/__init__.py index 4386d54..26b27f0 100644 --- a/markdownTable/__init__.py +++ b/markdownTable/__init__.py @@ -89,12 +89,12 @@ def getPadding(self): padding[item] = len(item) for item in self.data: for key in item.keys(): - if(type(item[key]) is float and self.float_rounding): + if (type(item[key]) is float and self.float_rounding): item[key] = round(item[key], self.float_rounding) if self.multiline: multiline_data = item[key].split(" ") multiline_min_width = max(multiline_data, key=len) - if (padding[key]+self.padding_width) < len(multiline_min_width) +self.padding_width: + if (padding[key]+self.padding_width) < len(multiline_min_width) + self.padding_width: padding[key] = len(multiline_min_width)+self.padding_width else: if (padding[key]-self.padding_width) < len(str(item[key])): @@ -175,7 +175,6 @@ def getNormalRow(self, item): return row def getMultilineRow(self, item): - row = '' multiline_items = {} for key in self.data[0].keys(): items = item[key].split(" ") @@ -203,7 +202,7 @@ def getMultilineRow(self, item): if len(value) < multiline_rows: for i in range(len(value), multiline_rows): multiline_items[key].append(" ") - + rows = '' for ix in range(0, multiline_rows): row_dict = {} @@ -214,12 +213,11 @@ def getMultilineRow(self, item): rows += self.newline_char return rows - def getBody(self): rows = '' for ix, item in enumerate(self.data): rows += self.getRow(item) - if(ix < len(self.data)-1): + if (ix < len(self.data)-1): rows += self.newline_char if self.row_sep == 'always' and ix < len(self.data)-1: rows += self.var_row_sep + self.newline_char @@ -234,12 +232,3 @@ def getMarkdown(self): return '```'+data+'```' else: return data - -test = [{"A": "row1_A and additional stuff", "B": "row1_B", "C": "row1_C"}, - {"A": "row2_A", "B": "row2_B and additional stuff", "C": "row2_C"}, - {"A": "row3_A", "B": "row3_B", "C": "row3_C"}] -tabletest = markdownTable(test).setParams(padding_width=2, - padding_weight="centerleft", - quote=False, - multiline=True) -print(tabletest.getMarkdown()) \ No newline at end of file diff --git a/tests/tests.py b/tests/tests.py index d4b1cee..456ebd6 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -19,6 +19,7 @@ {"A": "row2_A", "B": "row2_B and additional stuff", "C": "row2_C"}, {"A": "row3_A", "B": "row3_B", "C": "row3_C"}] + def test_bad_data_missing_data(): with pytest.raises(Exception): markdownTable(bad_data_0).getMarkdown() @@ -81,7 +82,8 @@ def test_formatting_padding_char(): res = '```\n+------------------------------------------------------------+\n|......title......|......time......|.....date.....|..seats...|\n+-----------------+----------------+--------------+----------+\n|..Vrij Zwemmen...|..21:30-23:00...|..Wed 09.12...|..24/24...|\n+-----------------+----------------+--------------+----------+\n|..Vrij Zwemmen...|..12:00-13:00...|..Thu 10.12...|..18/18...|\n+-----------------+----------------+--------------+----------+\n|..Vrij Zwemmen...|...7:30-8:30....|..Fri 11.12...|..18/18...|\n+-----------------+----------------+--------------+----------+\n|..Vrij Zwemmen...|..13:15-14:15...|..Sat 12.12...|..18/18...|\n+------------------------------------------------------------+```' assert mt == res + def test_multiline_data(): - mt = markdownTable(multiline_data).setParams(padding_width=2,padding_weight="centerleft",multiline=True).getMarkdown() + mt = markdownTable(multiline_data).setParams(padding_width=2, padding_weight="centerleft", multiline=True).getMarkdown() res = '```\n+----------------------------------+\n| A | B | C |\n+------------+------------+--------+\n| row1_A and | row1_B | row1_C |\n| additional | | |\n| stuff | | |\n+------------+------------+--------+\n| row2_A | row2_B and | row2_C |\n| | additional | |\n| | stuff | |\n+------------+------------+--------+\n| row3_A | row3_B | row3_C |\n+----------------------------------+```' assert mt == res