home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2830 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  23.9 KB  |  804 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __author__ = 'Steve Purcell'
  5. __email__ = 'stephen_purcell at yahoo dot com'
  6. __version__ = '#Revision: 1.63 $'[11:-2]
  7. import time
  8. import sys
  9. import traceback
  10. import os
  11. import types
  12. __all__ = [
  13.     'TestResult',
  14.     'TestCase',
  15.     'TestSuite',
  16.     'TextTestRunner',
  17.     'TestLoader',
  18.     'FunctionTestCase',
  19.     'main',
  20.     'defaultTestLoader']
  21. __all__.extend([
  22.     'getTestCaseNames',
  23.     'makeSuite',
  24.     'findTestCases'])
  25. if sys.version_info[:2] < (2, 2):
  26.     
  27.     def isinstance(obj, clsinfo):
  28.         import __builtin__
  29.         if type(clsinfo) in (tuple, list):
  30.             for cls in clsinfo:
  31.                 if cls is type:
  32.                     cls = types.ClassType
  33.                 
  34.                 if __builtin__.isinstance(obj, cls):
  35.                     return 1
  36.             
  37.             return 0
  38.         return __builtin__.isinstance(obj, clsinfo)
  39.  
  40.  
  41.  
  42. def _CmpToKey(mycmp):
  43.     
  44.     class K((object,)):
  45.         
  46.         def __init__(self, obj):
  47.             self.obj = obj
  48.  
  49.         
  50.         def __lt__(self, other):
  51.             return mycmp(self.obj, other.obj) == -1
  52.  
  53.  
  54.     return K
  55.  
  56. __metaclass__ = type
  57.  
  58. def _strclass(cls):
  59.     return '%s.%s' % (cls.__module__, cls.__name__)
  60.  
  61. __unittest = 1
  62.  
  63. class TestResult:
  64.     
  65.     def __init__(self):
  66.         self.failures = []
  67.         self.errors = []
  68.         self.testsRun = 0
  69.         self.shouldStop = False
  70.  
  71.     
  72.     def startTest(self, test):
  73.         self.testsRun = self.testsRun + 1
  74.  
  75.     
  76.     def stopTest(self, test):
  77.         pass
  78.  
  79.     
  80.     def addError(self, test, err):
  81.         self.errors.append((test, self._exc_info_to_string(err, test)))
  82.  
  83.     
  84.     def addFailure(self, test, err):
  85.         self.failures.append((test, self._exc_info_to_string(err, test)))
  86.  
  87.     
  88.     def addSuccess(self, test):
  89.         pass
  90.  
  91.     
  92.     def wasSuccessful(self):
  93.         if len(self.errors) == len(self.errors):
  94.             return len(self.errors) == 0
  95.         len(self.errors) == len(self.errors)
  96.         return len(self.errors)
  97.  
  98.     
  99.     def stop(self):
  100.         self.shouldStop = True
  101.  
  102.     
  103.     def _exc_info_to_string(self, err, test):
  104.         (exctype, value, tb) = err
  105.         while tb and self._is_relevant_tb_level(tb):
  106.             tb = tb.tb_next
  107.         if exctype is test.failureException:
  108.             length = self._count_relevant_tb_levels(tb)
  109.             return ''.join(traceback.format_exception(exctype, value, tb, length))
  110.         return ''.join(traceback.format_exception(exctype, value, tb))
  111.  
  112.     
  113.     def _is_relevant_tb_level(self, tb):
  114.         return '__unittest' in tb.tb_frame.f_globals
  115.  
  116.     
  117.     def _count_relevant_tb_levels(self, tb):
  118.         length = 0
  119.         while tb and not self._is_relevant_tb_level(tb):
  120.             length += 1
  121.             tb = tb.tb_next
  122.         return length
  123.  
  124.     
  125.     def __repr__(self):
  126.         return '<%s run=%i errors=%i failures=%i>' % (_strclass(self.__class__), self.testsRun, len(self.errors), len(self.failures))
  127.  
  128.  
  129.  
  130. class TestCase:
  131.     failureException = AssertionError
  132.     
  133.     def __init__(self, methodName = 'runTest'):
  134.         
  135.         try:
  136.             self._testMethodName = methodName
  137.             testMethod = getattr(self, methodName)
  138.             self._testMethodDoc = testMethod.__doc__
  139.         except AttributeError:
  140.             raise ValueError, 'no such test method in %s: %s' % (self.__class__, methodName)
  141.  
  142.  
  143.     
  144.     def setUp(self):
  145.         pass
  146.  
  147.     
  148.     def tearDown(self):
  149.         pass
  150.  
  151.     
  152.     def countTestCases(self):
  153.         return 1
  154.  
  155.     
  156.     def defaultTestResult(self):
  157.         return TestResult()
  158.  
  159.     
  160.     def shortDescription(self):
  161.         doc = self._testMethodDoc
  162.         if not doc or doc.split('\n')[0].strip():
  163.             pass
  164.  
  165.     
  166.     def id(self):
  167.         return '%s.%s' % (_strclass(self.__class__), self._testMethodName)
  168.  
  169.     
  170.     def __eq__(self, other):
  171.         if type(self) is not type(other):
  172.             return False
  173.         return self._testMethodName == other._testMethodName
  174.  
  175.     
  176.     def __ne__(self, other):
  177.         return not (self == other)
  178.  
  179.     
  180.     def __hash__(self):
  181.         return hash((type(self), self._testMethodName))
  182.  
  183.     
  184.     def __str__(self):
  185.         return '%s (%s)' % (self._testMethodName, _strclass(self.__class__))
  186.  
  187.     
  188.     def __repr__(self):
  189.         return '<%s testMethod=%s>' % (_strclass(self.__class__), self._testMethodName)
  190.  
  191.     
  192.     def run(self, result = None):
  193.         if result is None:
  194.             result = self.defaultTestResult()
  195.         
  196.         result.startTest(self)
  197.         testMethod = getattr(self, self._testMethodName)
  198.         
  199.         try:
  200.             self.setUp()
  201.         except KeyboardInterrupt:
  202.             raise 
  203.         except:
  204.             result.addError(self, self._exc_info())
  205.             return None
  206.         
  207.  
  208.         ok = False
  209.         
  210.         try:
  211.             testMethod()
  212.             ok = True
  213.         except self.failureException:
  214.             result.addFailure(self, self._exc_info())
  215.         except KeyboardInterrupt:
  216.             raise 
  217.         except:
  218.             result.addError(self, self._exc_info())
  219.  
  220.         
  221.         try:
  222.             self.tearDown()
  223.         except KeyboardInterrupt:
  224.             raise 
  225.         except:
  226.             result.addError(self, self._exc_info())
  227.             ok = False
  228.  
  229.         if ok:
  230.             result.addSuccess(self)
  231.         result.stopTest(self)
  232.  
  233.     
  234.     def __call__(self, *args, **kwds):
  235.         return self.run(*args, **kwds)
  236.  
  237.     
  238.     def debug(self):
  239.         self.setUp()
  240.         getattr(self, self._testMethodName)()
  241.         self.tearDown()
  242.  
  243.     
  244.     def _exc_info(self):
  245.         return sys.exc_info()
  246.  
  247.     
  248.     def fail(self, msg = None):
  249.         raise self.failureException, msg
  250.  
  251.     
  252.     def failIf(self, expr, msg = None):
  253.         if expr:
  254.             raise self.failureException, msg
  255.         expr
  256.  
  257.     
  258.     def failUnless(self, expr, msg = None):
  259.         if not expr:
  260.             raise self.failureException, msg
  261.         expr
  262.  
  263.     
  264.     def failUnlessRaises(self, excClass, callableObj, *args, **kwargs):
  265.         
  266.         try:
  267.             callableObj(*args, **kwargs)
  268.         except excClass:
  269.             return None
  270.  
  271.         if hasattr(excClass, '__name__'):
  272.             excName = excClass.__name__
  273.         else:
  274.             excName = str(excClass)
  275.         raise self.failureException, '%s not raised' % excName
  276.  
  277.     
  278.     def failUnlessEqual(self, first, second, msg = None):
  279.         if not first == second:
  280.             if not msg:
  281.                 pass
  282.             raise self.failureException, '%r != %r' % (first, second)
  283.         first == second
  284.  
  285.     
  286.     def failIfEqual(self, first, second, msg = None):
  287.         if first == second:
  288.             if not msg:
  289.                 pass
  290.             raise self.failureException, '%r == %r' % (first, second)
  291.         first == second
  292.  
  293.     
  294.     def failUnlessAlmostEqual(self, first, second, places = 7, msg = None):
  295.         if round(abs(second - first), places) != 0:
  296.             if not msg:
  297.                 pass
  298.             raise self.failureException, '%r != %r within %r places' % (first, second, places)
  299.         round(abs(second - first), places) != 0
  300.  
  301.     
  302.     def failIfAlmostEqual(self, first, second, places = 7, msg = None):
  303.         if round(abs(second - first), places) == 0:
  304.             if not msg:
  305.                 pass
  306.             raise self.failureException, '%r == %r within %r places' % (first, second, places)
  307.         round(abs(second - first), places) == 0
  308.  
  309.     assertEqual = assertEquals = failUnlessEqual
  310.     assertNotEqual = assertNotEquals = failIfEqual
  311.     assertAlmostEqual = assertAlmostEquals = failUnlessAlmostEqual
  312.     assertNotAlmostEqual = assertNotAlmostEquals = failIfAlmostEqual
  313.     assertRaises = failUnlessRaises
  314.     assert_ = assertTrue = failUnless
  315.     assertFalse = failIf
  316.  
  317.  
  318. class TestSuite:
  319.     
  320.     def __init__(self, tests = ()):
  321.         self._tests = []
  322.         self.addTests(tests)
  323.  
  324.     
  325.     def __repr__(self):
  326.         return '<%s tests=%s>' % (_strclass(self.__class__), self._tests)
  327.  
  328.     __str__ = __repr__
  329.     
  330.     def __eq__(self, other):
  331.         if type(self) is not type(other):
  332.             return False
  333.         return self._tests == other._tests
  334.  
  335.     
  336.     def __ne__(self, other):
  337.         return not (self == other)
  338.  
  339.     __hash__ = None
  340.     
  341.     def __iter__(self):
  342.         return iter(self._tests)
  343.  
  344.     
  345.     def countTestCases(self):
  346.         cases = 0
  347.         for test in self._tests:
  348.             cases += test.countTestCases()
  349.         
  350.         return cases
  351.  
  352.     
  353.     def addTest(self, test):
  354.         if not hasattr(test, '__call__'):
  355.             raise TypeError('the test to add must be callable')
  356.         hasattr(test, '__call__')
  357.         if isinstance(test, (type, types.ClassType)) and issubclass(test, (TestCase, TestSuite)):
  358.             raise TypeError('TestCases and TestSuites must be instantiated before passing them to addTest()')
  359.         issubclass(test, (TestCase, TestSuite))
  360.         self._tests.append(test)
  361.  
  362.     
  363.     def addTests(self, tests):
  364.         if isinstance(tests, basestring):
  365.             raise TypeError('tests must be an iterable of tests, not a string')
  366.         isinstance(tests, basestring)
  367.         for test in tests:
  368.             self.addTest(test)
  369.         
  370.  
  371.     
  372.     def run(self, result):
  373.         for test in self._tests:
  374.             if result.shouldStop:
  375.                 break
  376.             
  377.             test(result)
  378.         
  379.         return result
  380.  
  381.     
  382.     def __call__(self, *args, **kwds):
  383.         return self.run(*args, **kwds)
  384.  
  385.     
  386.     def debug(self):
  387.         for test in self._tests:
  388.             test.debug()
  389.         
  390.  
  391.  
  392.  
  393. class FunctionTestCase(TestCase):
  394.     
  395.     def __init__(self, testFunc, setUp = None, tearDown = None, description = None):
  396.         TestCase.__init__(self)
  397.         self._FunctionTestCase__setUpFunc = setUp
  398.         self._FunctionTestCase__tearDownFunc = tearDown
  399.         self._FunctionTestCase__testFunc = testFunc
  400.         self._FunctionTestCase__description = description
  401.  
  402.     
  403.     def setUp(self):
  404.         if self._FunctionTestCase__setUpFunc is not None:
  405.             self._FunctionTestCase__setUpFunc()
  406.         
  407.  
  408.     
  409.     def tearDown(self):
  410.         if self._FunctionTestCase__tearDownFunc is not None:
  411.             self._FunctionTestCase__tearDownFunc()
  412.         
  413.  
  414.     
  415.     def runTest(self):
  416.         self._FunctionTestCase__testFunc()
  417.  
  418.     
  419.     def id(self):
  420.         return self._FunctionTestCase__testFunc.__name__
  421.  
  422.     
  423.     def __eq__(self, other):
  424.         if type(self) is not type(other):
  425.             return False
  426.         if self._FunctionTestCase__setUpFunc == other._FunctionTestCase__setUpFunc and self._FunctionTestCase__tearDownFunc == other._FunctionTestCase__tearDownFunc and self._FunctionTestCase__testFunc == other._FunctionTestCase__testFunc:
  427.             pass
  428.         return self._FunctionTestCase__description == other._FunctionTestCase__description
  429.  
  430.     
  431.     def __ne__(self, other):
  432.         return not (self == other)
  433.  
  434.     
  435.     def __hash__(self):
  436.         return hash((type(self), self._FunctionTestCase__setUpFunc, self._FunctionTestCase__tearDownFunc, self._FunctionTestCase__testFunc, self._FunctionTestCase__description))
  437.  
  438.     
  439.     def __str__(self):
  440.         return '%s (%s)' % (_strclass(self.__class__), self._FunctionTestCase__testFunc.__name__)
  441.  
  442.     
  443.     def __repr__(self):
  444.         return '<%s testFunc=%s>' % (_strclass(self.__class__), self._FunctionTestCase__testFunc)
  445.  
  446.     
  447.     def shortDescription(self):
  448.         if self._FunctionTestCase__description is not None:
  449.             return self._FunctionTestCase__description
  450.         doc = self._FunctionTestCase__testFunc.__doc__
  451.         if not doc or doc.split('\n')[0].strip():
  452.             pass
  453.  
  454.  
  455.  
  456. class TestLoader:
  457.     testMethodPrefix = 'test'
  458.     sortTestMethodsUsing = cmp
  459.     suiteClass = TestSuite
  460.     
  461.     def loadTestsFromTestCase(self, testCaseClass):
  462.         if issubclass(testCaseClass, TestSuite):
  463.             raise TypeError('Test cases should not be derived from TestSuite. Maybe you meant to derive from TestCase?')
  464.         issubclass(testCaseClass, TestSuite)
  465.         testCaseNames = self.getTestCaseNames(testCaseClass)
  466.         if not testCaseNames and hasattr(testCaseClass, 'runTest'):
  467.             testCaseNames = [
  468.                 'runTest']
  469.         
  470.         return self.suiteClass(map(testCaseClass, testCaseNames))
  471.  
  472.     
  473.     def loadTestsFromModule(self, module):
  474.         tests = []
  475.         for name in dir(module):
  476.             obj = getattr(module, name)
  477.             if isinstance(obj, (type, types.ClassType)) and issubclass(obj, TestCase):
  478.                 tests.append(self.loadTestsFromTestCase(obj))
  479.                 continue
  480.         
  481.         return self.suiteClass(tests)
  482.  
  483.     
  484.     def loadTestsFromName(self, name, module = None):
  485.         parts = name.split('.')
  486.         if module is None:
  487.             parts_copy = parts[:]
  488.             while parts_copy:
  489.                 
  490.                 try:
  491.                     module = __import__('.'.join(parts_copy))
  492.                 continue
  493.                 except ImportError:
  494.                     del parts_copy[-1]
  495.                     if not parts_copy:
  496.                         raise 
  497.                     parts_copy
  498.                     continue
  499.                 
  500.  
  501.                 None<EXCEPTION MATCH>ImportError
  502.             parts = parts[1:]
  503.         
  504.         obj = module
  505.         for part in parts:
  506.             parent = obj
  507.             obj = getattr(obj, part)
  508.         
  509.         if type(obj) == types.ModuleType:
  510.             return self.loadTestsFromModule(obj)
  511.         if isinstance(obj, (type, types.ClassType)) and issubclass(obj, TestCase):
  512.             return self.loadTestsFromTestCase(obj)
  513.         if type(obj) == types.UnboundMethodType and isinstance(parent, (type, types.ClassType)) and issubclass(parent, TestCase):
  514.             return TestSuite([
  515.                 parent(obj.__name__)])
  516.         if isinstance(obj, TestSuite):
  517.             return obj
  518.         if hasattr(obj, '__call__'):
  519.             test = obj()
  520.             if isinstance(test, TestSuite):
  521.                 return test
  522.             if isinstance(test, TestCase):
  523.                 return TestSuite([
  524.                     test])
  525.             raise TypeError('calling %s returned %s, not a test' % (obj, test))
  526.         hasattr(obj, '__call__')
  527.         raise TypeError("don't know how to make test from: %s" % obj)
  528.  
  529.     
  530.     def loadTestsFromNames(self, names, module = None):
  531.         suites = [ self.loadTestsFromName(name, module) for name in names ]
  532.         return self.suiteClass(suites)
  533.  
  534.     
  535.     def getTestCaseNames(self, testCaseClass):
  536.         
  537.         def isTestMethod(attrname, testCaseClass = testCaseClass, prefix = self.testMethodPrefix):
  538.             if attrname.startswith(prefix):
  539.                 pass
  540.             return hasattr(getattr(testCaseClass, attrname), '__call__')
  541.  
  542.         testFnNames = filter(isTestMethod, dir(testCaseClass))
  543.         if self.sortTestMethodsUsing:
  544.             testFnNames.sort(key = _CmpToKey(self.sortTestMethodsUsing))
  545.         
  546.         return testFnNames
  547.  
  548.  
  549. defaultTestLoader = TestLoader()
  550.  
  551. def _makeLoader(prefix, sortUsing, suiteClass = None):
  552.     loader = TestLoader()
  553.     loader.sortTestMethodsUsing = sortUsing
  554.     loader.testMethodPrefix = prefix
  555.     if suiteClass:
  556.         loader.suiteClass = suiteClass
  557.     
  558.     return loader
  559.  
  560.  
  561. def getTestCaseNames(testCaseClass, prefix, sortUsing = cmp):
  562.     return _makeLoader(prefix, sortUsing).getTestCaseNames(testCaseClass)
  563.  
  564.  
  565. def makeSuite(testCaseClass, prefix = 'test', sortUsing = cmp, suiteClass = TestSuite):
  566.     return _makeLoader(prefix, sortUsing, suiteClass).loadTestsFromTestCase(testCaseClass)
  567.  
  568.  
  569. def findTestCases(module, prefix = 'test', sortUsing = cmp, suiteClass = TestSuite):
  570.     return _makeLoader(prefix, sortUsing, suiteClass).loadTestsFromModule(module)
  571.  
  572.  
  573. class _WritelnDecorator:
  574.     
  575.     def __init__(self, stream):
  576.         self.stream = stream
  577.  
  578.     
  579.     def __getattr__(self, attr):
  580.         return getattr(self.stream, attr)
  581.  
  582.     
  583.     def writeln(self, arg = None):
  584.         if arg:
  585.             self.write(arg)
  586.         
  587.         self.write('\n')
  588.  
  589.  
  590.  
  591. class _TextTestResult(TestResult):
  592.     separator1 = '=' * 70
  593.     separator2 = '-' * 70
  594.     
  595.     def __init__(self, stream, descriptions, verbosity):
  596.         TestResult.__init__(self)
  597.         self.stream = stream
  598.         self.showAll = verbosity > 1
  599.         self.dots = verbosity == 1
  600.         self.descriptions = descriptions
  601.  
  602.     
  603.     def getDescription(self, test):
  604.         if self.descriptions:
  605.             if not test.shortDescription():
  606.                 pass
  607.             return str(test)
  608.         return str(test)
  609.  
  610.     
  611.     def startTest(self, test):
  612.         TestResult.startTest(self, test)
  613.         if self.showAll:
  614.             self.stream.write(self.getDescription(test))
  615.             self.stream.write(' ... ')
  616.             self.stream.flush()
  617.         
  618.  
  619.     
  620.     def addSuccess(self, test):
  621.         TestResult.addSuccess(self, test)
  622.         if self.showAll:
  623.             self.stream.writeln('ok')
  624.         elif self.dots:
  625.             self.stream.write('.')
  626.             self.stream.flush()
  627.         
  628.  
  629.     
  630.     def addError(self, test, err):
  631.         TestResult.addError(self, test, err)
  632.         if self.showAll:
  633.             self.stream.writeln('ERROR')
  634.         elif self.dots:
  635.             self.stream.write('E')
  636.             self.stream.flush()
  637.         
  638.  
  639.     
  640.     def addFailure(self, test, err):
  641.         TestResult.addFailure(self, test, err)
  642.         if self.showAll:
  643.             self.stream.writeln('FAIL')
  644.         elif self.dots:
  645.             self.stream.write('F')
  646.             self.stream.flush()
  647.         
  648.  
  649.     
  650.     def printErrors(self):
  651.         if self.dots or self.showAll:
  652.             self.stream.writeln()
  653.         
  654.         self.printErrorList('ERROR', self.errors)
  655.         self.printErrorList('FAIL', self.failures)
  656.  
  657.     
  658.     def printErrorList(self, flavour, errors):
  659.         for test, err in errors:
  660.             self.stream.writeln(self.separator1)
  661.             self.stream.writeln('%s: %s' % (flavour, self.getDescription(test)))
  662.             self.stream.writeln(self.separator2)
  663.             self.stream.writeln('%s' % err)
  664.         
  665.  
  666.  
  667.  
  668. class TextTestRunner:
  669.     
  670.     def __init__(self, stream = sys.stderr, descriptions = 1, verbosity = 1):
  671.         self.stream = _WritelnDecorator(stream)
  672.         self.descriptions = descriptions
  673.         self.verbosity = verbosity
  674.  
  675.     
  676.     def _makeResult(self):
  677.         return _TextTestResult(self.stream, self.descriptions, self.verbosity)
  678.  
  679.     
  680.     def run(self, test):
  681.         result = self._makeResult()
  682.         startTime = time.time()
  683.         test(result)
  684.         stopTime = time.time()
  685.         timeTaken = stopTime - startTime
  686.         result.printErrors()
  687.         self.stream.writeln(result.separator2)
  688.         run = result.testsRun
  689.         if not run != 1 or 's':
  690.             pass
  691.         self.stream.writeln('Ran %d test%s in %.3fs' % (run, '', timeTaken))
  692.         self.stream.writeln()
  693.         if not result.wasSuccessful():
  694.             self.stream.write('FAILED (')
  695.             (failed, errored) = map(len, (result.failures, result.errors))
  696.             if failed:
  697.                 self.stream.write('failures=%d' % failed)
  698.             
  699.             if errored:
  700.                 if failed:
  701.                     self.stream.write(', ')
  702.                 
  703.                 self.stream.write('errors=%d' % errored)
  704.             
  705.             self.stream.writeln(')')
  706.         else:
  707.             self.stream.writeln('OK')
  708.         return result
  709.  
  710.  
  711.  
  712. class TestProgram:
  713.     USAGE = "Usage: %(progName)s [options] [test] [...]\n\nOptions:\n  -h, --help       Show this message\n  -v, --verbose    Verbose output\n  -q, --quiet      Minimal output\n\nExamples:\n  %(progName)s                               - run default set of tests\n  %(progName)s MyTestSuite                   - run suite 'MyTestSuite'\n  %(progName)s MyTestCase.testSomething      - run MyTestCase.testSomething\n  %(progName)s MyTestCase                    - run all 'test*' test methods\n                                               in MyTestCase\n"
  714.     
  715.     def __init__(self, module = '__main__', defaultTest = None, argv = None, testRunner = None, testLoader = defaultTestLoader):
  716.         if type(module) == type(''):
  717.             self.module = __import__(module)
  718.             for part in module.split('.')[1:]:
  719.                 self.module = getattr(self.module, part)
  720.             
  721.         else:
  722.             self.module = module
  723.         if argv is None:
  724.             argv = sys.argv
  725.         
  726.         self.verbosity = 1
  727.         self.defaultTest = defaultTest
  728.         self.testRunner = testRunner
  729.         self.testLoader = testLoader
  730.         self.progName = os.path.basename(argv[0])
  731.         self.parseArgs(argv)
  732.         self.runTests()
  733.  
  734.     
  735.     def usageExit(self, msg = None):
  736.         if msg:
  737.             print msg
  738.         
  739.         print self.USAGE % self.__dict__
  740.         sys.exit(2)
  741.  
  742.     
  743.     def parseArgs(self, argv):
  744.         import getopt
  745.         
  746.         try:
  747.             (options, args) = getopt.getopt(argv[1:], 'hHvq', [
  748.                 'help',
  749.                 'verbose',
  750.                 'quiet'])
  751.             for opt, value in options:
  752.                 if opt in ('-h', '-H', '--help'):
  753.                     self.usageExit()
  754.                 
  755.                 if opt in ('-q', '--quiet'):
  756.                     self.verbosity = 0
  757.                 
  758.                 if opt in ('-v', '--verbose'):
  759.                     self.verbosity = 2
  760.                     continue
  761.             
  762.             if len(args) == 0 and self.defaultTest is None:
  763.                 self.test = self.testLoader.loadTestsFromModule(self.module)
  764.                 return None
  765.             if len(args) > 0:
  766.                 self.testNames = args
  767.             else:
  768.                 self.testNames = (self.defaultTest,)
  769.             self.createTests()
  770.         except getopt.error:
  771.             msg = None
  772.             self.usageExit(msg)
  773.  
  774.  
  775.     
  776.     def createTests(self):
  777.         self.test = self.testLoader.loadTestsFromNames(self.testNames, self.module)
  778.  
  779.     
  780.     def runTests(self):
  781.         if self.testRunner is None:
  782.             self.testRunner = TextTestRunner
  783.         
  784.         if isinstance(self.testRunner, (type, types.ClassType)):
  785.             
  786.             try:
  787.                 testRunner = self.testRunner(verbosity = self.verbosity)
  788.             except TypeError:
  789.                 testRunner = self.testRunner()
  790.             except:
  791.                 None<EXCEPTION MATCH>TypeError
  792.             
  793.  
  794.         None<EXCEPTION MATCH>TypeError
  795.         testRunner = self.testRunner
  796.         result = testRunner.run(self.test)
  797.         sys.exit(not result.wasSuccessful())
  798.  
  799.  
  800. main = TestProgram
  801. if __name__ == '__main__':
  802.     main(module = None)
  803.  
  804.