Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Static Public Attributes
run_tests.TestRunner Class Reference

List of all members.

Public Member Functions

def __init__
def runTest
def run

Public Attributes

 tests

Static Public Attributes

list file = sys.argv[0]
 file = __file__
tuple testdir = os.path.dirname(file)

Detailed Description

Definition at line 298 of file run_tests.py.


Constructor & Destructor Documentation

def run_tests.TestRunner.__init__ (   self,
  tests = [],
  verbosity = 0 
)

Definition at line 306 of file run_tests.py.

00306 
00307     def __init__(self, tests=[], verbosity=0):
00308         # if no tests were specified to run, we run them all
00309         # including the doctests
00310         self.tests = tests
00311         if not self.tests:
00312             # Make a list of all applicable test modules.
00313             names = os.listdir(TestRunner.testdir)
00314             for name in names:
00315                 if name[:5] == "test_" and name[-3:] == ".py":
00316                     self.tests.append(name[:-3])
00317             self.tests.sort()
00318             self.tests.append("doctest")
00319         if "doctest" in self.tests:
00320             self.tests.remove("doctest")
00321             self.tests.extend(DOCTEST_MODULES)
00322         stream = cStringIO.StringIO()
00323         unittest.TextTestRunner.__init__(self, stream,
00324                 verbosity=verbosity)


Member Function Documentation

def run_tests.TestRunner.run (   self)
Run tests, return number of failures (integer).

Definition at line 403 of file run_tests.py.

00403 
00404     def run(self):
00405         """Run tests, return number of failures (integer)."""
00406         failures = 0
00407         startTime = time.time()
00408         for test in self.tests:
00409             ok = self.runTest(test)
00410             if not ok:
00411                 failures += 1
00412         total = len(self.tests)
00413         stopTime = time.time()
00414         timeTaken = stopTime - startTime
00415         sys.stderr.write(self.stream.getvalue())
00416         sys.stderr.write('-' * 70 + "\n")
00417         sys.stderr.write("Ran %d test%s in %.3f seconds\n" %
00418                             (total, total != 1 and "s" or "", timeTaken))
00419         sys.stderr.write("\n")
00420         if failures:
00421             sys.stderr.write("FAILED (failures = %d)\n" % failures)
00422         return failures
00423 

Here is the call graph for this function:

def run_tests.TestRunner.runTest (   self,
  name 
)

Definition at line 325 of file run_tests.py.

00325 
00326     def runTest(self, name):
00327         from Bio import MissingExternalDependencyError
00328         result = self._makeResult()
00329         output = cStringIO.StringIO()
00330         # Restore the language and thus default encoding (in case a prior
00331         # test changed this, e.g. to help with detecting command line tools)
00332         global system_lang
00333         os.environ['LANG']=system_lang
00334         # Note the current directory:
00335         cur_dir = os.path.abspath(".")
00336         try:
00337             stdout = sys.stdout
00338             sys.stdout = output
00339             if name.startswith("test_"):
00340                 sys.stderr.write("%s ... " % name)
00341                 #It's either a unittest or a print-and-compare test
00342                 suite = unittest.TestLoader().loadTestsFromName(name)
00343                 if suite.countTestCases()==0:
00344                     # This is a print-and-compare test instead of a
00345                     # unittest-type test.
00346                     test = ComparisonTestCase(name, output)
00347                     suite = unittest.TestSuite([test])
00348             else:
00349                 #It's a doc test
00350                 sys.stderr.write("%s docstring test ... " % name)
00351                 #Can't use fromlist=name.split(".") until python 2.5+
00352                 module = __import__(name, None, None, name.split("."))
00353                 suite = doctest.DocTestSuite(module)
00354                 del module
00355             suite.run(result)
00356             if cur_dir != os.path.abspath("."):
00357                 sys.stderr.write("FAIL\n")
00358                 result.stream.write(result.separator1+"\n")
00359                 result.stream.write("ERROR: %s\n" % name)
00360                 result.stream.write(result.separator2+"\n")
00361                 result.stream.write("Current directory changed\n")
00362                 result.stream.write("Was: %s\n" % cur_dir)
00363                 result.stream.write("Now: %s\n" % os.path.abspath("."))
00364                 os.chdir(cur_dir)
00365                 if not result.wasSuccessful():
00366                     result.printErrors()
00367                 return False
00368             elif result.wasSuccessful():
00369                 sys.stderr.write("ok\n")
00370                 return True
00371             else:
00372                 sys.stderr.write("FAIL\n")
00373                 result.printErrors()
00374             return False
00375         except MissingExternalDependencyError, msg:
00376             sys.stderr.write("skipping. %s\n" % msg)
00377             return True
00378         except Exception, msg:
00379             # This happened during the import
00380             sys.stderr.write("ERROR\n")
00381             result.stream.write(result.separator1+"\n")
00382             result.stream.write("ERROR: %s\n" % name)
00383             result.stream.write(result.separator2+"\n")
00384             result.stream.write(traceback.format_exc())
00385             return False
00386         except KeyboardInterrupt, err:
00387             # Want to allow this, and abort the test
00388             # (see below for special case)
00389             raise err
00390         except:
00391             # This happens in Jython with java.lang.ClassFormatError:
00392             # Invalid method Code length ...
00393             sys.stderr.write("ERROR\n")
00394             result.stream.write(result.separator1+"\n")
00395             result.stream.write("ERROR: %s\n" % name)
00396             result.stream.write(result.separator2+"\n")
00397             result.stream.write(traceback.format_exc())
00398             return False
00399         finally:
00400             sys.stdout = stdout
00401             #Running under PyPy we were leaking file handles...
00402             gc.collect()

Here is the caller graph for this function:


Member Data Documentation

list run_tests.TestRunner.file = sys.argv[0] [static]

Definition at line 301 of file run_tests.py.

run_tests.TestRunner.file = __file__ [static]

Definition at line 303 of file run_tests.py.

tuple run_tests.TestRunner.testdir = os.path.dirname(file) [static]

Definition at line 304 of file run_tests.py.

Definition at line 309 of file run_tests.py.


The documentation for this class was generated from the following file: