Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_out_table_no_query_no_transformer_order(self):
output_producer = OutputProducer(cli_ctx=self.mock_ctx)
obj = {'name': 'qwerty', 'val': '0b1f6472qwerty', 'active': True, 'sub': '0b1f6472'}
result_item = CommandResultItem(obj, table_transformer=None, is_query_active=False)
output_producer.out(result_item, formatter=format_table, out_file=self.io)
# Should be alphabetical order as no table transformer and query is not active.
self.assertEqual(normalize_newlines(self.io.getvalue()), normalize_newlines(
"""Active Name Sub Val
-------- ------ -------- --------------
def test_out_table_no_query_yes_jmespath_table_transformer(self):
output_producer = OutputProducer(cli_ctx=self.mock_ctx)
obj = {'name': 'qwerty', 'val': '0b1f6472qwerty', 'active': True, 'sub': '0b1f6472'}
result_item = CommandResultItem(obj,
table_transformer='{Name:name, Val:val, Active:active}',
is_query_active=False)
output_producer.out(result_item, formatter=format_table, out_file=self.io)
# Should be table transformer order
self.assertEqual(normalize_newlines(self.io.getvalue()), normalize_newlines(
"""Name Val Active
------ -------------- --------
def test_out_json_non_ASCII(self):
output_producer = OutputProducer(cli_ctx=self.mock_ctx)
output_producer.out(CommandResultItem({'active': True, 'contents': '生活很糟糕'}),
formatter=format_json, out_file=self.io)
self.assertEqual(normalize_newlines(self.io.getvalue()), normalize_newlines(
"""{
"active": true,
def test_out_table_list_of_lists(self):
output_producer = OutputProducer(cli_ctx=self.mock_ctx)
obj = [['a', 'b'], ['c', 'd']]
output_producer.out(CommandResultItem(obj), formatter=format_table, out_file=self.io)
self.assertEqual(normalize_newlines(self.io.getvalue()), normalize_newlines(
"""Column1 Column2
--------- ---------
def test_out_json_byte(self):
output_producer = OutputProducer(cli_ctx=self.mock_ctx)
output_producer.out(CommandResultItem({'active': True, 'contents': b'0b1f6472'}),
formatter=format_json, out_file=self.io)
self.assertEqual(normalize_newlines(self.io.getvalue()), normalize_newlines(
"""{
"active": true,
def test_out_json_valid(self):
"""
The JSON output when the input is a dict should be the dict serialized to JSON
"""
output_producer = OutputProducer(cli_ctx=self.mock_ctx)
output_producer.out(CommandResultItem({'active': True, 'id': '0b1f6472'}),
formatter=format_json, out_file=self.io)
self.assertEqual(normalize_newlines(self.io.getvalue()), normalize_newlines(
"""{
"active": true,
def test_out_table_no_query_yes_transformer_order(self):
output_producer = OutputProducer(cli_ctx=self.mock_ctx)
obj = {'name': 'qwerty', 'val': '0b1f6472qwerty', 'active': True, 'sub': '0b1f6472'}
def transformer(r):
return OrderedDict([('Name', r['name']), ('Val', r['val']),
('Active', r['active']), ('Sub', r['sub'])])
result_item = CommandResultItem(obj, table_transformer=transformer, is_query_active=False)
output_producer.out(result_item, formatter=format_table, out_file=self.io)
# Should be table transformer order
self.assertEqual(normalize_newlines(self.io.getvalue()), normalize_newlines(
"""Name Val Active Sub
------ -------------- -------- --------
def test_out_table_complex_obj(self):
output_producer = OutputProducer(cli_ctx=self.mock_ctx)
obj = OrderedDict()
obj['name'] = 'qwerty'
obj['val'] = '0b1f6472qwerty'
obj['sub'] = {'1'}
result_item = CommandResultItem(obj)
output_producer.out(result_item, formatter=format_table, out_file=self.io)
self.assertEqual(normalize_newlines(self.io.getvalue()), normalize_newlines(
"""Name Val
------ --------------
def test_out_json_byte_empty(self):
output_producer = OutputProducer(cli_ctx=self.mock_ctx)
output_producer.out(CommandResultItem({'active': True, 'contents': b''}),
formatter=format_json, out_file=self.io)
self.assertEqual(normalize_newlines(self.io.getvalue()), normalize_newlines(
"""{
"active": true,