Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
TestCase Class Reference
Inheritance diagram for TestCase:
FunctionTestCase

Public Member Functions

def __init__
 
def setUp
 
def tearDown
 
def countTestCases
 
def defaultTestResult
 
def shortDescription
 
def id
 
def __str__
 
def __repr__
 
def run
 
def __call__
 
def debug
 
def fail
 
def failIf
 
def failUnless
 
def failUnlessRaises
 
def failUnlessEqual
 
def failIfEqual
 

Static Public Attributes

 failureException = AssertionError
 
 assertEqual = failUnlessEqual
 
 assertNotEqual = failIfEqual
 
 assertRaises = failUnlessRaises
 
 assert_ = failUnless
 

Detailed Description

A class whose instances are single test cases.

By default, the test code itself should be placed in a method named
'runTest'.

If the fixture may be used for many test cases, create as
many test methods as are needed. When instantiating such a TestCase
subclass, specify in the constructor arguments the name of the test method
that the instance is to execute.

Test authors should subclass TestCase for their own tests. Construction
and deconstruction of the test's environment ('fixture') can be
implemented by overriding the 'setUp' and 'tearDown' methods respectively.

If it is necessary to override the __init__ method, the base class
__init__ method must always be called. It is important that subclasses
should not change the signature of their __init__ method, since instances
of the classes are instantiated automatically by parts of the framework
in order to be run.

Definition at line 120 of file unittest.py.

Constructor & Destructor Documentation

def __init__ (   self,
  methodName = 'runTest' 
)
Create an instance of the class that will use the named test
   method when executed. Raises a ValueError if the instance does
   not have a method with the specified name.

Definition at line 148 of file unittest.py.

References SymbolTable.__class__, TestCase.__testMethodDoc, and TestCase.__testMethodName.

149  def __init__(self, methodName='runTest'):
150  """Create an instance of the class that will use the named test
151  method when executed. Raises a ValueError if the instance does
152  not have a method with the specified name.
153  """
154  try:
155  self.__testMethodName = methodName
156  testMethod = getattr(self, methodName)
157  self.__testMethodDoc = testMethod.__doc__
158  except AttributeError:
159  raise ValueError, "no such test method in %s: %s" % \
160  (self.__class__, methodName)

Member Function Documentation

def __call__ (   self,
  result = None 
)

Definition at line 198 of file unittest.py.

References TestCase.__exc_info(), TestCase.__testMethodName, TestCase.defaultTestResult(), TestCase.failureException, TestCase.setUp(), and TestCase.tearDown().

199  def __call__(self, result=None):
200  if result is None: result = self.defaultTestResult()
201  result.startTest(self)
202  testMethod = getattr(self, self.__testMethodName)
203  try:
204  try:
205  self.setUp()
206  except KeyboardInterrupt:
207  raise
208  except:
209  result.addError(self, self.__exc_info())
210  return
211 
212  ok = 0
213  try:
214  testMethod()
215  ok = 1
216  except self.failureException, e:
217  result.addFailure(self, self.__exc_info())
218  except KeyboardInterrupt:
219  raise
220  except:
221  result.addError(self, self.__exc_info())
222 
223  try:
224  self.tearDown()
225  except KeyboardInterrupt:
226  raise
227  except:
228  result.addError(self, self.__exc_info())
229  ok = 0
230  if ok: result.addSuccess(self)
231  finally:
232  result.stopTest(self)
def __repr__ (   self)

Definition at line 191 of file unittest.py.

References SymbolTable.__class__, and TestCase.__testMethodName.

192  def __repr__(self):
193  return "<%s testMethod=%s>" % \
194  (self.__class__, self.__testMethodName)
def __str__ (   self)

Definition at line 188 of file unittest.py.

References SymbolTable.__class__, and TestCase.__testMethodName.

189  def __str__(self):
190  return "%s (%s)" % (self.__testMethodName, self.__class__)
def countTestCases (   self)

Definition at line 169 of file unittest.py.

170  def countTestCases(self):
171  return 1
def debug (   self)
Run the test without collecting errors in a TestResult

Definition at line 233 of file unittest.py.

References TestCase.__testMethodName, TestCase.setUp(), and TestCase.tearDown().

234  def debug(self):
235  """Run the test without collecting errors in a TestResult"""
236  self.setUp()
237  getattr(self, self.__testMethodName)()
238  self.tearDown()
def defaultTestResult (   self)

Definition at line 172 of file unittest.py.

