<s> """<STR_LIT>""" <EOL> import sys <EOL> import time <EOL> import unittest <EOL> from python_toolbox . third_party . six import u <EOL> from python_toolbox . third_party . unittest2 import result <EOL> try : <EOL> from python_toolbox . third_party . unittest2 . signals import registerResult <EOL> except ImportError : <EOL> def registerResult ( _ ) : <EOL> pass <EOL> __unittest = True <EOL> class _WritelnDecorator ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , stream ) : <EOL> self . stream = stream <EOL> def __getattr__ ( self , attr ) : <EOL> if attr in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> raise AttributeError ( attr ) <EOL> return getattr ( self . stream , attr ) <EOL> def writeln ( self , arg = None ) : <EOL> if arg : <EOL> self . write ( arg ) <EOL> self . write ( u ( '<STR_LIT:\n>' ) ) <EOL> class TextTestResult ( result . TestResult ) : <EOL> """<STR_LIT>""" <EOL> separator1 = u ( '<STR_LIT:=>' * <NUM_LIT> ) <EOL> separator2 = u ( '<STR_LIT:->' * <NUM_LIT> ) <EOL> def __init__ ( self , stream , descriptions , verbosity ) : <EOL> super ( TextTestResult , self ) . __init__ ( stream , descriptions , verbosity ) <EOL> self . stream = stream <EOL> self . showAll = verbosity > <NUM_LIT:1> <EOL> self . dots = verbosity == <NUM_LIT:1> <EOL> self . descriptions = descriptions <EOL> def getDescription ( self , test ) : <EOL> doc_first_line = test . shortDescription ( ) <EOL> if self . descriptions and doc_first_line : <EOL> return '<STR_LIT:\n>' . join ( ( str ( test ) , doc_first_line ) ) <EOL> else : <EOL> return str ( test ) <EOL> def startTest ( self , test ) : <EOL> super ( TextTestResult , self ) . startTest ( test ) <EOL> if self . showAll : <EOL> self . stream . write ( self . getDescription ( test ) ) <EOL> self . stream . write ( "<STR_LIT>" ) <EOL> self . stream . flush ( ) <EOL> def addSuccess ( self , test ) : <EOL> super ( TextTestResult , self ) . addSuccess ( test ) <EOL> if self . showAll : <EOL> self . stream . writeln ( "<STR_LIT>" ) <EOL> elif self . dots : <EOL> self . stream . write ( '<STR_LIT:.>' ) <EOL> self . stream . flush ( ) <EOL> def addError ( self , test , err ) : <EOL> super ( TextTestResult , self ) . addError ( test , err ) <EOL> if self . showAll : <EOL> self . stream . writeln ( "<STR_LIT>" ) <EOL> elif self . dots : <EOL> self . stream . write ( '<STR_LIT:E>' ) <EOL> self . stream . flush ( ) <EOL> def addFailure ( self , test , err ) : <EOL> super ( TextTestResult , self ) . addFailure ( test , err ) <EOL> if self . showAll : <EOL> self . stream . writeln ( "<STR_LIT>" ) <EOL> elif self . dots : <EOL> self . stream . write ( '<STR_LIT:F>' ) <EOL> self . stream . flush ( ) <EOL> def addSkip ( self , test , reason ) : <EOL> super ( TextTestResult , self ) . addSkip ( test , reason ) <EOL> if self . showAll : <EOL> self . stream . writeln ( "<STR_LIT>" % ( reason , ) ) <EOL> elif self . dots : <EOL> self . stream . write ( "<STR_LIT:s>" ) <EOL> self . stream . flush ( ) <EOL> def addExpectedFailure ( self , test , err ) : <EOL> super ( TextTestResult , self ) . addExpectedFailure ( test , err ) <EOL> if self . showAll : <EOL> self . stream . writeln ( "<STR_LIT>" ) <EOL> elif self . dots : <EOL> self . stream . write ( "<STR_LIT:x>" ) <EOL> self . stream . flush ( ) <EOL> def addUnexpectedSuccess ( self , test ) : <EOL> super ( TextTestResult , self ) . addUnexpectedSuccess ( test ) <EOL> if self . showAll : <EOL> self . stream . writeln ( "<STR_LIT>" ) <EOL> elif self . dots : <EOL> self . stream . write ( "<STR_LIT:u>" ) <EOL> self . stream . flush ( ) <EOL> def printErrors ( self ) : <EOL> if self . dots or self . showAll : <EOL> self . stream . writeln ( ) <EOL> self . printErrorList ( '<STR_LIT>' , self . errors ) <EOL> self . printErrorList ( '<STR_LIT>' , self . failures ) <EOL> def printErrorList ( self , flavour , errors ) : <EOL> for test , err in errors : <EOL> self . stream . writeln ( self . separator1 ) <EOL> self . stream . writeln ( "<STR_LIT>" % ( flavour , self . getDescription ( test ) ) ) <EOL> self . stream . writeln ( self . separator2 ) <EOL> self . stream . writeln ( "<STR_LIT:%s>" % err ) <EOL> def stopTestRun ( self ) : <EOL> super ( TextTestResult , self ) . stopTestRun ( ) <EOL> self . printErrors ( ) <EOL> class TextTestRunner ( unittest . TextTestRunner ) : <EOL> """<STR_LIT>""" <EOL> resultclass = TextTestResult <EOL> def __init__ ( self , stream = sys . stderr , descriptions = True , verbosity = <NUM_LIT:1> , <EOL> failfast = False , buffer = False , resultclass = None , <EOL> tb_locals = False ) : <EOL> """<STR_LIT>""" <EOL> self . stream = _WritelnDecorator ( stream ) <EOL> self . descriptions = descriptions <EOL> self . verbosity = verbosity <EOL> self . failfast = failfast <EOL> self . buffer = buffer <EOL> self . tb_locals = tb_locals <EOL> if resultclass is not None : <EOL> self . resultclass = resultclass <EOL> def _makeResult ( self ) : <EOL> return self . resultclass ( self . stream , self . descriptions , self . verbosity ) <EOL> def run ( self , test ) : <EOL> "<STR_LIT>" <EOL> result = self . _makeResult ( ) <EOL> result . failfast = self . failfast <EOL> result . buffer = self . buffer <EOL> result . tb_locals = self . tb_locals <EOL> registerResult ( result ) <EOL> startTime = time . time ( ) <EOL> startTestRun = getattr ( result , '<STR_LIT>' , None ) <EOL> if startTestRun is not None : <EOL> startTestRun ( ) <EOL> try : <EOL> test ( result ) <EOL> finally : <EOL> stopTestRun = getattr ( result , '<STR_LIT>' , None ) <EOL> if stopTestRun is not None : <EOL> stopTestRun ( ) <EOL> else : <EOL> result . printErrors ( ) <EOL> stopTime = time . time ( ) <EOL> timeTaken = stopTime - startTime <EOL> if hasattr ( result , '<STR_LIT>' ) : <EOL> self . stream . writeln ( result . separator2 ) <EOL> run = result . testsRun <EOL> self . stream . writeln ( u ( "<STR_LIT>" ) % <EOL> ( run , run != <NUM_LIT:1> and "<STR_LIT:s>" or "<STR_LIT>" , timeTaken ) ) <EOL> self . stream . writeln ( ) <EOL> expectedFails = unexpectedSuccesses = skipped = <NUM_LIT:0> <EOL> try : <EOL> results = map ( len , ( result . expectedFailures , <EOL> result . unexpectedSuccesses , <EOL> result . skipped ) ) <EOL> except AttributeError : <EOL> pass <EOL> else : <EOL> expectedFails , unexpectedSuccesses , skipped = results <EOL> infos = [ ] <EOL> if not result . wasSuccessful ( ) : <EOL> self . stream . write ( u ( "<STR_LIT>" ) ) <EOL> failed , errored = map ( len , ( result . failures , result . errors ) ) <EOL> if failed : <EOL> infos . append ( u ( "<STR_LIT>" ) % failed ) <EOL> if errored : <EOL> infos . append ( u ( "<STR_LIT>" ) % errored ) <EOL> else : <EOL> self . stream . write ( u ( "<STR_LIT:OK>" ) ) <EOL> if skipped : <EOL> infos . append ( u ( "<STR_LIT>" ) % skipped ) <EOL> if expectedFails : <EOL> infos . append ( u ( "<STR_LIT>" ) % expectedFails ) <EOL> if unexpectedSuccesses : <EOL> infos . append ( u ( "<STR_LIT>" ) % unexpectedSuccesses ) <EOL> if infos : <EOL> self . stream . writeln ( u ( "<STR_LIT>" ) % ( u ( "<STR_LIT:U+002CU+0020>" ) . join ( infos ) , ) ) <EOL> else : <EOL> self . stream . write ( u ( "<STR_LIT:\n>" ) ) <EOL> return result </s>
