t.t.u._Assertions(pyunit.TestCase, object) : class documentation

Part of twisted.trial.unittest View Source View In Hierarchy

Known subclasses: twisted.trial.unittest.TestCase

Replaces many of the built-in TestCase assertions. In general, these assertions provide better error messages and are easier to use in callbacks. Also provides new assertions such as failUnlessFailure.

Although the tests are defined as 'failIf*' and 'failUnless*', they can also be called as 'assertNot*' and 'assert*'.
Method fail absolutely fails the test, do not pass go, do not collect $200
Method failIf fails the test if condition evaluates to False
Method failUnless fails the test if condition evaluates to True
Method failUnlessRaises fails the test unless calling the function f with the given args and kwargs raises exception. The failure will report the traceback and call stack of the unexpected exception.
Method failUnlessEqual Fail the test if first and second are not equal.
Method failUnlessIdentical fail the test if first is not second. This is an obect-identity-equality test, not an object equality (i.e. __eq__) test
Method failIfIdentical fail the test if first is second. This is an obect-identity-equality test, not an object equality (i.e. __eq__) test
Method failIfEqual fail the test if first == second
Method failUnlessIn fail the test if containee is not found in container
Method failIfIn fail the test if containee is found in container
Method failIfAlmostEqual 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.
Method failUnlessAlmostEqual 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.
Method failUnlessApproximates asserts that first - second > tolerance
Method failUnlessFailure Assert that deferred will errback with one of expectedFailures. Returns the original Deferred with callbacks added. You will need to return this Deferred from your test case.
Method failUnlessSubstring Undocumented
Method failIfSubstring Undocumented
Method failUnlessWarns Fail if the given function doesn't generate the specified warning when called. It calls the function, checks the warning, and forwards the result of the function if everything is fine.
Method failUnlessIsInstance Assert that the given instance is of the given class or of one of the given classes.
Method failIfIsInstance Assert that the given instance is not of the given class or of one of the given classes.
def fail(self, msg=None): (source)
absolutely fails the test, do not pass go, do not collect $200
Parametersmsgthe message that will be displayed as the reason for the failure
def failIf(self, condition, msg=None): (source)
fails the test if condition evaluates to False
Parametersconditionany object that defines __nonzero__
def failUnless(self, condition, msg=None): (source)
fails the test if condition evaluates to True
Parametersconditionany object that defines __nonzero__
def failUnlessRaises(self, exception, f, *args, **kwargs): (source)
fails the test unless calling the function f with the given args and kwargs raises exception. The failure will report the traceback and call stack of the unexpected exception.
Parametersexceptionexception type that is to be expected
fthe function to call
ReturnsThe raised exception instance, if it is of the given type.
Raisesself.failureExceptionRaised if the function call does not raise an exception or if it raises an exception of a different type.
def failUnlessEqual(self, first, second, msg=''): (source)
Fail the test if first and second are not equal.
ParametersmsgA string describing the failure that's included in the exception.
def failUnlessIdentical(self, first, second, msg=None): (source)
fail the test if first is not second. This is an obect-identity-equality test, not an object equality (i.e. __eq__) test
Parametersmsgif msg is None, then the failure message will be '%r is not %r' % (first, second)
def failIfIdentical(self, first, second, msg=None): (source)
fail the test if first is second. This is an obect-identity-equality test, not an object equality (i.e. __eq__) test
Parametersmsgif msg is None, then the failure message will be '%r is %r' % (first, second)
def failIfEqual(self, first, second, msg=None): (source)
fail the test if first == second
Parametersmsgif msg is None, then the failure message will be '%r == %r' % (first, second)
def failUnlessIn(self, containee, container, msg=None): (source)
fail the test if containee is not found in container
Parameterscontaineethe value that should be in container
containera sequence type, or in the case of a mapping type, will follow semantics of 'if key in dict.keys()'
msgif msg is None, then the failure message will be '%r not in %r' % (first, second)
def failIfIn(self, containee, container, msg=None): (source)
fail the test if containee is found in container
Parameterscontaineethe value that should not be in container
containera sequence type, or in the case of a mapping type, will follow semantics of 'if key in dict.keys()'
msgif msg is None, then the failure message will be '%r in %r' % (first, second)
def failIfAlmostEqual(self, first, second, places=7, msg=None): (source)
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.
Notesdecimal places (from zero) is usually not the same as significant digits (measured from the most signficant digit).
included for compatiblity with PyUnit test cases
def failUnlessAlmostEqual(self, first, second, places=7, msg=None): (source)
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.
Notesdecimal places (from zero) is usually not the same as significant digits (measured from the most signficant digit).
included for compatiblity with PyUnit test cases
def failUnlessApproximates(self, first, second, tolerance, msg=None): (source)
asserts that first - second > tolerance
Parametersmsgif msg is None, then the failure message will be '%r ~== %r' % (first, second)
def failUnlessFailure(self, deferred, *expectedFailures): (source)
Assert that deferred will errback with one of expectedFailures. Returns the original Deferred with callbacks added. You will need to return this Deferred from your test case.
def failUnlessSubstring(self, substring, astring, msg=None): (source)
Undocumented
def failIfSubstring(self, substring, astring, msg=None): (source)
Undocumented
def failUnlessWarns(self, category, message, filename, f, *args, **kwargs): (source)
Fail if the given function doesn't generate the specified warning when called. It calls the function, checks the warning, and forwards the result of the function if everything is fine.
Parameterscategorythe category of the warning to check.
messagethe output message of the warning to check.
filenamethe filename where the warning should come from.
fthe function which is supposed to generate the warning. (type: any callable. )
argsthe arguments to f.
kwargsthe keywords arguments to f.
Returnsthe result of the original function f.
def failUnlessIsInstance(self, instance, classOrTuple): (source)
Assert that the given instance is of the given class or of one of the given classes.
Parametersinstancethe object to test the type (first argument of the isinstance call). (type: any. )
classOrTuplethe class or classes to test against (second argument of the isinstance call). (type: class, type, or tuple. )
def failIfIsInstance(self, instance, classOrTuple): (source)
Assert that the given instance is not of the given class or of one of the given classes.
Parametersinstancethe object to test the type (first argument of the isinstance call). (type: any. )
classOrTuplethe class or classes to test against (second argument of the isinstance call). (type: class, type, or tuple. )
API Documentation for Twisted, generated by pydoctor at 2011-10-27 15:57:47.