173  def defaultTestResult(self):
174  return TestResult()
def fail (   self,
  msg = None 
)
Fail immediately, with the given message.

Definition at line 252 of file unittest.py.

References TestCase.failureException.

253  def fail(self, msg=None):
254  """Fail immediately, with the given message."""
255  raise self.failureException, msg
def failIf (   self,
  expr,
  msg = None 
)

Definition at line 256 of file unittest.py.

References TestCase.failureException.

257  def failIf(self, expr, msg=None):
258  "Fail the test if the expression is true."
259  if expr: raise self.failureException, msg
def failIfEqual (   self,
  first,
  second,
  msg = None 
)
Fail if the two objects are equal as determined by the '=='
   operator.

Definition at line 289 of file unittest.py.

References TestCase.failureException.

290  def failIfEqual(self, first, second, msg=None):
291  """Fail if the two objects are equal as determined by the '=='
292  operator.
293  """
294  if first == second:
295  raise self.failureException, \
296  (msg or '%s == %s' % (`first`, `second`))
def failUnless (   self,
  expr,
  msg = None 
)
Fail the test unless the expression is true.

Definition at line 260 of file unittest.py.

References TestCase.failureException.

261  def failUnless(self, expr, msg=None):
262  """Fail the test unless the expression is true."""
263  if not expr: raise self.failureException, msg
def failUnlessEqual (   self,
  first,
  second,
  msg = None 
)
Fail if the two objects are unequal as determined by the '!='
   operator.

Definition at line 281 of file unittest.py.

References TestCase.failureException.

282  def failUnlessEqual(self, first, second, msg=None):
283  """Fail if the two objects are unequal as determined by the '!='
284  operator.
285  """
286  if first != second:
287  raise self.failureException, \
288  (msg or '%s != %s' % (`first`, `second`))
def failUnlessRaises (   self,
  excClass,
  callableObj,
  args,
  kwargs 
)
Fail unless an exception of class excClass is thrown
   by callableObj when invoked with arguments args and keyword
   arguments kwargs. If a different type of exception is
   thrown, it will not be caught, and the test case will be
   deemed to have suffered an error, exactly as for an
   unexpected exception.

Definition at line 264 of file unittest.py.

References TestCase.failureException, and locale.str().

265  def failUnlessRaises(self, excClass, callableObj, *args, **kwargs):
266  """Fail unless an exception of class excClass is thrown
267  by callableObj when invoked with arguments args and keyword
268  arguments kwargs. If a different type of exception is
269  thrown, it will not be caught, and the test case will be
270  deemed to have suffered an error, exactly as for an
271  unexpected exception.
272  """
273  try:
274  apply(callableObj, args, kwargs)
275  except excClass:
276  return
277  else:
278  if hasattr(excClass,'__name__'): excName = excClass.__name__
279  else: excName = str(excClass)
280  raise self.failureException, excName
def id (   self)

Definition at line 185 of file unittest.py.

References SymbolTable.__class__, and TestCase.__testMethodName.

186  def id(self):
187  return "%s.%s" % (self.__class__, self.__testMethodName)
def run (   self,
  result = None 
)

Definition at line 195 of file unittest.py.

196  def run(self, result=None):
197  return self(result)
def setUp (   self)

Definition at line 161 of file unittest.py.

162  def setUp(self):
163  "Hook method for setting up the test fixture before exercising it."
164  pass
def shortDescription (   self)
Returns a one-line description of the test, or None if no
description has been provided.

The default implementation of this method returns the first line of
the specified test method's docstring.

Definition at line 175 of file unittest.py.

References TestCase.__testMethodDoc, string.split(), and string.strip().

176  def shortDescription(self):
177  """Returns a one-line description of the test, or None if no
178  description has been provided.
179 
180  The default implementation of this method returns the first line of
181  the specified test method's docstring.
182  """
183  doc = self.__testMethodDoc
184  return doc and string.strip(string.split(doc, "\n")[0]) or None
def tearDown (   self)

Definition at line 165 of file unittest.py.

166  def tearDown(self):
167  "Hook method for deconstructing the test fixture after testing it."
168  pass

Field Documentation

assert_ = failUnless
static

Definition at line 303 of file unittest.py.

assertEqual = failUnlessEqual
static

Definition at line 297 of file unittest.py.

assertNotEqual = failIfEqual
static

Definition at line 299 of file unittest.py.

assertRaises = failUnlessRaises
static

Definition at line 301 of file unittest.py.

failureException = AssertionError
static

Definition at line 146 of file unittest.py.


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