<s> from genty import genty , genty_dataset <EOL> import os <EOL> from tempfile import mkstemp <EOL> from app . common . console_output import ConsoleOutput <EOL> from test . framework . base_integration_test_case import BaseIntegrationTestCase <EOL> @ genty <EOL> class TestConsoleOutput ( BaseIntegrationTestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> console_output = [ ] <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> console_output . append ( '<STR_LIT>' + str ( i ) ) <EOL> cls . _completed_console_output_fd , cls . _completed_console_output_file_path = mkstemp ( ) <EOL> with open ( cls . _completed_console_output_file_path , '<STR_LIT:w>' ) as f : <EOL> f . write ( "<STR_LIT:\n>" . join ( console_output ) + "<STR_LIT:\n>" ) <EOL> cls . _incomplete_console_output_fd , cls . _incomplete_console_output_file_path = mkstemp ( ) <EOL> with open ( cls . _incomplete_console_output_file_path , '<STR_LIT:w>' ) as f : <EOL> f . write ( "<STR_LIT:\n>" . join ( console_output ) ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> os . close ( cls . _completed_console_output_fd ) <EOL> os . close ( cls . _incomplete_console_output_fd ) <EOL> os . remove ( cls . _completed_console_output_file_path ) <EOL> os . remove ( cls . _incomplete_console_output_file_path ) <EOL> @ genty_dataset ( <EOL> happy_path_zero_offset = ( <NUM_LIT:5> , <NUM_LIT:0> , <NUM_LIT:5> , <NUM_LIT:0> , <NUM_LIT:10> , "<STR_LIT>" ) , <EOL> happy_path_mid_offset_1 = ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:10> , "<STR_LIT>" ) , <EOL> happy_path_mid_offset_2 = ( <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:10> , "<STR_LIT>" ) , <EOL> out_of_lines_near_end_offset = ( <NUM_LIT:5> , <NUM_LIT:7> , <NUM_LIT:3> , <NUM_LIT:7> , <NUM_LIT:10> , "<STR_LIT>" ) , <EOL> happy_path_no_offset_1 = ( <NUM_LIT:5> , None , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:10> , "<STR_LIT>" ) , <EOL> happy_path_no_offset_2 = ( <NUM_LIT:1> , None , <NUM_LIT:1> , <NUM_LIT:9> , <NUM_LIT:10> , "<STR_LIT>" ) , <EOL> out_of_lines_no_offset = ( <NUM_LIT:200> , None , <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:10> , <EOL> "<STR_LIT>" ) , <EOL> ) <EOL> def test_segment_for_completed_console_output ( <EOL> self , <EOL> input_max_lines , <EOL> input_offset_line , <EOL> expected_num_lines , <EOL> expected_offset_line , <EOL> expected_total_num_lines , <EOL> expected_content <EOL> ) : <EOL> """<STR_LIT>""" <EOL> console_output = ConsoleOutput ( self . _completed_console_output_file_path ) <EOL> segment = console_output . segment ( max_lines = input_max_lines , offset_line = input_offset_line ) <EOL> self . assertEquals ( segment . num_lines , expected_num_lines ) <EOL> self . assertEquals ( segment . offset_line , expected_offset_line ) <EOL> self . assertEquals ( segment . total_num_lines , expected_total_num_lines ) <EOL> self . assertEquals ( segment . content , expected_content ) <EOL> @ genty_dataset ( <EOL> mid_offset = ( <NUM_LIT:15> , <NUM_LIT:5> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:9> , "<STR_LIT>" ) , <EOL> no_offset = ( <NUM_LIT:15> , None , <NUM_LIT:9> , <NUM_LIT:0> , <NUM_LIT:9> , "<STR_LIT>" ) , <EOL> mid_lines_no_offset = ( <NUM_LIT:4> , None , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:9> , "<STR_LIT>" ) , <EOL> ) <EOL> def test_segment_for_incomplete_console_output ( <EOL> self , <EOL> input_max_lines , <EOL> input_offset_line , <EOL> expected_num_lines , <EOL> expected_offset_line , <EOL> expected_total_num_lines , <EOL> expected_content <EOL> ) : <EOL> """<STR_LIT>""" <EOL> console_output = ConsoleOutput ( self . _incomplete_console_output_file_path ) <EOL> segment = console_output . segment ( max_lines = input_max_lines , offset_line = input_offset_line ) <EOL> self . assertEquals ( segment . num_lines , expected_num_lines ) <EOL> self . assertEquals ( segment . offset_line , expected_offset_line ) <EOL> self . assertEquals ( segment . total_num_lines , expected_total_num_lines ) <EOL> self . assertEquals ( segment . content , expected_content ) <EOL> def test_segment_raises_value_error_if_offset_greater_than_total_length ( self ) : <EOL> with self . assertRaises ( ValueError ) : <EOL> console_output = ConsoleOutput ( self . _completed_console_output_file_path ) <EOL> console_output . segment ( max_lines = <NUM_LIT:5> , offset_line = <NUM_LIT> ) </s>
