<s> """<STR_LIT>""" <EOL> import sys <EOL> import traceback <EOL> import vroom <EOL> import vroom . buffer <EOL> import vroom . color <EOL> import vroom . controls <EOL> import vroom . messages <EOL> import vroom . shell <EOL> import vroom . test <EOL> import vroom . vim <EOL> STATUS = vroom . Specification ( <EOL> PASS = '<STR_LIT>' , <EOL> ERROR = '<STR_LIT>' , <EOL> FAIL = '<STR_LIT>' ) <EOL> COLORS = { <EOL> STATUS . PASS : vroom . color . GREEN , <EOL> STATUS . ERROR : vroom . color . YELLOW , <EOL> STATUS . FAIL : vroom . color . RED , <EOL> } <EOL> class Writer ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , filename , args ) : <EOL> """<STR_LIT>""" <EOL> self . messages = MessageLogger ( args . dump_messages , args . verbose , args . color ) <EOL> self . commands = CommandLogger ( args . dump_commands , args . verbose , args . color ) <EOL> self . syscalls = SyscallLogger ( args . dump_syscalls , args . verbose , args . color ) <EOL> self . actions = ActionLogger ( args . out , args . verbose , args . color ) <EOL> self . _filename = filename <EOL> def Begin ( self , lines ) : <EOL> """<STR_LIT>""" <EOL> self . actions . Open ( lines ) <EOL> def Write ( self , file = None ) : <EOL> """<STR_LIT>""" <EOL> self . actions . Print ( self . _filename , color = ( <EOL> vroom . color . BOLD , vroom . color . TEAL ) , file = file ) <EOL> self . actions . Print ( '<STR_LIT>' , verbose = True , file = file ) <EOL> self . actions . Write ( self . _filename , file = file ) <EOL> extra = self . messages . Write ( self . _filename , file = file ) <EOL> extra = self . commands . Write ( self . _filename , file = file ) or extra <EOL> extra = self . syscalls . Write ( self . _filename , file = file ) or extra <EOL> self . actions . Print ( '<STR_LIT>' , file = file , verbose = None if extra else True ) <EOL> stats = self . Stats ( ) <EOL> plural = '<STR_LIT>' if stats [ '<STR_LIT>' ] == <NUM_LIT:1> else '<STR_LIT:s>' <EOL> self . actions . Print ( '<STR_LIT>' % ( <EOL> stats [ '<STR_LIT>' ] , plural , self . _filename ) , end = '<STR_LIT:U+0020>' ) <EOL> self . actions . PutStat ( stats , STATUS . PASS , '<STR_LIT>' , file = file ) <EOL> self . actions . PutStat ( stats , STATUS . ERROR , '<STR_LIT>' , file = file ) <EOL> self . actions . PutStat ( stats , STATUS . FAIL , '<STR_LIT>' , file = file , end = '<STR_LIT>' ) <EOL> if stats [ '<STR_LIT>' ] == <NUM_LIT:0> : <EOL> self . actions . Print ( <EOL> '<STR_LIT>' , color = vroom . color . YELLOW , file = file , end = '<STR_LIT>' ) <EOL> self . actions . Print ( '<STR_LIT>' , file = file ) <EOL> def Stats ( self ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> stats = self . actions . Results ( ) <EOL> stats [ '<STR_LIT>' ] = ( <EOL> stats [ STATUS . PASS ] + stats [ STATUS . ERROR ] + stats [ STATUS . FAIL ] ) <EOL> self . _stats = stats <EOL> return self . _stats <EOL> def Status ( self ) : <EOL> """<STR_LIT>""" <EOL> stats = self . Stats ( ) <EOL> if stats [ STATUS . FAIL ] : <EOL> return STATUS . FAIL <EOL> elif stats [ STATUS . ERROR ] : <EOL> return STATUS . ERROR <EOL> return STATUS . PASS <EOL> class Logger ( object ) : <EOL> """<STR_LIT>""" <EOL> HEADER = None <EOL> EMPTY = None <EOL> def __init__ ( self , file , verbose , color ) : <EOL> """<STR_LIT>""" <EOL> self . _verbose = verbose <EOL> self . _color = color <EOL> self . _file = file <EOL> self . _queue = [ ] <EOL> def Log ( self , message ) : <EOL> """<STR_LIT>""" <EOL> self . _queue . append ( message ) <EOL> def Logs ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _queue <EOL> def Print ( self , message , verbose = None , color = None , end = '<STR_LIT:\n>' , file = None ) : <EOL> """<STR_LIT>""" <EOL> handle = file or self . _file <EOL> if ( verbose is None ) or ( verbose == self . _verbose ) : <EOL> if handle == sys . stdout and color is not None : <EOL> if not isinstance ( color , tuple ) : <EOL> color = ( color , ) <EOL> message = self . _color ( message , * color ) <EOL> handle . write ( message + end ) <EOL> def Write ( self , filename , file = None ) : <EOL> """<STR_LIT>""" <EOL> if self . _file is None : <EOL> return False <EOL> file = file or self . _file <EOL> lines = list ( self . Finalize ( self . _queue ) ) <EOL> self . Print ( '<STR_LIT>' , file = file ) <EOL> if lines : <EOL> if self . HEADER : <EOL> header = self . HEADER % { '<STR_LIT:filename>' : filename } <EOL> self . Print ( header , end = '<STR_LIT>' , file = file ) <EOL> for line in lines : <EOL> self . Print ( line . rstrip ( '<STR_LIT:\n>' ) , file = file ) <EOL> elif self . EMPTY : <EOL> empty = self . EMPTY % { '<STR_LIT:filename>' : filename } <EOL> self . Print ( empty , end = '<STR_LIT>' , file = file ) <EOL> return True <EOL> def Finalize ( self , queue ) : <EOL> """<STR_LIT>""" <EOL> return PrefixWithIndex ( queue ) <EOL> class MessageLogger ( Logger ) : <EOL> """<STR_LIT>""" <EOL> HEADER = '<STR_LIT>' <EOL> EMPTY = '<STR_LIT>' <EOL> class CommandLogger ( Logger ) : <EOL> """<STR_LIT>""" <EOL> HEADER = '<STR_LIT>' <EOL> EMPTY = '<STR_LIT>' <EOL> class SyscallLogger ( Logger ) : <EOL> """<STR_LIT>""" <EOL> HEADER = '<STR_LIT>' <EOL> EMPTY = '<STR_LIT>' <EOL> def Finalize ( self , queue ) : <EOL> return map ( str , queue ) <EOL> class ActionLogger ( Logger ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . _opened = False <EOL> super ( ActionLogger , self ) . __init__ ( * args , ** kwargs ) <EOL> def Open ( self , lines ) : <EOL> """<STR_LIT>""" <EOL> self . _lines = lines <EOL> self . _nextline = <NUM_LIT:0> <EOL> self . _passed = <NUM_LIT:0> <EOL> self . _errored = <NUM_LIT:0> <EOL> self . _failed = <NUM_LIT:0> <EOL> self . _opened = True <EOL> def Write ( self , filename , file = None ) : <EOL> """<STR_LIT>""" <EOL> if not self . _opened : <EOL> raise NoTestRunning <EOL> self . ExecutedUpTo ( len ( self . _lines ) - <NUM_LIT:1> ) <EOL> for ( line , args , kwargs ) in self . _queue : <EOL> self . Print ( line , * args , file = file , ** kwargs ) <EOL> def PutStat ( self , stats , stat , fmt , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> assert stat in stats and stat in COLORS <EOL> num = stats [ stat ] <EOL> kwargs . setdefault ( '<STR_LIT:end>' , '<STR_LIT:U+002CU+0020>' ) <EOL> if num : <EOL> kwargs [ '<STR_LIT>' ] = COLORS [ stat ] <EOL> self . Print ( fmt % num , ** kwargs ) <EOL> def Queue ( self , message , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . _queue . append ( ( message , args , kwargs ) ) <EOL> def Log ( self , result , lineno , error = None ) : <EOL> """<STR_LIT>""" <EOL> self . Tally ( result ) <EOL> self . ExecutedUpTo ( lineno ) <EOL> if error is not None : <EOL> self . _Error ( result , error , lineno ) <EOL> def Tally ( self , result ) : <EOL> """<STR_LIT>""" <EOL> if result == vroom . test . RESULT . PASSED : <EOL> self . _passed += <NUM_LIT:1> <EOL> if result == vroom . test . RESULT . ERROR : <EOL> self . _errored += <NUM_LIT:1> <EOL> if result == vroom . test . RESULT . FAILED : <EOL> self . _failed += <NUM_LIT:1> <EOL> def ExecutedUpTo ( self , lineno ) : <EOL> """<STR_LIT>""" <EOL> if self . _verbose : <EOL> for i , line in enumerate ( self . _lines [ self . _nextline : lineno + <NUM_LIT:1> ] ) : <EOL> number = self . Lineno ( self . _nextline + i ) <EOL> self . Queue ( '<STR_LIT>' % ( number , line . rstrip ( '<STR_LIT:\n>' ) ) ) <EOL> self . _nextline = lineno + <NUM_LIT:1> <EOL> def Lineno ( self , lineno ) : <EOL> """<STR_LIT>""" <EOL> numberifier = '<STR_LIT>' % len ( str ( len ( self . _lines ) ) ) <EOL> return numberifier % ( lineno + <NUM_LIT:1> ) <EOL> def Error ( self , result , error ) : <EOL> """<STR_LIT>""" <EOL> self . Tally ( result ) <EOL> self . _Error ( result , error ) <EOL> def _Error ( self , result , error , lineno = None ) : <EOL> """<STR_LIT>""" <EOL> self . Queue ( '<STR_LIT>' , verbose = True ) <EOL> if result == vroom . test . RESULT . ERROR : <EOL> self . Queue ( result . upper ( ) , color = COLORS [ STATUS . ERROR ] , end = '<STR_LIT>' ) <EOL> else : <EOL> self . Queue ( result . upper ( ) , color = COLORS [ STATUS . FAIL ] , end = '<STR_LIT>' ) <EOL> if lineno is not None : <EOL> self . Queue ( '<STR_LIT>' % self . Lineno ( lineno ) , verbose = False , end = '<STR_LIT>' ) <EOL> self . Queue ( '<STR_LIT>' , end = '<STR_LIT>' ) <EOL> self . Queue ( str ( error ) ) <EOL> contexted = [ False ] <EOL> def QueueContext ( attr , writer , * args ) : <EOL> value = None <EOL> if hasattr ( error , attr ) : <EOL> value = getattr ( error , attr ) <EOL> elif hasattr ( error , '<STR_LIT>' ) : <EOL> for f in error . GetFlattenedFailures ( ) : <EOL> if hasattr ( f , attr ) : <EOL> value = getattr ( f , attr ) <EOL> break <EOL> if value is None : <EOL> return <EOL> contexted [ <NUM_LIT:0> ] = True <EOL> self . Queue ( '<STR_LIT>' ) <EOL> writer ( value , self . Queue , * args ) <EOL> QueueContext ( '<STR_LIT>' , ErrorMessageContext ) <EOL> QueueContext ( '<STR_LIT>' , ErrorBufferContext ) <EOL> if lineno is not None : <EOL> stripped = self . _lines [ lineno ] [ <NUM_LIT:2> : ] <EOL> line = '<STR_LIT>' % ( <EOL> self . Lineno ( lineno ) , stripped ) <EOL> self . Queue ( line , end = '<STR_LIT>' , verbose = False ) <EOL> QueueContext ( '<STR_LIT>' , ErrorShellQueue ) <EOL> QueueContext ( '<STR_LIT>' , ErrorSystemCalls ) <EOL> QueueContext ( '<STR_LIT>' , ErrorCommandContext ) <EOL> if contexted [ <NUM_LIT:0> ] : <EOL> self . Queue ( '<STR_LIT>' , verbose = False ) <EOL> self . Queue ( '<STR_LIT>' , verbose = True ) <EOL> def Results ( self ) : <EOL> """<STR_LIT>""" <EOL> return { <EOL> STATUS . PASS : self . _passed , <EOL> STATUS . ERROR : self . _errored , <EOL> STATUS . FAIL : self . _failed , <EOL> } <EOL> def Exception ( self , exctype , exception , tb ) : <EOL> """<STR_LIT>""" <EOL> self . Tally ( vroom . test . RESULT . ERROR ) <EOL> self . Queue ( '<STR_LIT>' , verbose = True ) <EOL> self . Queue ( '<STR_LIT>' ) <EOL> self . Queue ( '<STR_LIT>' , color = COLORS [ STATUS . ERROR ] , end = '<STR_LIT>' ) <EOL> self . Queue ( '<STR_LIT>' , end = '<STR_LIT>' ) <EOL> self . Queue ( '<STR_LIT>' . join ( traceback . format_exception ( exctype , exception , tb ) ) ) <EOL> self . Queue ( '<STR_LIT>' ) <EOL> if hasattr ( exception , '<STR_LIT>' ) : <EOL> ErrorShellErrors ( exception . shell_errors , self . Queue ) <EOL> self . Queue ( '<STR_LIT>' ) <EOL> self . Queue ( '<STR_LIT>' , verbose = True ) <EOL> def WriteBackmatter ( writers , args ) : <EOL> """<STR_LIT>""" <EOL> if len ( writers ) == <NUM_LIT:1> : <EOL> return <EOL> count = <NUM_LIT:0> <EOL> total = <NUM_LIT:0> <EOL> passed = <NUM_LIT:0> <EOL> errored = <NUM_LIT:0> <EOL> args . out . write ( args . color ( '<STR_LIT>' , vroom . color . VIOLET ) ) <EOL> for writer in writers : <EOL> count += <NUM_LIT:1> <EOL> total += writer . Stats ( ) [ '<STR_LIT>' ] <EOL> status = writer . Status ( ) <EOL> if status == STATUS . PASS : <EOL> passed += <NUM_LIT:1> <EOL> elif status == STATUS . ERROR : <EOL> errored += <NUM_LIT:1> <EOL> args . out . write ( args . color ( '<STR_LIT:o>' , COLORS [ status ] ) ) <EOL> args . out . write ( args . color ( '<STR_LIT>' , vroom . color . VIOLET ) ) <EOL> plural = '<STR_LIT>' if total == <NUM_LIT:1> else '<STR_LIT:s>' <EOL> args . out . write ( '<STR_LIT>' % ( total , plural , count ) ) <EOL> if passed == count : <EOL> args . out . write ( '<STR_LIT>' ) <EOL> args . out . write ( args . color ( '<STR_LIT:OK>' , COLORS [ STATUS . PASS ] ) ) <EOL> args . out . write ( '<STR_LIT:.>' ) <EOL> else : <EOL> args . out . write ( args . color ( '<STR_LIT>' % passed , COLORS [ STATUS . PASS ] ) ) <EOL> args . out . write ( '<STR_LIT:U+002CU+0020>' ) <EOL> args . out . write ( args . color ( '<STR_LIT>' % errored , COLORS [ STATUS . ERROR ] ) ) <EOL> args . out . write ( '<STR_LIT:U+002CU+0020>' ) <EOL> failed = count - passed - errored <EOL> args . out . write ( args . color ( '<STR_LIT>' % failed , COLORS [ STATUS . FAIL ] ) ) <EOL> args . out . write ( '<STR_LIT:\n>' ) <EOL> def PrefixWithIndex ( logs ) : <EOL> """<STR_LIT>""" <EOL> logs = list ( logs ) <EOL> while logs and logs [ - <NUM_LIT:1> ] is None : <EOL> logs . pop ( ) <EOL> numberifier = '<STR_LIT>' % len ( str ( len ( list ( filter ( bool , logs ) ) ) ) ) <EOL> adjustment = <NUM_LIT:0> <EOL> for ( i , log ) in enumerate ( logs ) : <EOL> if log is None : <EOL> adjustment += <NUM_LIT:1> <EOL> yield '<STR_LIT>' <EOL> else : <EOL> index = numberifier % ( i + <NUM_LIT:1> - adjustment ) <EOL> yield '<STR_LIT>' % ( index , log ) <EOL> def ErrorContextPrinter ( header , empty , modifier = None , singleton = None ) : <EOL> """<STR_LIT>""" <EOL> def WriteExtraData ( data , printer ) : <EOL> data = list ( modifier ( data ) if modifier else data ) <EOL> if data : <EOL> if not singleton or len ( data ) > <NUM_LIT:1> : <EOL> printer ( header , end = '<STR_LIT>' ) <EOL> for datum in data : <EOL> if datum is None : <EOL> printer ( '<STR_LIT>' ) <EOL> else : <EOL> printer ( str ( datum ) ) <EOL> else : <EOL> printer ( singleton % data [ <NUM_LIT:0> ] ) <EOL> else : <EOL> printer ( empty ) <EOL> return WriteExtraData <EOL> ErrorMessageContext = ErrorContextPrinter ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> modifier = None , <EOL> singleton = '<STR_LIT>' ) <EOL> ErrorCommandContext = ErrorContextPrinter ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> ErrorSystemCalls = ErrorContextPrinter ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> ErrorShellQueue = ErrorContextPrinter ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> ErrorShellErrors = ErrorContextPrinter ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> modifier = PrefixWithIndex ) <EOL> def ErrorBufferContext ( context , printer ) : <EOL> """<STR_LIT>""" <EOL> if context is None : <EOL> printer ( '<STR_LIT>' ) <EOL> return <EOL> if context [ '<STR_LIT>' ] is None : <EOL> printer ( '<STR_LIT>' , end = '<STR_LIT>' , verbose = True ) <EOL> else : <EOL> printer ( '<STR_LIT>' % context [ '<STR_LIT>' ] , end = '<STR_LIT>' , verbose = True ) <EOL> printer ( '<STR_LIT>' , verbose = True ) <EOL> printer ( '<STR_LIT>' , verbose = False ) <EOL> ( start , end ) = ( context [ '<STR_LIT:start>' ] , context [ '<STR_LIT:end>' ] ) <EOL> if not context [ '<STR_LIT:data>' ] : <EOL> printer ( '<STR_LIT>' ) <EOL> return <EOL> buflines = list ( PrefixWithIndex ( context [ '<STR_LIT:data>' ] ) ) <EOL> if end > start : <EOL> for i , bufline in enumerate ( buflines [ start : end ] ) : <EOL> if context [ '<STR_LIT>' ] == i + start : <EOL> printer ( bufline + '<STR_LIT>' , color = vroom . color . BOLD ) <EOL> else : <EOL> printer ( bufline ) <EOL> else : <EOL> for bufline in buflines : <EOL> printer ( bufline ) <EOL> class NoTestRunning ( ValueError ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( NoTestRunning , self ) . __init__ ( <EOL> '<STR_LIT>' ) </s>
