<s> import sys <EOL> from robot . errors import DataError <EOL> from robot . utils import get_console_length , isatty , pad_console_length <EOL> from . highlighting import HighlightingStream <EOL> class VerboseOutput ( object ) : <EOL> def __init__ ( self , width = <NUM_LIT> , colors = '<STR_LIT>' , markers = '<STR_LIT>' , stdout = None , <EOL> stderr = None ) : <EOL> self . _writer = VerboseWriter ( width , colors , markers , stdout , stderr ) <EOL> self . _started = False <EOL> self . _started_keywords = <NUM_LIT:0> <EOL> self . _running_test = False <EOL> def start_suite ( self , suite ) : <EOL> if not self . _started : <EOL> self . _writer . suite_separator ( ) <EOL> self . _started = True <EOL> self . _writer . info ( suite . longname , suite . doc , start_suite = True ) <EOL> self . _writer . suite_separator ( ) <EOL> def end_suite ( self , suite ) : <EOL> self . _writer . info ( suite . longname , suite . doc ) <EOL> self . _writer . status ( suite . status ) <EOL> self . _writer . message ( suite . full_message ) <EOL> self . _writer . suite_separator ( ) <EOL> def start_test ( self , test ) : <EOL> self . _writer . info ( test . name , test . doc ) <EOL> self . _running_test = True <EOL> def end_test ( self , test ) : <EOL> self . _writer . status ( test . status , clear = True ) <EOL> self . _writer . message ( test . message ) <EOL> self . _writer . test_separator ( ) <EOL> self . _running_test = False <EOL> def start_keyword ( self , kw ) : <EOL> self . _started_keywords += <NUM_LIT:1> <EOL> def end_keyword ( self , kw ) : <EOL> self . _started_keywords -= <NUM_LIT:1> <EOL> if self . _running_test and not self . _started_keywords : <EOL> self . _writer . keyword_marker ( kw . status ) <EOL> def message ( self , msg ) : <EOL> if msg . level in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . _writer . error ( msg . message , msg . level , clear = self . _running_test ) <EOL> def output_file ( self , name , path ) : <EOL> self . _writer . output ( name , path ) <EOL> class VerboseWriter ( object ) : <EOL> _status_length = len ( '<STR_LIT>' ) <EOL> def __init__ ( self , width = <NUM_LIT> , colors = '<STR_LIT>' , markers = '<STR_LIT>' , stdout = None , <EOL> stderr = None ) : <EOL> self . _width = width <EOL> self . _stdout = HighlightingStream ( stdout or sys . __stdout__ , colors ) <EOL> self . _stderr = HighlightingStream ( stderr or sys . __stderr__ , colors ) <EOL> self . _keyword_marker = KeywordMarker ( self . _stdout , markers ) <EOL> self . _last_info = None <EOL> def info ( self , name , doc , start_suite = False ) : <EOL> width , separator = self . _get_info_width_and_separator ( start_suite ) <EOL> self . _last_info = self . _get_info ( name , doc , width ) + separator <EOL> self . _write_info ( ) <EOL> self . _keyword_marker . reset_count ( ) <EOL> def _write_info ( self ) : <EOL> self . _stdout . write ( self . _last_info ) <EOL> def _get_info_width_and_separator ( self , start_suite ) : <EOL> if start_suite : <EOL> return self . _width , '<STR_LIT:\n>' <EOL> return self . _width - self . _status_length - <NUM_LIT:1> , '<STR_LIT:U+0020>' <EOL> def _get_info ( self , name , doc , width ) : <EOL> if get_console_length ( name ) > width : <EOL> return pad_console_length ( name , width ) <EOL> info = name if not doc else '<STR_LIT>' % ( name , doc . splitlines ( ) [ <NUM_LIT:0> ] ) <EOL> return pad_console_length ( info , width ) <EOL> def suite_separator ( self ) : <EOL> self . _fill ( '<STR_LIT:=>' ) <EOL> def test_separator ( self ) : <EOL> self . _fill ( '<STR_LIT:->' ) <EOL> def _fill ( self , char ) : <EOL> self . _stdout . write ( '<STR_LIT>' % ( char * self . _width ) ) <EOL> def status ( self , status , clear = False ) : <EOL> if self . _should_clear_markers ( clear ) : <EOL> self . _clear_status ( ) <EOL> self . _stdout . write ( '<STR_LIT>' , flush = False ) <EOL> self . _stdout . highlight ( status , flush = False ) <EOL> self . _stdout . write ( '<STR_LIT>' ) <EOL> def _should_clear_markers ( self , clear ) : <EOL> return clear and self . _keyword_marker . marking_enabled <EOL> def _clear_status ( self ) : <EOL> self . _clear_info ( ) <EOL> self . _write_info ( ) <EOL> def _clear_info ( self ) : <EOL> self . _stdout . write ( '<STR_LIT>' % ( '<STR_LIT:U+0020>' * self . _width ) ) <EOL> self . _keyword_marker . reset_count ( ) <EOL> def message ( self , message ) : <EOL> if message : <EOL> self . _stdout . write ( message . strip ( ) + '<STR_LIT:\n>' ) <EOL> def keyword_marker ( self , status ) : <EOL> if self . _keyword_marker . marker_count == self . _status_length : <EOL> self . _clear_status ( ) <EOL> self . _keyword_marker . reset_count ( ) <EOL> self . _keyword_marker . mark ( status ) <EOL> def error ( self , message , level , clear = False ) : <EOL> if self . _should_clear_markers ( clear ) : <EOL> self . _clear_info ( ) <EOL> self . _stderr . error ( message , level ) <EOL> if self . _should_clear_markers ( clear ) : <EOL> self . _write_info ( ) <EOL> def output ( self , name , path ) : <EOL> self . _stdout . write ( '<STR_LIT>' % ( name + '<STR_LIT::>' , path ) ) <EOL> class KeywordMarker ( object ) : <EOL> def __init__ ( self , highlighter , markers ) : <EOL> self . _highlighter = highlighter <EOL> self . marking_enabled = self . _marking_enabled ( markers , highlighter ) <EOL> self . marker_count = <NUM_LIT:0> <EOL> def _marking_enabled ( self , markers , highlighter ) : <EOL> options = { '<STR_LIT>' : isatty ( highlighter . stream ) , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False } <EOL> try : <EOL> return options [ markers . upper ( ) ] <EOL> except KeyError : <EOL> raise DataError ( "<STR_LIT>" <EOL> "<STR_LIT>" % markers ) <EOL> def mark ( self , status ) : <EOL> if self . marking_enabled : <EOL> marker , status = ( '<STR_LIT:.>' , '<STR_LIT>' ) if status != '<STR_LIT>' else ( '<STR_LIT:F>' , '<STR_LIT>' ) <EOL> self . _highlighter . highlight ( marker , status ) <EOL> self . marker_count += <NUM_LIT:1> <EOL> def reset_count ( self ) : <EOL> self . marker_count = <NUM_LIT:0> </s>
