Skip to content

Commit

Permalink
tab output: disable number parse (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
yugangw-msft authored Jul 31, 2018
1 parent 7cbee25 commit 77403d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion knack/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ def _auto_table(self, result):
def dump(self, data):
from tabulate import tabulate
table_data = self._auto_table(data)
table_str = tabulate(table_data, headers="keys", tablefmt="simple") if table_data else ''
table_str = tabulate(table_data, headers="keys", tablefmt="simple",
disable_numparse=True) if table_data else ''
if table_str == '\n':
raise ValueError('Unable to extract fields for table.')
return table_str + '\n'
Expand Down
15 changes: 13 additions & 2 deletions tests/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ def test_out_table(self):
obj['lun'] = 0
output_producer.out(CommandResultItem(obj), formatter=format_table, out_file=self.io)
self.assertEqual(normalize_newlines(self.io.getvalue()), normalize_newlines(
"""Active Lun Val
"""Active Lun Val
-------- ----- --------
True 0 0b1f6472
True 0 0b1f6472
"""))

def test_out_table_list_of_lists(self):
Expand Down Expand Up @@ -158,6 +158,17 @@ def test_out_table_no_query_yes_jmespath_table_transformer(self):
"""Name Val Active
------ -------------- --------
qwerty 0b1f6472qwerty True
"""))

def test_out_table_with_number(self):
output_producer = OutputProducer(cli_ctx=self.mock_ctx)
obj = OrderedDict()
obj['Sku'] = '6.10'
output_producer.out(CommandResultItem(obj), formatter=format_table, out_file=self.io)
self.assertEqual(normalize_newlines(self.io.getvalue()), normalize_newlines(
"""Sku
-----
6.10
"""))

# TSV output tests
Expand Down

0 comments on commit 77403d5

Please sign in to comment.