unittest (version: 1.20)
 


Python unit testing framework, based on Erich Gamma's JUnit and Kent Beck's
Smalltalk testing framework.
 
Further information is available in the bundled documentation, and from
 
  http://pyunit.sourceforge.net/
 
This module contains the core framework classes that form the basis of
specific test cases and suites (TestCaseTestSuite etc.), and also a
text-based utility class for running the tests and reporting the results
(TextTestRunner).
 
Copyright (c) 1999, 2000, 2001 Steve Purcell
This module is free software, and you may redistribute it and/or modify
it under the same terms as Python itself, so long as this copyright message
and disclaimer are retained in their original form.
 
IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
 
THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE.  THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS,
AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.


 Modules
                                                                                                                                                                                                                               
os
string
sys
time
traceback


 Classes
                                                                                                                                                                                                                               
JUnitTextTestRunner
TestCase
FunctionTestCase
TestProgram
TestResult
_JUnitTextTestResult
_VerboseTextTestResult
TestSuite
VerboseTextTestRunner
_WritelnDecorator


 class FunctionTestCase(TestCase)
           A test case that wraps a test function.
 
This is useful for slipping pre-existing test functions into the
PyUnit framework. Optionally, set-up and tidy-up functions can be
supplied. As with TestCase, the tidy-up ('tearDown') function will
always be called if the set-up ('setUp') function ran successfully.
 
                                                                                                                                                                                                                     
__init__(self, testFunc, setUp=None, tearDown=None, description=None)
no doc string
__repr__(self)
no doc string
__str__(self)
no doc string
id(self)
no doc string
runTest(self)
no doc string
setUp(self)
no doc string
shortDescription(self)
no doc string
tearDown(self)
no doc string


 class JUnitTextTestRunner
           A test runner class that displays results in textual form.
 
The display format approximates that of JUnit's 'textui' test runner.
This test runner may be removed in a future version of PyUnit.
 
                                                                                                                                                                                                                     
__init__(self, stream=<open file '<stderr>', mode 'w' at 804ac88>)
no doc string
run(self, test)
Run the given test case or test suite.


 class TestCase
           A class whose instances are single test cases.
 
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.
 
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.
 
                                                                                                                                                                                                                     
__exc_info(self)
Return a version of sys.exc_info() with the traceback frame
minimised; usually the top level of the traceback frame is not
needed.
__call__(self, result=None)
no doc string
__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.
__repr__(self)
no doc string
__str__(self)
no doc string
assertRaises(self, excClass, callableObj, *args, **kwargs)
Assert that 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.
assert_(self, expr, msg=None)
Equivalent of built-in 'assert', but is not optimised out when
__debug__ is false.
countTestCases(self)
no doc string
defaultTestResult(self)
no doc string
fail(self, msg=None)
Fail immediately, with the given message.
failIf(self, expr, msg=None)
Fail the test if the expression is true.
assert_(self, expr, msg=None)
Equivalent of built-in 'assert', but is not optimised out when
__debug__ is false.
id(self)
no doc string
run(self, result=None)
no doc string
setUp(self)
Hook method for setting up the test fixture before exercising it.
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.
tearDown(self)
Hook method for deconstructing the test fixture after testing it.


 class TestProgram
           A command-line program that runs a set of tests; this is primarily
for making test modules conveniently executable.
 
                                                                                                                                                                                                                     
__init__(self, module='__main__', defaultTest=None, argv=None, testRunner=None)
no doc string
createTests(self)
no doc string
parseArgs(self, argv)
no doc string
runTests(self)
no doc string
usageExit(self, msg=None)
no doc string


 class TestResult
           Holder for test result information.
 
Test results are automatically managed by the TestCase and TestSuite
classes, and do not need to be explicitly manipulated by writers of tests.
 
Each instance holds the total number of tests run, and collections of
failures and errors that occurred among those test runs. The collections
contain tuples of (testcase, exceptioninfo), where exceptioninfo is a
tuple of values as returned by sys.exc_info().
 
                                                                                                                                                                                                                     
__init__(self)
no doc string
__repr__(self)
no doc string
addError(self, test, err)
Called when an error has occurred
addFailure(self, test, err)
Called when a failure has occurred
startTest(self, test)
Called when the given test is about to be run
stop(self)
Indicates that the tests should be aborted
stopTest(self, test)
Called when the given test has been run
wasSuccessful(self)
Tells whether or not this result was a success


 class TestSuite
           A test suite is a composite test consisting of a number of TestCases.
 
