<s> """<STR_LIT>""" <EOL> from __future__ import print_function , absolute_import , unicode_literals <EOL> import osbs . cli . render <EOL> from osbs . cli . render import TablePrinter , get_terminal_size <EOL> from flexmock import flexmock <EOL> LONGEST_VAL1 = "<STR_LIT:l>" * <NUM_LIT:10> <EOL> LONGEST_VAL2 = "<STR_LIT:l>" * <NUM_LIT:100> <EOL> LONGEST_VAL3 = "<STR_LIT:l>" * <NUM_LIT> <EOL> SAMPLE_DATA = [ <EOL> { "<STR_LIT:x>" : "<STR_LIT:H>" * <NUM_LIT:8> , "<STR_LIT:y>" : "<STR_LIT:H>" * <NUM_LIT:20> , "<STR_LIT:z>" : "<STR_LIT:H>" * <NUM_LIT:4> } , <EOL> { "<STR_LIT:x>" : LONGEST_VAL1 , "<STR_LIT:y>" : LONGEST_VAL2 , "<STR_LIT:z>" : "<STR_LIT:a>" } , <EOL> { "<STR_LIT:x>" : "<STR_LIT>" , "<STR_LIT:y>" : "<STR_LIT>" , "<STR_LIT:z>" : LONGEST_VAL3 } , <EOL> ] <EOL> def test_get_terminal_size ( ) : <EOL> result = get_terminal_size ( ) <EOL> assert isinstance ( result , tuple ) <EOL> assert isinstance ( result [ <NUM_LIT:0> ] , int ) or result [ <NUM_LIT:0> ] is None <EOL> assert isinstance ( result [ <NUM_LIT:1> ] , int ) or result [ <NUM_LIT:1> ] is None <EOL> def test_get_longest_val_in_col ( ) : <EOL> p = TablePrinter ( SAMPLE_DATA , [ "<STR_LIT:x>" , "<STR_LIT:y>" ] ) <EOL> assert p . _longest_val_in_column ( "<STR_LIT:x>" ) == len ( LONGEST_VAL1 ) + <NUM_LIT:2> <EOL> assert p . _longest_val_in_column ( "<STR_LIT:y>" ) == len ( LONGEST_VAL2 ) + <NUM_LIT:2> <EOL> def test_get_longest_col_vals ( ) : <EOL> p = TablePrinter ( SAMPLE_DATA , [ "<STR_LIT:x>" , "<STR_LIT:y>" , "<STR_LIT:z>" ] ) <EOL> response = p . get_all_longest_col_lengths ( ) <EOL> assert response [ "<STR_LIT:x>" ] == len ( LONGEST_VAL1 ) + <NUM_LIT:2> <EOL> assert response [ "<STR_LIT:y>" ] == len ( LONGEST_VAL2 ) + <NUM_LIT:2> <EOL> assert response [ "<STR_LIT:z>" ] == len ( LONGEST_VAL3 ) + <NUM_LIT:2> <EOL> def test_print_table ( ) : <EOL> p = TablePrinter ( SAMPLE_DATA , [ "<STR_LIT:x>" , "<STR_LIT:y>" , "<STR_LIT:z>" ] ) <EOL> p . render ( ) <EOL> def test_print_table_with_mocked_terminal ( capsys ) : <EOL> ( flexmock ( osbs . cli . render ) <EOL> . should_receive ( '<STR_LIT>' ) <EOL> . and_return ( <NUM_LIT> , <NUM_LIT> ) <EOL> . once ( ) ) <EOL> short_data = [ { '<STR_LIT:x>' : '<STR_LIT>' , '<STR_LIT:y>' : '<STR_LIT>' , '<STR_LIT:z>' : '<STR_LIT>' } , <EOL> { '<STR_LIT:x>' : '<STR_LIT:x>' * <NUM_LIT:8> , '<STR_LIT:y>' : '<STR_LIT:y>' * <NUM_LIT:20> , '<STR_LIT:z>' : '<STR_LIT:z>' * <NUM_LIT:4> } ] <EOL> p = TablePrinter ( short_data , [ "<STR_LIT:x>" , "<STR_LIT:y>" , "<STR_LIT:z>" ] ) <EOL> p . render ( ) <EOL> out , err = capsys . readouterr ( ) <EOL> expected_header = """<STR_LIT>""" . lstrip ( '<STR_LIT:\n>' ) <EOL> expected_data = """<STR_LIT>""" . lstrip ( '<STR_LIT:\n>' ) <EOL> assert err == expected_header <EOL> assert out == expected_data </s>
