<s> '''<STR_LIT>''' <EOL> __author__ = "<STR_LIT>" <EOL> __email__ = "<STR_LIT>" <EOL> __version__ = "<STR_LIT>" [ <NUM_LIT:11> : - <NUM_LIT:2> ] <EOL> import time <EOL> import sys <EOL> import traceback <EOL> import string <EOL> import os <EOL> import types <EOL> class TestResult : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . failures = [ ] <EOL> self . errors = [ ] <EOL> self . testsRun = <NUM_LIT:0> <EOL> self . shouldStop = <NUM_LIT:0> <EOL> self . params = "<STR_LIT>" <EOL> def startTest ( self , test ) : <EOL> "<STR_LIT>" <EOL> self . testsRun = self . testsRun + <NUM_LIT:1> <EOL> def stopTest ( self , test ) : <EOL> "<STR_LIT>" <EOL> pass <EOL> def addError ( self , test , err ) : <EOL> "<STR_LIT>" <EOL> self . errors . append ( ( test , err ) ) <EOL> def addFailure ( self , test , err ) : <EOL> "<STR_LIT>" <EOL> self . failures . append ( ( test , err ) ) <EOL> def addSuccess ( self , test ) : <EOL> "<STR_LIT>" <EOL> pass <EOL> def wasSuccessful ( self ) : <EOL> "<STR_LIT>" <EOL> return len ( self . failures ) == len ( self . errors ) == <NUM_LIT:0> <EOL> def stop ( self ) : <EOL> "<STR_LIT>" <EOL> self . shouldStop = <NUM_LIT:1> <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . __class__ , self . testsRun , len ( self . errors ) , <EOL> len ( self . failures ) ) <EOL> class TestCase : <EOL> """<STR_LIT>""" <EOL> failureException = AssertionError <EOL> def __init__ ( self , methodName = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> self . result = TestResult ( ) <EOL> try : <EOL> self . __testMethodName = methodName <EOL> testMethod = getattr ( self , methodName ) <EOL> self . __testMethodDoc = testMethod . __doc__ <EOL> except AttributeError : <EOL> raise ValueError , "<STR_LIT>" % ( self . __class__ , methodName ) <EOL> def setUp ( self ) : <EOL> "<STR_LIT>" <EOL> pass <EOL> def tearDown ( self ) : <EOL> "<STR_LIT>" <EOL> pass <EOL> def countTestCases ( self ) : <EOL> return <NUM_LIT:1> <EOL> def shortDescription ( self ) : <EOL> """<STR_LIT>""" <EOL> doc = self . __testMethodDoc <EOL> return doc and string . strip ( string . split ( doc , "<STR_LIT:\n>" ) [ <NUM_LIT:0> ] ) or None <EOL> def id ( self ) : <EOL> return "<STR_LIT>" % ( self . __class__ , self . __testMethodName ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . __testMethodName , self . __class__ ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . __class__ , self . __testMethodName ) <EOL> def run ( self , result = None ) : <EOL> if result is not None : self . result = result <EOL> return self ( result ) <EOL> def __call__ ( self , result = None ) : <EOL> if result is not None : self . result = result <EOL> result . startTest ( self ) <EOL> testMethod = getattr ( self , self . __testMethodName ) <EOL> try : <EOL> try : <EOL> self . setUp ( ) <EOL> except : <EOL> result . addError ( self , self . __exc_info ( ) ) <EOL> return <EOL> ok = <NUM_LIT:0> <EOL> try : <EOL> testMethod ( ) <EOL> ok = <NUM_LIT:1> <EOL> except self . failureException , e : <EOL> result . addFailure ( self , self . __exc_info ( ) ) <EOL> except : <EOL> result . addError ( self , self . __exc_info ( ) ) <EOL> try : <EOL> self . tearDown ( ) <EOL> except : <EOL> result . addError ( self , self . __exc_info ( ) ) <EOL> ok = <NUM_LIT:0> <EOL> if ok : result . addSuccess ( self ) <EOL> finally : <EOL> result . stopTest ( self ) <EOL> def debug ( self ) : <EOL> """<STR_LIT>""" <EOL> self . setUp ( ) <EOL> getattr ( self , self . __testMethodName ) ( ) <EOL> self . tearDown ( ) <EOL> def __exc_info ( self ) : <EOL> """<STR_LIT>""" <EOL> exctype , excvalue , tb = sys . exc_info ( ) <EOL> if sys . platform [ : <NUM_LIT:4> ] == '<STR_LIT>' : <EOL> return ( exctype , excvalue , tb ) <EOL> newtb = tb . tb_next <EOL> if newtb is None : <EOL> return ( exctype , excvalue , tb ) <EOL> return ( exctype , excvalue , newtb ) <EOL> def fail ( self , msg = None ) : <EOL> """<STR_LIT>""" <EOL> raise self . failureException , msg <EOL> def failIf ( self , expr , msg = None ) : <EOL> "<STR_LIT>" <EOL> if expr : raise self . failureException , msg <EOL> def failUnless ( self , expr , msg = None ) : <EOL> """<STR_LIT>""" <EOL> if not expr : raise self . failureException , msg <EOL> def failUnlessRaises ( self , excClass , callableObj , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> apply ( callableObj , args , kwargs ) <EOL> except excClass : <EOL> return <EOL> else : <EOL> if hasattr ( excClass , '<STR_LIT>' ) : excName = excClass . __name__ <EOL> else : excName = str ( excClass ) <EOL> raise self . failureException , excName <EOL> def failUnlessEqual ( self , first , second , msg = None ) : <EOL> """<STR_LIT>""" <EOL> if first != second : <EOL> raise self . failureException , ( msg or '<STR_LIT>' % ( first , second ) ) <EOL> def failIfEqual ( self , first , second , msg = None ) : <EOL> """<STR_LIT>""" <EOL> if first == second : <EOL> raise self . failureException , ( msg or '<STR_LIT>' % ( first , second ) ) <EOL> assertEqual = assertEquals = failUnlessEqual <EOL> assertNotEqual = assertNotEquals = failIfEqual <EOL> assertRaises = failUnlessRaises <EOL> assert_ = failUnless <EOL> def writeParameter ( self , paramName , paramValue ) : <EOL> testcase = self . __class__ <EOL> testmethod = self . id ( ) . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] <EOL> self . result . params += "<STR_LIT>" % ( paramName , paramValue , testcase , testmethod ) <EOL> class TestSuite : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , tests = ( ) ) : <EOL> self . _tests = [ ] <EOL> self . addTests ( tests ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . __class__ , self . _tests ) <EOL> __str__ = __repr__ <EOL> def countTestCases ( self ) : <EOL> cases = <NUM_LIT:0> <EOL> for test in self . _tests : <EOL> cases = cases + test . countTestCases ( ) <EOL> return cases <EOL> def addTest ( self , test ) : <EOL> self . _tests . append ( test ) <EOL> def addTests ( self , tests ) : <EOL> for test in tests : <EOL> self . addTest ( test ) <EOL> def run ( self , result ) : <EOL> return self ( result ) <EOL> def __call__ ( self , result ) : <EOL> for test in self . _tests : <EOL> if result . shouldStop : <EOL> break <EOL> test ( result ) <EOL> return result <EOL> def debug ( self ) : <EOL> """<STR_LIT>""" <EOL> for test in self . _tests : test . debug ( ) <EOL> class FunctionTestCase ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , testFunc , setUp = None , tearDown = None , <EOL> description = None ) : <EOL> TestCase . __init__ ( self ) <EOL> self . __setUpFunc = setUp <EOL> self . __tearDownFunc = tearDown <EOL> self . __testFunc = testFunc <EOL> self . __description = description <EOL> def setUp ( self ) : <EOL> if self . __setUpFunc is not None : <EOL> self . __setUpFunc ( ) <EOL> def tearDown ( self ) : <EOL> if self . __tearDownFunc is not None : <EOL> self . __tearDownFunc ( ) <EOL> def runTest ( self ) : <EOL> self . __testFunc ( ) <EOL> def id ( self ) : <EOL> return self . __testFunc . __name__ <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . __class__ , self . __testFunc . __name__ ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . __class__ , self . __testFunc ) <EOL> def shortDescription ( self ) : <EOL> if self . __description is not None : return self . __description <EOL> doc = self . __testFunc . __doc__ <EOL> return doc and string . strip ( string . split ( doc , "<STR_LIT:\n>" ) [ <NUM_LIT:0> ] ) or None <EOL> class TestLoader : <EOL> """<STR_LIT>""" <EOL> testMethodPrefix = '<STR_LIT:test>' <EOL> sortTestMethodsUsing = cmp <EOL> suiteClass = TestSuite <EOL> def loadTestsFromTestCase ( self , testCaseClass ) : <EOL> """<STR_LIT>""" <EOL> return self . suiteClass ( map ( testCaseClass , <EOL> self . getTestCaseNames ( testCaseClass ) ) ) <EOL> def loadTestsFromModule ( self , module ) : <EOL> """<STR_LIT>""" <EOL> tests = [ ] <EOL> for name in dir ( module ) : <EOL> obj = getattr ( module , name ) <EOL> if type ( obj ) == types . ClassType and issubclass ( obj , TestCase ) : <EOL> tests . append ( self . loadTestsFromTestCase ( obj ) ) <EOL> return self . suiteClass ( tests ) <EOL> def loadTestsFromName ( self , name , module = None ) : <EOL> """<STR_LIT>""" <EOL> parts = string . split ( name , '<STR_LIT:.>' ) <EOL> if module is None : <EOL> if not parts : <EOL> raise ValueError , "<STR_LIT>" % name <EOL> else : <EOL> parts_copy = parts [ : ] <EOL> while parts_copy : <EOL> try : <EOL> module = __import__ ( string . join ( parts_copy , '<STR_LIT:.>' ) ) <EOL> break <EOL> except ImportError : <EOL> del parts_copy [ - <NUM_LIT:1> ] <EOL> if not parts_copy : raise <EOL> parts = parts [ <NUM_LIT:1> : ] <EOL> obj = module <EOL> for part in parts : <EOL> obj = getattr ( obj , part ) <EOL> import unittest <EOL> if type ( obj ) == types . ModuleType : <EOL> return self . loadTestsFromModule ( obj ) <EOL> elif type ( obj ) == types . ClassType and issubclass ( obj , unittest . TestCase ) : <EOL> return self . loadTestsFromTestCase ( obj ) <EOL> elif type ( obj ) == types . UnboundMethodType : <EOL> return obj . im_class ( obj . __name__ ) <EOL> elif callable ( obj ) : <EOL> test = obj ( ) <EOL> if not isinstance ( test , unittest . TestCase ) and not isinstance ( test , unittest . TestSuite ) : <EOL> raise ValueError , "<STR_LIT>" % ( obj , test ) <EOL> return test <EOL> else : <EOL> raise ValueError , "<STR_LIT>" % obj <EOL> def loadTestsFromNames ( self , names , module = None ) : <EOL> """<STR_LIT>""" <EOL> suites = [ ] <EOL> for name in names : <EOL> suites . append ( self . loadTestsFromName ( name , module ) ) <EOL> return self . suiteClass ( suites ) <EOL> def getTestCaseNames ( self , testCaseClass ) : <EOL> """<STR_LIT>""" <EOL> testFnNames = filter ( lambda n , p = self . testMethodPrefix : n [ : len ( p ) ] == p , <EOL> dir ( testCaseClass ) ) <EOL> for baseclass in testCaseClass . __bases__ : <EOL> for testFnName in self . getTestCaseNames ( baseclass ) : <EOL> if testFnName not in testFnNames : <EOL> testFnNames . append ( testFnName ) <EOL> if self . sortTestMethodsUsing : <EOL> testFnNames . sort ( self . sortTestMethodsUsing ) <EOL> return testFnNames <EOL> defaultTestLoader = TestLoader ( ) <EOL> def _makeLoader ( prefix , sortUsing , suiteClass = None ) : <EOL> loader = TestLoader ( ) <EOL> loader . sortTestMethodsUsing = sortUsing <EOL> loader . testMethodPrefix = prefix <EOL> if suiteClass : loader . suiteClass = suiteClass <EOL> return loader <EOL> def getTestCaseNames ( testCaseClass , prefix , sortUsing = cmp ) : <EOL> return _makeLoader ( prefix , sortUsing ) . getTestCaseNames ( testCaseClass ) <EOL> def makeSuite ( testCaseClass , prefix = '<STR_LIT:test>' , sortUsing = cmp , suiteClass = TestSuite ) : <EOL> return _makeLoader ( prefix , sortUsing , suiteClass ) . loadTestsFromTestCase ( testCaseClass ) <EOL> def findTestCases ( module , prefix = '<STR_LIT:test>' , sortUsing = cmp , suiteClass = TestSuite ) : <EOL> return _makeLoader ( prefix , sortUsing , suiteClass ) . loadTestsFromModule ( module ) <EOL> class _WritelnDecorator : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , stream ) : <EOL> self . stream = stream <EOL> def __getattr__ ( self , attr ) : <EOL> return getattr ( self . stream , attr ) <EOL> def writeln ( self , * args ) : <EOL> if args : apply ( self . write , args ) <EOL> self . write ( '<STR_LIT:\n>' ) <EOL> class _XmlTextTestResult ( TestResult ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , stream , descriptions , verbosity ) : <EOL> TestResult . __init__ ( self ) <EOL> self . stream = _WritelnDecorator ( stream ) <EOL> self . showAll = verbosity > <NUM_LIT:1> <EOL> self . descriptions = descriptions <EOL> self . _lastWas = '<STR_LIT:success>' <EOL> self . _errorsAndFailures = "<STR_LIT>" <EOL> self . _startTime = <NUM_LIT:0.0> <EOL> def getDescription ( self , test ) : <EOL> if self . descriptions : <EOL> return test . shortDescription ( ) or str ( test ) <EOL> else : <EOL> return str ( test ) <EOL> def startTest ( self , test ) : <EOL> self . _startTime = time . time ( ) <EOL> TestResult . startTest ( self , test ) <EOL> self . stream . write ( '<STR_LIT>' % test . __class__ + '<STR_LIT>' % test . id ( ) . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] + '<STR_LIT:">' ) <EOL> def stopTest ( self , test ) : <EOL> stopTime = time . time ( ) <EOL> deltaTime = stopTime - self . _startTime <EOL> TestResult . stopTest ( self , test ) <EOL> self . stream . write ( '<STR_LIT>' % deltaTime ) <EOL> if self . _lastWas == '<STR_LIT:success>' : <EOL> self . stream . write ( '<STR_LIT>' ) <EOL> else : <EOL> self . stream . write ( '<STR_LIT:>>' ) <EOL> if self . _lastWas == '<STR_LIT:error>' : <EOL> self . stream . write ( self . _errorsAndFailures ) <EOL> elif self . _lastWas == '<STR_LIT>' : <EOL> self . stream . write ( self . _errorsAndFailures ) <EOL> else : <EOL> assert ( false ) <EOL> self . stream . write ( '<STR_LIT>' ) <EOL> self . _errorsAndFailures = "<STR_LIT>" <EOL> def addSuccess ( self , test ) : <EOL> TestResult . addSuccess ( self , test ) <EOL> self . _lastWas = '<STR_LIT:success>' <EOL> def addError ( self , test , err ) : <EOL> TestResult . addError ( self , test , err ) <EOL> if err [ <NUM_LIT:0> ] is KeyboardInterrupt : <EOL> self . shouldStop = <NUM_LIT:1> <EOL> self . _lastWas = '<STR_LIT:error>' <EOL> self . _errorsAndFailures += '<STR_LIT>' % err [ <NUM_LIT:0> ] <EOL> for line in apply ( traceback . format_exception , err ) : <EOL> for l in string . split ( line , "<STR_LIT:\n>" ) [ : - <NUM_LIT:1> ] : <EOL> self . _errorsAndFailures += "<STR_LIT:%s>" % l <EOL> self . _errorsAndFailures += "<STR_LIT>" <EOL> def addFailure ( self , test , err ) : <EOL> TestResult . addFailure ( self , test , err ) <EOL> if err [ <NUM_LIT:0> ] is KeyboardInterrupt : <EOL> self . shouldStop = <NUM_LIT:1> <EOL> self . _lastWas = '<STR_LIT>' <EOL> self . _errorsAndFailures += '<STR_LIT>' % err [ <NUM_LIT:0> ] <EOL> for line in apply ( traceback . format_exception , err ) : <EOL> for l in string . split ( line , "<STR_LIT:\n>" ) [ : - <NUM_LIT:1> ] : <EOL> self . _errorsAndFailures += "<STR_LIT:%s>" % l <EOL> self . _errorsAndFailures += "<STR_LIT>" <EOL> def printErrors ( self ) : <EOL> assert false <EOL> def printErrorList ( self , flavour , errors ) : <EOL> assert false <EOL> class _TextTestResult ( TestResult ) : <EOL> """<STR_LIT>""" <EOL> separator1 = '<STR_LIT:=>' * <NUM_LIT> <EOL> separator2 = '<STR_LIT:->' * <NUM_LIT> <EOL> def __init__ ( self , stream , descriptions , verbosity ) : <EOL> TestResult . __init__ ( self ) <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> if self . descriptions : <EOL> return test . shortDescription ( ) or str ( test ) <EOL> else : <EOL> return str ( test ) <EOL> def startTest ( self , test ) : <EOL> TestResult . startTest ( self , test ) <EOL> if self . showAll : <EOL> self . stream . write ( self . getDescription ( test ) ) <EOL> self . stream . write ( "<STR_LIT>" ) <EOL> def addSuccess ( self , test ) : <EOL> TestResult . addSuccess ( self , test ) <EOL> if self . showAll : <EOL> self . stream . writeln ( "<STR_LIT>" ) <EOL> elif self . dots : <EOL> self . stream . write ( '<STR_LIT:.>' ) <EOL> def addError ( self , test , err ) : <EOL> TestResult . addError ( self , test , err ) <EOL> if self . showAll : <EOL> self . stream . writeln ( "<STR_LIT>" ) <EOL> elif self . dots : <EOL> self . stream . write ( '<STR_LIT:E>' ) <EOL> if err [ <NUM_LIT:0> ] is KeyboardInterrupt : <EOL> self . shouldStop = <NUM_LIT:1> <EOL> def addFailure ( self , test , err ) : <EOL> TestResult . addFailure ( self , test , err ) <EOL> if self . showAll : <EOL> self . stream . writeln ( "<STR_LIT>" ) <EOL> elif self . dots : <EOL> self . stream . write ( '<STR_LIT:F>' ) <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> for line in apply ( traceback . format_exception , err ) : <EOL> for l in string . split ( line , "<STR_LIT:\n>" ) [ : - <NUM_LIT:1> ] : <EOL> self . stream . writeln ( "<STR_LIT:%s>" % l ) <EOL> class TextTestRunner : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , stream = sys . stderr , descriptions = <NUM_LIT:1> , verbosity = <NUM_LIT:1> ) : <EOL> self . stream = _WritelnDecorator ( stream ) <EOL> self . descriptions = descriptions <EOL> self . verbosity = verbosity <EOL> def _makeResult ( self ) : <EOL> return _TextTestResult ( self . stream , self . descriptions , self . verbosity ) <EOL> def run ( self , test ) : <EOL> "<STR_LIT>" <EOL> result = self . _makeResult ( ) <EOL> startTime = time . time ( ) <EOL> test ( result ) <EOL> stopTime = time . time ( ) <EOL> timeTaken = float ( stopTime - startTime ) <EOL> result . printErrors ( ) <EOL> self . stream . writeln ( result . separator2 ) <EOL> run = result . testsRun <EOL> self . stream . writeln ( "<STR_LIT>" % <EOL> ( run , run == <NUM_LIT:1> and "<STR_LIT>" or "<STR_LIT:s>" , timeTaken ) ) <EOL> self . stream . writeln ( ) <EOL> if not result . wasSuccessful ( ) : <EOL> self . stream . write ( "<STR_LIT>" ) <EOL> failed , errored = map ( len , ( result . failures , result . errors ) ) <EOL> if failed : <EOL> self . stream . write ( "<STR_LIT>" % failed ) <EOL> if errored : <EOL> if failed : self . stream . write ( "<STR_LIT:U+002CU+0020>" ) <EOL> self . stream . write ( "<STR_LIT>" % errored ) <EOL> self . stream . writeln ( "<STR_LIT:)>" ) <EOL> else : <EOL> self . stream . writeln ( "<STR_LIT:OK>" ) <EOL> return result <EOL> class XmlTextTestRunner : <EOL> """<STR_LIT>""" <EOL> class _StdOut : <EOL> def __init__ ( self , std ) : <EOL> self . reset ( ) <EOL> self . _std = std <EOL> return <EOL> def write ( self , string ) : <EOL> self . _string += string <EOL> self . _std . write ( string ) <EOL> return <EOL> def read ( self ) : <EOL> return self . _string <EOL> def reset ( self ) : <EOL> self . _string = "<STR_LIT>" <EOL> class _StringStream : <EOL> def __init__ ( self ) : <EOL> self . reset ( ) <EOL> return <EOL> def write ( self , string ) : <EOL> self . _string += string <EOL> return <EOL> def read ( self ) : <EOL> return self . _string <EOL> def reset ( self ) : <EOL> self . _string = "<STR_LIT>" <EOL> def __init__ ( self , stream = sys . stderr , descriptions = <NUM_LIT:1> , verbosity = <NUM_LIT:1> ) : <EOL> self . descriptions = descriptions <EOL> self . verbosity = verbosity <EOL> self . stdout = self . _StdOut ( sys . stdout ) <EOL> sys . stdout = self . stdout <EOL> self . stderr = self . _StdOut ( sys . stderr ) <EOL> sys . stderr = self . stderr <EOL> self . testResults = self . _StringStream ( ) <EOL> self . totalTime = <NUM_LIT:0.0> <EOL> self . output = None <EOL> def _openOutputFile ( self , fileName ) : <EOL> if not os . path . isdir ( os . path . join ( "<STR_LIT>" , "<STR_LIT>" ) ) : os . makedirs ( os . path . join ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> self . outputFileName = '<STR_LIT>' <EOL> self . output = open ( self . outputFileName , '<STR_LIT:w>' ) <EOL> def _makeResult ( self ) : <EOL> return _XmlTextTestResult ( self . testResults , self . descriptions , self . verbosity ) <EOL> def _resetBuffers ( self ) : <EOL> self . testResults . reset ( ) <EOL> def run ( self , test ) : <EOL> "<STR_LIT>" <EOL> result = self . _makeResult ( ) <EOL> for t in test . _tests : <EOL> size = len ( sys . argv [ <NUM_LIT:0> ] ) <EOL> if sys . argv [ <NUM_LIT:0> ] . endswith ( '<STR_LIT>' ) : <EOL> ( filePath , fileName ) = os . path . split ( sys . argv [ <NUM_LIT:0> ] ) <EOL> fileName = fileName . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] <EOL> else : <EOL> fileName = "<STR_LIT:%s>" % string . split ( "<STR_LIT:%s>" % t . _tests [ <NUM_LIT:0> ] . _tests [ <NUM_LIT:0> ] . __class__ , '<STR_LIT:.>' ) [ <NUM_LIT:0> ] <EOL> self . _openOutputFile ( fileName ) <EOL> startTime = time . time ( ) <EOL> t ( result ) <EOL> stopTime = time . time ( ) <EOL> timeTaken = float ( stopTime - startTime ) <EOL> self . totalTime += timeTaken <EOL> self . _writeReport ( result , self . totalTime ) <EOL> run = result . testsRun <EOL> return result <EOL> def _writeReport ( self , result , timeTaken ) : <EOL> if self . output != None : <EOL> self . output . write ( '<STR_LIT>' ) <EOL> self . output . write ( '<STR_LIT>' % len ( result . errors ) ) <EOL> self . output . write ( '<STR_LIT>' % len ( result . failures ) ) <EOL> self . output . write ( '<STR_LIT>' % "<STR_LIT>" ) <EOL> self . output . write ( '<STR_LIT>' % result . testsRun ) <EOL> self . output . write ( '<STR_LIT>' % timeTaken ) <EOL> self . output . write ( '<STR_LIT>' ) <EOL> self . output . write ( self . testResults . read ( ) ) <EOL> self . output . write ( '<STR_LIT>' ) <EOL> self . output . write ( result . params ) <EOL> self . output . write ( '<STR_LIT>' ) <EOL> self . output . write ( self . stdout . read ( ) ) <EOL> self . output . write ( '<STR_LIT>' ) <EOL> self . output . write ( '<STR_LIT>' ) <EOL> self . output . write ( self . stderr . read ( ) ) <EOL> self . output . write ( '<STR_LIT>' ) <EOL> self . output . write ( '<STR_LIT>' ) <EOL> self . output . close ( ) <EOL> self . _resetBuffers ( ) <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' % ( result . testsRun , result . testsRun == <NUM_LIT:1> and '<STR_LIT>' or '<STR_LIT:s>' , timeTaken ) <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' , self . outputFileName , '<STR_LIT:\n>' <EOL> msg = '<STR_LIT>' <EOL> if not result . wasSuccessful ( ) : <EOL> msg += "<STR_LIT>" <EOL> failed , errored = map ( len , ( result . failures , result . errors ) ) <EOL> if failed : <EOL> msg += "<STR_LIT>" % failed <EOL> if errored : <EOL> if failed : msg += "<STR_LIT:U+002CU+0020>" <EOL> msg += "<STR_LIT>" % errored <EOL> msg += "<STR_LIT:)>" <EOL> else : <EOL> msg += "<STR_LIT:OK>" <EOL> print msg <EOL> else : <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> return <EOL> class TestProgram : <EOL> """<STR_LIT>""" <EOL> USAGE = """<STR_LIT>""" <EOL> def __init__ ( self , module = '<STR_LIT:__main__>' , defaultTest = None , <EOL> argv = None , testRunner = None , testLoader = defaultTestLoader ) : <EOL> if type ( module ) == type ( '<STR_LIT>' ) : <EOL> self . module = __import__ ( module ) <EOL> for part in string . split ( module , '<STR_LIT:.>' ) [ <NUM_LIT:1> : ] : <EOL> self . module = getattr ( self . module , part ) <EOL> else : <EOL> self . module = module <EOL> if argv is None : <EOL> argv = sys . argv <EOL> self . verbosity = <NUM_LIT:2> <EOL> self . xmlReport = False <EOL> self . defaultTest = defaultTest <EOL> self . testRunner = testRunner <EOL> self . testLoader = testLoader <EOL> self . progName = os . path . basename ( argv [ <NUM_LIT:0> ] ) <EOL> self . parseArgs ( argv ) <EOL> self . runTests ( ) <EOL> def usageExit ( self , msg = None ) : <EOL> if msg : print msg <EOL> print self . USAGE % self . __dict__ <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> def parseArgs ( self , argv ) : <EOL> import getopt <EOL> try : <EOL> options , args = getopt . getopt ( argv [ <NUM_LIT:1> : ] , '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:text>' ] ) <EOL> except getopt . error , msg : <EOL> self . usageExit ( msg ) <EOL> for opt , value in options : <EOL> if opt in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . usageExit ( ) <EOL> if opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . verbosity = <NUM_LIT:0> <EOL> if opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . verbosity = <NUM_LIT:2> <EOL> if opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . xmlReport = True <EOL> if opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . xmlReport = False <EOL> if os . getenv ( '<STR_LIT>' ) : <EOL> self . xmlReport = True <EOL> if len ( args ) == <NUM_LIT:0> and self . defaultTest is None : <EOL> self . test = self . testLoader . loadTestsFromModule ( self . module ) <EOL> return <EOL> if len ( args ) > <NUM_LIT:0> : <EOL> self . testNames = args <EOL> else : <EOL> print '<STR_LIT>' % self . defaultTest <EOL> self . testNames = ( self . defaultTest , ) <EOL> self . createTests ( ) <EOL> def createTests ( self ) : <EOL> self . test = self . testLoader . loadTestsFromNames ( self . testNames , <EOL> self . module ) <EOL> def runTests ( self ) : <EOL> if self . testRunner is None : <EOL> if self . xmlReport == True : <EOL> self . testRunner = XmlTextTestRunner ( verbosity = self . verbosity ) <EOL> else : <EOL> self . testRunner = TextTestRunner ( verbosity = self . verbosity ) <EOL> result = self . testRunner . run ( self . test ) <EOL> sys . exit ( not result . wasSuccessful ( ) ) <EOL> main = TestProgram <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( module = None ) </s>
