Skip to content

Commit ce76700

Browse files
Merge pull request #1697 from allmightyspiff/issues1658
Fixed an issue with printing tables that contained empty items
2 parents 2b777c2 + 02b8d6a commit ce76700

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

SoftLayer/CLI/formatting.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ def format_prettytable(table, fmt='table'):
7272
"""Converts SoftLayer.CLI.formatting.Table instance to a prettytable."""
7373
for i, row in enumerate(table.rows):
7474
for j, item in enumerate(row):
75-
table.rows[i][j] = format_output(item)
75+
# Issue when adding items that evaulate to None (like empty lists) for Rich Tables
76+
# so we just cast those to a str
77+
if item:
78+
table.rows[i][j] = format_output(item)
79+
else:
80+
table.rows[i][j] = str(item)
7681
ptable = table.prettytable(fmt)
7782
return ptable
7883

tests/CLI/helper_tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,3 +484,13 @@ def test_format_api_list_with_none_value(self):
484484

485485
self.assertIsInstance(result, formatting.Table)
486486
self.assertEqual(result.columns, ['key'])
487+
488+
def test_format_api_list_with_empty_array(self):
489+
result = formatting.iter_to_table([{'id': 130224450, 'activeTickets': []}])
490+
self.assertIsInstance(result, formatting.Table)
491+
self.assertIn('id', result.columns)
492+
self.assertIn('activeTickets', result.columns)
493+
formatted = formatting.format_output(result, "table")
494+
# No good ways to test whats actually in a Rich.Table without going through the hassel of
495+
# printing it out. As long as this didn't throw and exception it should be fine.
496+
self.assertEqual(formatted.row_count, 1)

0 commit comments

Comments
 (0)