Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
All Data Structures Namespaces Files Functions Variables
TestLoader Class Reference

Public Member Functions

def loadTestsFromTestCase
 
def loadTestsFromModule
 
def loadTestsFromName
 
def loadTestsFromNames
 
def getTestCaseNames
 

Static Public Attributes

string testMethodPrefix = 'test'
 
 sortTestMethodsUsing = cmp
 
 suiteClass = TestSuite
 

Detailed Description

This class is responsible for loading tests according to various
criteria and returning them wrapped in a Test

Definition at line 401 of file unittest.py.

Member Function Documentation

def getTestCaseNames (   self,
  testCaseClass 
)
Return a sorted sequence of method names found within testCaseClass

Definition at line 476 of file unittest.py.

References sre_parse.dir, fnmatch.filter(), TestLoader.getTestCaseNames(), TestLoader.sortTestMethodsUsing, and TestLoader.testMethodPrefix.

477  def getTestCaseNames(self, testCaseClass):
478  """Return a sorted sequence of method names found within testCaseClass
479  """
480  testFnNames = filter(lambda n,p=self.testMethodPrefix: n[:len(p)] == p,
481  dir(testCaseClass))
482  for baseclass in testCaseClass.__bases__:
483  for testFnName in self.getTestCaseNames(baseclass):
484  if testFnName not in testFnNames: # handle overridden methods
485  testFnNames.append(testFnName)
486  if self.sortTestMethodsUsing:
487  testFnNames.sort(self.sortTestMethodsUsing)
488  return testFnNames
489 
490 
def loadTestsFromModule (   self,
  module 
)
Return a suite of all tests cases contained in the given module

Definition at line 414 of file unittest.py.

References sre_parse.dir, TestLoader.loadTestsFromTestCase(), and TestLoader.suiteClass.

415  def loadTestsFromModule(self, module):
416  """Return a suite of all tests cases contained in the given module"""
417  tests = []
418  for name in dir(module):
419  obj = getattr(module, name)
420  if type(obj) == types.ClassType and issubclass(obj, TestCase):
421  tests.append(self.loadTestsFromTestCase(obj))
422  return self.suiteClass(tests)
def loadTestsFromName (   self,
  name,
  module = None 
)
Return a suite of all tests cases given a string specifier.

The name may resolve either to a module, a test case class, a
test method within a test case class, or a callable object which
returns a TestCase or TestSuite instance.

The method optionally resolves the names relative to a given module.

Definition at line 423 of file unittest.py.

References string.join(), TestLoader.loadTestsFromModule(), TestLoader.loadTestsFromTestCase(), go_somewhere_significant.obj, and string.split().

424  def loadTestsFromName(self, name, module=None):
425  """Return a suite of all tests cases given a string specifier.
426 
427  The name may resolve either to a module, a test case class, a
428  test method within a test case class, or a callable object which
429  returns a TestCase or TestSuite instance.
430 
431  The method optionally resolves the names relative to a given module.
432  """
433  parts = string.split(name, '.')
434  if module is None:
435  if not parts:
436  raise ValueError, "incomplete test name: %s" % name
437  else:
438  parts_copy = parts[:]
439  while parts_copy:
440  try:
441  module = __import__(string.join(parts_copy,'.'))
442  break
443  except ImportError:
444  del parts_copy[-1]
445  if not parts_copy: raise
446  parts = parts[1:]
447  obj = module
448  for part in parts:
449  obj = getattr(obj, part)
450 
451  import unittest
452  if type(obj) == types.ModuleType:
453  return self.loadTestsFromModule(obj)
454  elif type(obj) == types.ClassType and issubclass(obj, unittest.TestCase):
455  return self.loadTestsFromTestCase(obj)
456  elif type(obj) == types.UnboundMethodType:
457  return obj.im_class(obj.__name__)
458  elif callable(obj):
459  test = obj()
460  if not isinstance(test, unittest.TestCase) and \
461  not isinstance(test, unittest.TestSuite):
462  raise ValueError, \
463  "calling %s returned %s, not a test" % (obj,test)
464  return test
465  else:
466  raise ValueError, "don't know how to make test from: %s" % obj
def loadTestsFromNames (   self,
  names,
  module = None 
)
Return a suite of all tests cases found using the given sequence
of string specifiers. See 'loadTestsFromName()'.

Definition at line 467 of file unittest.py.

References TestLoader.loadTestsFromName(), and TestLoader.suiteClass.

468  def loadTestsFromNames(self, names, module=None):
469  """Return a suite of all tests cases found using the given sequence
470  of string specifiers. See 'loadTestsFromName()'.
471  """
472  suites = []
473  for name in names:
474  suites.append(self.loadTestsFromName(name, module))
475  return self.suiteClass(suites)
def loadTestsFromTestCase (   self,
  testCaseClass 
)
Return a suite of all tests cases contained in testCaseClass

Definition at line 409 of file unittest.py.

References TestLoader.getTestCaseNames(), and TestLoader.suiteClass.

410  def loadTestsFromTestCase(self, testCaseClass):
411  """Return a suite of all tests cases contained in testCaseClass"""
412  return self.suiteClass(map(testCaseClass,
413  self.getTestCaseNames(testCaseClass)))

Field Documentation

sortTestMethodsUsing = cmp
static

Definition at line 406 of file unittest.py.

suiteClass = TestSuite
static

Definition at line 407 of file unittest.py.

string testMethodPrefix = 'test'
static

Definition at line 405 of file unittest.py.


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