<s> import unittest <EOL> from awscli . compat import six <EOL> from awscli . formatter import TableFormatter <EOL> from awscli . table import MultiTable , Styler <EOL> SIMPLE_LIST = { <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> } <EOL> SIMPLE_LIST_TABLE = """<STR_LIT>""" <EOL> SIMPLE_DICT = { "<STR_LIT>" : <EOL> { "<STR_LIT:a>" : "<STR_LIT:0>" , <EOL> "<STR_LIT:b>" : "<STR_LIT>" , <EOL> "<STR_LIT:c>" : "<STR_LIT:0>" , <EOL> "<STR_LIT:d>" : "<STR_LIT>" , <EOL> "<STR_LIT:e>" : "<STR_LIT>" , <EOL> "<STR_LIT:f>" : "<STR_LIT:0>" } <EOL> } <EOL> SIMPLE_DICT_TABLE = """<STR_LIT>""" <EOL> LIST_OF_DICTS = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:Name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False <EOL> } , <EOL> { <EOL> "<STR_LIT:Name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True <EOL> } <EOL> ] , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : False <EOL> } , <EOL> { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:Name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True <EOL> } , <EOL> { <EOL> "<STR_LIT:Name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True <EOL> } <EOL> ] , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : False <EOL> } , <EOL> { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT:Name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True <EOL> } , <EOL> ] , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : True <EOL> } <EOL> ] <EOL> } <EOL> LIST_OF_DICTS_TABLE = """<STR_LIT>""" <EOL> INNER_LIST = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT:Name>" } ] , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:8> , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:8> , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> ] <EOL> } <EOL> INNER_LIST_TABLE = """<STR_LIT>""" <EOL> LIST_WITH_MISSING_KEYS = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:foo>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:8> , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT:description>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:8> , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> ] <EOL> } <EOL> LIST_WITH_MISSING_KEYS_TABLE = """<STR_LIT>""" <EOL> KEYS_NOT_FROM_FIRST_ROW = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:foo>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:8> , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT:description>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:8> , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> ] <EOL> } <EOL> KEYS_NOT_FROM_FIRST_ROW_TABLE = """<STR_LIT>""" <EOL> JMESPATH_FILTERED_RESPONSE = [ <EOL> [ <EOL> [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> ] , <EOL> [ <EOL> [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> ] , <EOL> ] <EOL> JMESPATH_FILTERED_RESPONSE_TABLE = """<STR_LIT>""" <EOL> JMESPATH_FILTERED_RESPONSE_DICT = [ <EOL> [ <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> ] , <EOL> [ <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> ] , <EOL> ] <EOL> JMESPATH_FILTERED_RESPONSE_DICT_TABLE = """<STR_LIT>""" <EOL> class Object ( object ) : <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . __dict__ . update ( kwargs ) <EOL> self . query = None <EOL> class TestTableFormatter ( unittest . TestCase ) : <EOL> maxDiff = None <EOL> def setUp ( self ) : <EOL> styler = Styler ( ) <EOL> self . table = MultiTable ( initial_section = False , <EOL> column_separator = '<STR_LIT:|>' , styler = styler , <EOL> auto_reformat = False ) <EOL> self . formatter = TableFormatter ( Object ( color = '<STR_LIT>' ) ) <EOL> self . formatter . table = self . table <EOL> self . stream = six . StringIO ( ) <EOL> def assert_data_renders_to ( self , data , table ) : <EOL> self . formatter ( '<STR_LIT>' , data , stream = self . stream ) <EOL> rendered = self . stream . getvalue ( ) <EOL> if rendered != table : <EOL> error_message = [ '<STR_LIT>' <EOL> '<STR_LIT>' ] <EOL> error_message . append ( '<STR_LIT>' ) <EOL> error_message . append ( table ) <EOL> error_message . append ( '<STR_LIT>' ) <EOL> error_message . append ( rendered ) <EOL> self . fail ( '<STR_LIT:\n>' . join ( error_message ) ) <EOL> def test_list_table ( self ) : <EOL> self . assert_data_renders_to ( data = SIMPLE_LIST , table = SIMPLE_LIST_TABLE ) <EOL> def test_dict_table ( self ) : <EOL> self . assert_data_renders_to ( data = SIMPLE_DICT , table = SIMPLE_DICT_TABLE ) <EOL> def test_list_of_dicts ( self ) : <EOL> self . assert_data_renders_to ( data = LIST_OF_DICTS , <EOL> table = LIST_OF_DICTS_TABLE ) <EOL> def test_inner_table ( self ) : <EOL> self . assert_data_renders_to ( data = INNER_LIST , <EOL> table = INNER_LIST_TABLE ) <EOL> def test_empty_table ( self ) : <EOL> self . assert_data_renders_to ( data = { } , <EOL> table = '<STR_LIT>' ) <EOL> def test_missing_keys ( self ) : <EOL> self . assert_data_renders_to ( data = LIST_WITH_MISSING_KEYS , <EOL> table = LIST_WITH_MISSING_KEYS_TABLE ) <EOL> def test_new_keys_after_first_row ( self ) : <EOL> self . assert_data_renders_to ( data = KEYS_NOT_FROM_FIRST_ROW , <EOL> table = KEYS_NOT_FROM_FIRST_ROW_TABLE ) <EOL> def test_jmespath_filtered_response ( self ) : <EOL> self . assert_data_renders_to ( data = JMESPATH_FILTERED_RESPONSE , <EOL> table = JMESPATH_FILTERED_RESPONSE_TABLE ) <EOL> def test_jmespath_filtered_dict_response ( self ) : <EOL> self . assert_data_renders_to ( data = JMESPATH_FILTERED_RESPONSE_DICT , <EOL> table = JMESPATH_FILTERED_RESPONSE_DICT_TABLE ) </s>
