Skip to content

Commit

Permalink
fix and workflow update
Browse files Browse the repository at this point in the history
  • Loading branch information
hvalev committed Aug 14, 2022
1 parent 6e36156 commit abebae0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
19 changes: 4 additions & 15 deletions markdownTable/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])):
Expand Down Expand Up @@ -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(" ")
Expand Down Expand Up @@ -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 = {}
Expand All @@ -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
Expand All @@ -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())
4 changes: 3 additions & 1 deletion tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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

0 comments on commit abebae0

Please sign in to comment.