<s> """<STR_LIT>""" <EOL> __author__ = "<STR_LIT>" <EOL> __email__ = "<STR_LIT>" <EOL> __revision__ = "<STR_LIT>" [ <NUM_LIT:11> : - <NUM_LIT:2> ] <EOL> import os <EOL> import re <EOL> import string <EOL> import sys <EOL> import time <EOL> import traceback <EOL> import types <EOL> import pprint <EOL> try : <EOL> True , False <EOL> except NameError : <EOL> True , False = ( <NUM_LIT:1> == <NUM_LIT:1> ) , ( <NUM_LIT:1> == <NUM_LIT:0> ) <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> 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> name = None <EOL> def __init__ ( self , methodName = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> self . _testMethodName = methodName <EOL> self . _setupTestMethod ( ) <EOL> self . _setupMetaData ( ) <EOL> def _setupTestMethod ( self ) : <EOL> try : <EOL> self . _testMethod = getattr ( self , self . _testMethodName ) <EOL> except AttributeError : <EOL> raise ValueError , "<STR_LIT>" % ( self . __class__ , self . _testMethodName ) <EOL> def _setupMetaData ( self ) : <EOL> """<STR_LIT>""" <EOL> testDoc = self . _testMethod . __doc__ or '<STR_LIT:\n>' <EOL> testDocLines = testDoc . splitlines ( ) <EOL> testDescription = testDocLines [ <NUM_LIT:0> ] . strip ( ) <EOL> if len ( testDocLines ) > <NUM_LIT:1> : <EOL> testExplanation = '<STR_LIT:\n>' . join ( <EOL> [ ln . strip ( ) for ln in testDocLines [ <NUM_LIT:1> : ] ] <EOL> ) . strip ( ) <EOL> else : <EOL> testExplanation = '<STR_LIT>' <EOL> fixtureDoc = self . __doc__ or '<STR_LIT:\n>' <EOL> fixtureDocLines = fixtureDoc . splitlines ( ) <EOL> fixtureDescription = fixtureDocLines [ <NUM_LIT:0> ] . strip ( ) <EOL> if len ( fixtureDocLines ) > <NUM_LIT:1> : <EOL> fixtureExplanation = '<STR_LIT:\n>' . join ( <EOL> [ ln . strip ( ) for ln in fixtureDocLines [ <NUM_LIT:1> : ] ] <EOL> ) . strip ( ) <EOL> else : <EOL> fixtureExplanation = '<STR_LIT>' <EOL> if not self . name : <EOL> self . name = self . __class__ <EOL> self . _id = "<STR_LIT>" % ( self . name , self . _testMethodName ) <EOL> if not fixtureDescription : <EOL> self . _description = testDescription <EOL> else : <EOL> self . _description = fixtureDescription + '<STR_LIT:U+002CU+0020>' + testDescription <EOL> if not fixtureExplanation : <EOL> self . _explanation = testExplanation <EOL> else : <EOL> self . _explanation = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> fixtureExplanation , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> testExplanation <EOL> ] <EOL> self . _explanation = '<STR_LIT:\n>' . join ( self . _explanation ) <EOL> def id ( self ) : <EOL> return self . _id <EOL> def setId ( self , id ) : <EOL> self . _id = id <EOL> def describe ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _description <EOL> shortDescription = describe <EOL> def setDescription ( self , descr ) : <EOL> self . _description = descr <EOL> def explain ( self ) : <EOL> return self . _explanation <EOL> def setExplanation ( self , expln ) : <EOL> self . _explanation = expln <EOL> def setUp ( self ) : <EOL> "<STR_LIT>" <EOL> pass <EOL> def run ( self , result = None ) : <EOL> return self ( result ) <EOL> def tearDown ( self ) : <EOL> "<STR_LIT>" <EOL> pass <EOL> def debug ( self ) : <EOL> """<STR_LIT>""" <EOL> self . setUp ( ) <EOL> self . _testMethod ( ) <EOL> self . tearDown ( ) <EOL> def defaultTestResult ( self ) : <EOL> return TestResult ( ) <EOL> def __call__ ( self , result = None ) : <EOL> if result is None : <EOL> result = self . defaultTestResult ( ) <EOL> result . startTest ( self ) <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> self . _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 : <EOL> result . addSuccess ( self ) <EOL> finally : <EOL> result . stopTest ( self ) <EOL> return result <EOL> def countTestCases ( self ) : <EOL> return <NUM_LIT:1> <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 __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> def failUnlessAlmostEqual ( self , first , second , places = <NUM_LIT:7> , msg = None ) : <EOL> """<STR_LIT>""" <EOL> if round ( second - first , places ) != <NUM_LIT:0> : <EOL> raise self . failureException , ( msg or '<STR_LIT>' % ( ` first ` , ` second ` , ` places ` ) ) <EOL> def failIfAlmostEqual ( self , first , second , places = <NUM_LIT:7> , msg = None ) : <EOL> """<STR_LIT>""" <EOL> if round ( second - first , places ) == <NUM_LIT:0> : <EOL> raise self . failureException , ( msg or '<STR_LIT>' % ( ` first ` , ` second ` , ` places ` ) ) <EOL> assertEqual = assertEquals = failUnlessEqual <EOL> assertNotEqual = assertNotEquals = failIfEqual <EOL> assertAlmostEqual = assertAlmostEquals = failUnlessAlmostEqual <EOL> assertNotAlmostEqual = assertNotAlmostEquals = failIfAlmostEqual <EOL> assertRaises = failUnlessRaises <EOL> assert_ = failUnless <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 describe ( 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> shortDescription = describe <EOL> class TestSuite : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , tests = ( ) , suiteName = None ) : <EOL> self . _tests = [ ] <EOL> self . _testMap = { } <EOL> self . suiteName = suiteName <EOL> self . addTests ( tests ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . __class__ , pprint . pformat ( 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> if isinstance ( test , TestSuite ) and test . suiteName : <EOL> name = test . suiteName <EOL> elif isinstance ( test , TestCase ) : <EOL> name = test . _testMethodName <EOL> else : <EOL> name = test . __class__ . __name__ <EOL> self . _testMap [ name ] = test <EOL> def addTests ( self , tests ) : <EOL> for test in tests : <EOL> self . addTest ( test ) <EOL> def getTestForName ( self , name ) : <EOL> return self . _testMap [ name ] <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 StreamWrapper : <EOL> def __init__ ( self , out = sys . stdout , err = sys . stderr ) : <EOL> self . _streamOut = out <EOL> self . _streamErr = err <EOL> def write ( self , txt ) : <EOL> self . _streamOut . write ( txt ) <EOL> self . _streamOut . flush ( ) <EOL> def writeln ( self , * lines ) : <EOL> for line in lines : <EOL> self . write ( line + '<STR_LIT:\n>' ) <EOL> if not lines : <EOL> self . write ( '<STR_LIT:\n>' ) <EOL> def writeErr ( self , txt ) : <EOL> self . _streamErr . write ( txt ) <EOL> def writelnErr ( self , * lines ) : <EOL> for line in lines : <EOL> self . writeErr ( line + '<STR_LIT:\n>' ) <EOL> if not lines : <EOL> self . writeErr ( '<STR_LIT:\n>' ) <EOL> class _TextTestResult ( TestResult , StreamWrapper ) : <EOL> _separatorWidth = <NUM_LIT> <EOL> _sep1 = '<STR_LIT:=>' <EOL> _sep2 = '<STR_LIT:->' <EOL> _errorSep1 = '<STR_LIT:*>' <EOL> _errorSep2 = '<STR_LIT:->' <EOL> _errorSep3 = '<STR_LIT>' <EOL> def __init__ ( self , <EOL> stream = sys . stdout , <EOL> errStream = sys . stderr , <EOL> verbosity = <NUM_LIT:1> , <EOL> explain = False ) : <EOL> TestResult . __init__ ( self ) <EOL> StreamWrapper . __init__ ( self , out = stream , err = errStream ) <EOL> self . _verbosity = verbosity <EOL> self . _showAll = verbosity > <NUM_LIT:1> <EOL> self . _dots = ( verbosity == <NUM_LIT:1> ) <EOL> self . _explain = explain <EOL> def beginTests ( self ) : <EOL> self . _startTime = time . time ( ) <EOL> def endTests ( self ) : <EOL> self . _stopTime = time . time ( ) <EOL> self . _timeTaken = float ( self . _stopTime - self . _startTime ) <EOL> def stop ( self ) : <EOL> self . shouldStop = <NUM_LIT:1> <EOL> def startTest ( self , test ) : <EOL> TestResult . startTest ( self , test ) <EOL> if self . _showAll : <EOL> self . write ( "<STR_LIT>" % ( test . id ( ) , test . describe ( ) ) ) <EOL> self . write ( "<STR_LIT>" ) <EOL> def addSuccess ( self , test ) : <EOL> TestResult . addSuccess ( self , test ) <EOL> if self . _showAll : <EOL> self . writeln ( "<STR_LIT>" ) <EOL> elif self . _dots : <EOL> self . write ( '<STR_LIT:.>' ) <EOL> def addError ( self , test , err ) : <EOL> TestResult . addError ( self , test , err ) <EOL> if self . _showAll : <EOL> self . writeln ( "<STR_LIT>" ) <EOL> elif self . _dots : <EOL> self . write ( '<STR_LIT:E>' ) <EOL> if err [ <NUM_LIT:0> ] is KeyboardInterrupt : <EOL> self . stop ( ) <EOL> def addFailure ( self , test , err ) : <EOL> TestResult . addFailure ( self , test , err ) <EOL> if self . _showAll : <EOL> self . writeln ( "<STR_LIT>" ) <EOL> elif self . _dots : <EOL> self . write ( '<STR_LIT:F>' ) <EOL> def summarize ( self ) : <EOL> self . printErrors ( ) <EOL> self . writeSep2 ( ) <EOL> run = self . testsRun <EOL> self . writeln ( "<STR_LIT>" % <EOL> ( run , run == <NUM_LIT:1> and "<STR_LIT>" or "<STR_LIT:s>" , self . _timeTaken ) ) <EOL> self . writeln ( ) <EOL> if not self . wasSuccessful ( ) : <EOL> self . writeErr ( "<STR_LIT>" ) <EOL> failed , errored = map ( len , ( self . failures , self . errors ) ) <EOL> if failed : <EOL> self . writeErr ( "<STR_LIT>" % failed ) <EOL> if errored : <EOL> if failed : self . writeErr ( "<STR_LIT:U+002CU+0020>" ) <EOL> self . writeErr ( "<STR_LIT>" % errored ) <EOL> self . writelnErr ( "<STR_LIT:)>" ) <EOL> else : <EOL> self . writelnErr ( "<STR_LIT:OK>" ) <EOL> def writeSep1 ( self ) : <EOL> self . writeln ( self . _sep1 * self . _separatorWidth ) <EOL> def writeSep2 ( self ) : <EOL> self . writeln ( self . _sep2 * self . _separatorWidth ) <EOL> def writeErrSep1 ( self ) : <EOL> self . writeln ( self . _errorSep1 * self . _separatorWidth ) <EOL> def writeErrSep2 ( self ) : <EOL> self . writeln ( self . _errorSep2 * self . _separatorWidth ) <EOL> def printErrors ( self ) : <EOL> if self . _dots or self . _showAll : <EOL> self . 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 . writeErrSep1 ( ) <EOL> self . writelnErr ( "<STR_LIT>" % ( flavour , test . id ( ) , test . describe ( ) ) ) <EOL> if self . _explain : <EOL> expln = test . explain ( ) <EOL> if expln : <EOL> self . writeErrSep2 ( ) <EOL> self . writeErr ( expln ) <EOL> self . writelnErr ( ) <EOL> self . writeErrSep2 ( ) <EOL> for line in apply ( traceback . format_exception , err ) : <EOL> for l in line . split ( "<STR_LIT:\n>" ) [ : - <NUM_LIT:1> ] : <EOL> self . writelnErr ( l ) <EOL> self . writelnErr ( "<STR_LIT>" ) <EOL> class TextTestRunner : <EOL> def __init__ ( self , <EOL> stream = sys . stdout , <EOL> errStream = sys . stderr , <EOL> verbosity = <NUM_LIT:1> , <EOL> explain = False ) : <EOL> self . _out = stream <EOL> self . _err = errStream <EOL> self . _verbosity = verbosity <EOL> self . _explain = explain <EOL> def run ( self , test ) : <EOL> result = self . _makeResult ( ) <EOL> result . beginTests ( ) <EOL> test ( result ) <EOL> result . endTests ( ) <EOL> result . summarize ( ) <EOL> return result <EOL> def _makeResult ( self ) : <EOL> return _TextTestResult ( stream = self . _out , <EOL> errStream = self . _err , <EOL> verbosity = self . _verbosity , <EOL> explain = self . _explain , <EOL> ) <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 ( tests = map ( testCaseClass , <EOL> self . getTestCaseNames ( testCaseClass ) ) , <EOL> suiteName = testCaseClass . __name__ ) <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> if isinstance ( obj , TestSuite ) : <EOL> obj = obj . getTestForName ( part ) <EOL> else : <EOL> obj = getattr ( obj , part ) <EOL> if type ( obj ) == types . ModuleType : <EOL> return self . loadTestsFromModule ( obj ) <EOL> elif type ( obj ) == types . ClassType and issubclass ( obj , TestCase ) : <EOL> return self . loadTestsFromTestCase ( obj ) <EOL> elif type ( obj ) == types . UnboundMethodType : <EOL> return obj . im_class ( obj . __name__ ) <EOL> elif isinstance ( obj , TestSuite ) : <EOL> return obj <EOL> elif isinstance ( obj , TestCase ) : <EOL> return obj <EOL> elif callable ( obj ) : <EOL> test = obj ( ) <EOL> if not isinstance ( test , TestCase ) and not isinstance ( test , 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 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> testSuite = None ) : <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 . test = testSuite <EOL> self . verbosity = <NUM_LIT:1> <EOL> self . explain = <NUM_LIT:0> <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>' ] ) <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 . explain = True <EOL> if len ( args ) == <NUM_LIT:0> and self . defaultTest is None and self . test 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> self . testNames = ( self . defaultTest , ) <EOL> self . createTests ( ) <EOL> except getopt . error , msg : <EOL> self . usageExit ( msg ) <EOL> def createTests ( self ) : <EOL> if self . test == None : <EOL> self . test = self . testLoader . loadTestsFromNames ( self . testNames , <EOL> self . module ) <EOL> def runTests ( self ) : <EOL> if self . testRunner is None : <EOL> self . testRunner = TextTestRunner ( verbosity = self . verbosity , <EOL> explain = self . explain ) <EOL> result = self . testRunner . run ( self . test ) <EOL> self . _cleanupAfterRunningTests ( ) <EOL> sys . exit ( not result . wasSuccessful ( ) ) <EOL> def _cleanupAfterRunningTests ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> main = TestProgram <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( module = None ) </s>