For use, create an instance of TestSuite, then add test case instances.
When all tests have been added, the suite can be passed to a test
runner, such as TextTestRunner. It will run the individual test cases
in the order in which they were added, aggregating the results. When
subclassing, do not forget to call the base class constructor.
 
                                                                                                                                                                                                                     
__call__(self, result)
no doc string
__init__(self, tests=())
no doc string
__repr__(self)
no doc string
__repr__(self)
no doc string
addTest(self, test)
no doc string
addTests(self, tests)
no doc string
countTestCases(self)
no doc string
run(self, result)
no doc string


 class VerboseTextTestRunner
           A test runner class that displays results in textual form.
 
It prints out the names of tests as they are run, errors as they
occur, and a summary of the results at the end of the test run.
 
                                                                                                                                                                                                                     
__init__(self, stream=<open file '<stderr>', mode 'w' at 804ac88>, descriptions=1)
no doc string
run(self, test)
Run the given test case or test suite.


 class VerboseTextTestRunner
           A test runner class that displays results in textual form.
 
It prints out the names of tests as they are run, errors as they
occur, and a summary of the results at the end of the test run.
 
                                                                                                                                                                                                                     
__init__(self, stream=<open file '<stderr>', mode 'w' at 804ac88>, descriptions=1)
no doc string
run(self, test)
Run the given test case or test suite.


 class _JUnitTextTestResult(TestResult)
           A test result class that can print formatted text results to a stream.
 
Used by JUnitTextTestRunner.
 
                                                                                                                                                                                                                     
__init__(self, stream)
no doc string
addError(self, test, error)
no doc string
addFailure(self, test, error)
no doc string
printErrors(self)
no doc string
printFailures(self)
no doc string
printHeader(self)
no doc string
printNumberedErrors(self, errFlavour, errors)
no doc string
printResult(self)
no doc string
startTest(self, test)
no doc string


 class _VerboseTextTestResult(TestResult)
           A test result class that can print formatted text results to a stream.
 
Used by VerboseTextTestRunner.
 
                                                                                                                                                                                                                     
__init__(self, stream, descriptions)
no doc string
_printError(self, flavour, test, err)
no doc string
addError(self, test, err)
no doc string
addFailure(self, test, err)
no doc string
startTest(self, test)
no doc string
stopTest(self, test)
no doc string


 class _WritelnDecorator
           Used to decorate file-like objects with a handy 'writeln' method
 
                                                                                                                                                                                                                     
__getattr__(self, attr)
no doc string
__init__(self, stream)
no doc string
writeln(self, *args)
no doc string


 class TestProgram
           A command-line program that runs a set of tests; this is primarily
for making test modules conveniently executable.
 
                                                                                                                                                                                                                     
__init__(self, module='__main__', defaultTest=None, argv=None, testRunner=None)
no doc string
createTests(self)
no doc string
parseArgs(self, argv)
no doc string
runTests(self)
no doc string
usageExit(self, msg=None)
no doc string


 Functions
                                                                                                                                                                                                                               
createTestInstance(name, module=None)
Finds tests by their name, optionally only within the given module.
 
Return the newly-constructed test, ready to run. If the name contains a ':'
then the portion of the name after the colon is used to find a specific
test case within the test case class named before the colon.
 
Examples:
 findTest('examples.listtests.suite')
    -- returns result of calling 'suite'
 findTest('examples.listtests.ListTestCase:checkAppend')
    -- returns result of calling ListTestCase('checkAppend')
 findTest('examples.listtests.ListTestCase:check-')
    -- returns result of calling makeSuite(ListTestCase, prefix="check")
getTestCaseNames(testCaseClass, prefix, sortUsing=<built-in function cmp>)
Extracts all the names of functions in the given test case class
and its base classes that start with the given prefix. This is used
by makeSuite().
makeSuite(testCaseClass, prefix='test', sortUsing=<built-in function cmp>)
Returns a TestSuite instance built from all of the test functions
in the given test case class whose names begin with the given
prefix. The cases are sorted by their function names
using the supplied comparison function, which defaults to 'cmp'.