From 77403d56e9817dfa212085698057c1e108c4fc2a Mon Sep 17 00:00:00 2001 From: Yugang Wang Date: Tue, 31 Jul 2018 15:11:14 -0700 Subject: [PATCH] tab output: disable number parse (#88) --- knack/output.py | 3 ++- tests/test_output.py | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/knack/output.py b/knack/output.py index 961e060..49d3bba 100644 --- a/knack/output.py +++ b/knack/output.py @@ -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' diff --git a/tests/test_output.py b/tests/test_output.py index 4897232..f87ce01 100644 --- a/tests/test_output.py +++ b/tests/test_output.py @@ -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): @@ -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