| |
- __builtin__.object
-
- TestCase
-
- FunctionTestCase
- TestLoader
- TestProgram
- TestProgram
- TestResult
- TestSuite
- TextTestRunner
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. |
|
- Method resolution order:
- FunctionTestCase
- TestCase
- __builtin__.object
Methods defined here:
- __init__(self, testFunc, setUp=None, tearDown=None, description=None)
- __repr__(self)
- __str__(self)
- id(self)
- runTest(self)
- setUp(self)
- shortDescription(self)
- tearDown(self)
Methods inherited from TestCase:
- __call__(self, result=None)
- assertAlmostEqual = failUnlessAlmostEqual(self, first, second, places=7, msg=None)
- Fail if the two objects are unequal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
Note that decimal places (from zero) is usually not the same
as significant digits (measured from the most signficant digit).
- assertAlmostEquals = failUnlessAlmostEqual(self, first, second, places=7, msg=None)
- Fail if the two objects are unequal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
Note that decimal places (from zero) is usually not the same
as significant digits (measured from the most signficant digit).
- assertEqual = failUnlessEqual(self, first, second, msg=None)
- Fail if the two objects are unequal as determined by the '=='
operator.
- assertEquals = failUnlessEqual(self, first, second, msg=None)
- Fail if the two objects are unequal as determined by the '=='
operator.
- assertNotAlmostEqual = failIfAlmostEqual(self, first, second, places=7, msg=None)
- Fail if the two objects are equal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
Note that decimal places (from zero) is usually not the same
as significant digits (measured from the most signficant digit).
- assertNotAlmostEquals = failIfAlmostEqual(self, first, second, places=7, msg=None)
- Fail if the two objects are equal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
Note that decimal places (from zero) is usually not the same
as significant digits (measured from the most signficant digit).
- assertNotEqual = failIfEqual(self, first, second, msg=None)
- Fail if the two objects are equal as determined by the '=='
operator.
- assertNotEquals = failIfEqual(self, first, second, msg=None)
- Fail if the two objects are equal as determined by the '=='
operator.
- assertRaises = 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.
- assert_ = failUnless(self, expr, msg=None)
- Fail the test unless the expression is true.
- countTestCases(self)
- debug(self)
- Run the test without collecting errors in a TestResult
- defaultTestResult(self)
- fail(self, msg=None)
- Fail immediately, with the given message.
- failIf(self, expr, msg=None)
- Fail the test if the expression is true.
- failIfAlmostEqual(self, first, second, places=7, msg=None)
- Fail if the two objects are equal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
Note that decimal places (from zero) is usually not the same
as significant digits (measured from the most signficant digit).
- failIfEqual(self, first, second, msg=None)
- Fail if the two objects are equal as determined by the '=='
operator.
- failUnless(self, expr, msg=None)
- Fail the test unless the expression is true.
- failUnlessAlmostEqual(self, first, second, places=7, msg=None)
- Fail if the two objects are unequal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
Note that decimal places (from zero) is usually not the same
as significant digits (measured from the most signficant digit).
- failUnlessEqual(self, first, second, msg=None)
- Fail if the two objects are unequal as determined by the '=='
operator.
- 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.
- run(self, result=None)
Data and other attributes inherited from TestCase:
- __dict__ = <dictproxy object>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of 'TestCase' objects>
- list of weak references to the object (if defined)
- failureException = <class exceptions.AssertionError>
- Assertion failed.
|
class TestCase(__builtin__.object) |
|
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. |
|
Methods defined here:
- __call__(self, result=None)
- __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)
- __str__(self)
- assertAlmostEqual = failUnlessAlmostEqual(self, first, second, places=7, msg=None)
- assertAlmostEquals = failUnlessAlmostEqual(self, first, second, places=7, msg=None)
- assertEqual = failUnlessEqual(self, first, second, msg=None)
- assertEquals = failUnlessEqual(self, first, second, msg=None)
- assertNotAlmostEqual = failIfAlmostEqual(self, first, second, places=7, msg=None)
- assertNotAlmostEquals = failIfAlmostEqual(self, first, second, places=7, msg=None)
- assertNotEqual = failIfEqual(self, first, second, msg=None)
- assertNotEquals = failIfEqual(self, first, second, msg=None)
- assertRaises = failUnlessRaises(self, excClass, callableObj, *args, **kwargs)
- assert_ = failUnless(self, expr, msg=None)
- countTestCases(self)
- debug(self)
- Run the test without collecting errors in a TestResult
- defaultTestResult(self)
- fail(self, msg=None)
- Fail immediately, with the given message.
- failIf(self, expr, msg=None)
- Fail the test if the expression is true.
- failIfAlmostEqual(self, first, second, places=7, msg=None)
- Fail if the two objects are equal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
Note that decimal places (from zero) is usually not the same
as significant digits (measured from the most signficant digit).
- failIfEqual(self, first, second, msg=None)
- Fail if the two objects are equal as determined by the '=='
operator.
- failUnless(self, expr, msg=None)
- Fail the test unless the expression is true.
- failUnlessAlmostEqual(self, first, second, places=7, msg=None)
- Fail if the two objects are unequal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
Note that decimal places (from zero) is usually not the same
as significant digits (measured from the most signficant digit).
- failUnlessEqual(self, first, second, msg=None)
- Fail if the two objects are unequal as determined by the '=='
operator.
- 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.
- id(self)
- run(self, result=None)
- 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.
Data and other attributes defined here:
- __dict__ = <dictproxy object>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of 'TestCase' objects>
- list of weak references to the object (if defined)
- failureException = <class exceptions.AssertionError>
- Assertion failed.
|
class TestLoader(__builtin__.object) |
|
This class is responsible for loading tests according to various
criteria and returning them wrapped in a Test |
|
Methods defined here:
- getTestCaseNames(self, testCaseClass)
- Return a sorted sequence of method names found within testCaseClass
- loadTestsFromModule(self, module)
- Return a suite of all tests cases contained in the given module
- 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.
- loadTestsFromNames(self, names, module=None)
- Return a suite of all tests cases found using the given sequence
of string specifiers. See 'loadTestsFromName()'.
- loadTestsFromTestCase(self, testCaseClass)
- Return a suite of all tests cases contained in testCaseClass
Data and other attributes defined here:
- __dict__ = <dictproxy object>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of 'TestLoader' objects>
- list of weak references to the object (if defined)
- sortTestMethodsUsing = <built-in function cmp>
- cmp(x, y) -> integer
Return negative if x<y, zero if x==y, positive if x>y.
- suiteClass = <class 'unittest.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.
- testMethodPrefix = 'test'
|
class TestProgram(__builtin__.object) |
|
A command-line program that runs a set of tests; this is primarily
for making test modules conveniently executable. |
|
Methods defined here:
- __init__(self, module='__main__', defaultTest=None, argv=None, testRunner=None, testLoader=<unittest.TestLoader object>)
- createTests(self)
- parseArgs(self, argv)
- runTests(self)
- usageExit(self, msg=None)
Data and other attributes defined here:
- USAGE = 'Usage: %(progName)s [options] [test] [...]\n\nOpti... in MyTestCase\n'
- __dict__ = <dictproxy object>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of 'TestProgram' objects>
- list of weak references to the object (if defined)
|
class TestResult(__builtin__.object) |
|
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 the
formatted traceback of the error that occurred. |
|
Methods defined here:
- __init__(self)
- __repr__(self)
- addError(self, test, err)
- Called when an error has occurred. 'err' is a tuple of values as
returned by sys.exc_info().
- addFailure(self, test, err)
- Called when an error has occurred. 'err' is a tuple of values as
returned by sys.exc_info().
- addSuccess(self, test)
- Called when a test has completed successfully
- 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
Data and other attributes defined here:
- __dict__ = <dictproxy object>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of 'TestResult' objects>
- list of weak references to the object (if defined)
|
class TestSuite(__builtin__.object) |
|
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. |
|
Methods defined here:
- __call__(self, result)
- __init__(self, tests=())
- __repr__(self)
- __str__ = __repr__(self)
- addTest(self, test)
- addTests(self, tests)
- countTestCases(self)
- debug(self)
- Run the tests without collecting errors in a TestResult
- run(self, result)
Data and other attributes defined here:
- __dict__ = <dictproxy object>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of 'TestSuite' objects>
- list of weak references to the object (if defined)
|
class TextTestRunner(__builtin__.object) |
|
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. |
|
Methods defined here:
- __init__(self, stream=<open file '<stderr>', mode 'w'>, descriptions=1, verbosity=1)
- run(self, test)
- Run the given test case or test suite.
Data and other attributes defined here:
- __dict__ = <dictproxy object>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of 'TextTestRunner' objects>
- list of weak references to the object (if defined)
|
main = class TestProgram(__builtin__.object) |
|
A command-line program that runs a set of tests; this is primarily
for making test modules conveniently executable. |
|
Methods defined here:
- __init__(self, module='__main__', defaultTest=None, argv=None, testRunner=None, testLoader=<unittest.TestLoader object>)
- createTests(self)
- parseArgs(self, argv)
- runTests(self)
- usageExit(self, msg=None)
Data and other attributes defined here:
- USAGE = 'Usage: %(progName)s [options] [test] [...]\n\nOpti... in MyTestCase\n'
- __dict__ = <dictproxy object>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of 'TestProgram' objects>
- list of weak references to the object (if defined)
| |