Go to the latest version of this document.
search in docstrings

Search bar offers the following options:

- Term presence. The below example searches for documents that must contain “foo”, might contain “bar” and must not contain “baz”: `+foo bar -baz`
- Wildcards. The below example searches for documents with words beginning with “foo”: `foo*`
- Search in specific fields. The following search matches all objects in "twisted.mail" that matches “search”: `+qname:twisted.mail.* +search`

  Possible fields: 'name', 'qname' (fully qualified name), 'docstring', and 'kind'. Last two fields are only applicable if "search in docstrings" is enabled.

- Fuzzy matches. The following search matches all documents that have a word within 1 edit distance of “foo”: `foo~1`

Results provided by Lunr.js

# ``twisted`.`trial`.`_synctest`.`_Assertions``

class documentation

`class _Assertions(pyunit.TestCase): (source)`

Known subclasses: `twisted.trial.unittest.SynchronousTestCase`

View In Hierarchy

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

Method | `assertAlmostEqual` | 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 | `assertApproximates` | Fail if `first` - `second` > `tolerance`
Method | `assertEqual` | Fail the test if `first` and `second` are not equal.
Method | `assertFalse` | Fail the test if `condition` evaluates to True.
Method | `assertIn` | Fail the test if `containee` is not found in `container`.
Method | `assertIs` | Fail the test if `first` is not `second`. This is an obect-identity-equality test, not an object equality (i.e. `__eq__`) test.
Method | `assertIsInstance` | Fail if `instance` is not an instance of the given class or of one of the given classes.
Method | `assertIsNot` | Fail the test if `first` is `second`. This is an obect-identity-equality test, not an object equality (i.e. `__eq__`) test.
Method | `assertNoResult` | Assert that `deferred` does not have a result at this point.
Method | `assertNotAlmostEqual` | 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 | `assertNotEqual` | Fail the test if `first` == `second`.
Method | `assertNotIn` | Fail the test if `containee` is found in `container`.
Method | `assertNotIsInstance` | Fail if `instance` is an instance of the given class or of one of the given classes.
Method | `assertNotSubstring` | Fail if `astring` contains `substring`.
Method | `assertRaises` | Fail 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 | `assertSubstring` | Fail if `substring` does not exist within `astring`.
Method | `assertTrue` | Fail the test if `condition` evaluates to False.
Method | `assertWarns` | 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 | `fail` | Absolutely fail the test. Do not pass go, do not collect $200.
Method | `failureResultOf` | Return the current failure result of `deferred` or raise `self.failureException`.
Method | `successResultOf` | Return the current success result of `deferred` or raise `self.failureException`.

def assertAlmostEqual(self, first, second, places=7, msg=None, delta=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.

Notes
decimal places (from zero) is usually not the same as significant digits (measured from the most significant digit).
included for compatibility with PyUnit test cases

def assertApproximates(self, first, second, tolerance, msg=None): (source)

Fail if `first` - `second` > `tolerance`

Parameters
first | Undocumented
second | Undocumented
tolerance | Undocumented
msg | if msg is None, then the failure message will be '%r ~== %r' % (first, second)

def assertEqual(self, first, second, msg=None): (source)

Fail the test if `first` and `second` are not equal.

Parameters
first | Undocumented
second | Undocumented
msg | A string describing the failure that's included in the exception.

def assertFalse(self, condition, msg=None): (source)

Fail the test if `condition` evaluates to True.

Parameters
condition | any object that defines __nonzero__
msg | Undocumented

def assertIn(self, containee, container, msg=None): (source)

Fail the test if `containee` is not found in `container`.

Parameters
containee | the value that should be in `container`
container | a sequence type, or in the case of a mapping type, will follow semantics of 'if key in dict.keys()'
msg | if msg is None, then the failure message will be '%r not in %r' % (first, second)

def assertIs(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.

Parameters
first | Undocumented
second | Undocumented
msg | if msg is None, then the failure message will be '%r is not %r' % (first, second)

def assertIsInstance(self, instance, classOrTuple, message=None): (source)

Fail if `instance` is not an instance of the given class or of one of the given classes.

Parameters
instance:any. | the object to test the type (first argument of the `isinstance` call).
classOrTuple:class, type, or tuple. | the class or classes to test against (second argument of the `isinstance` call).
message | Custom text to include in the exception text if the assertion fails.

def assertIsNot(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.

Parameters
first | Undocumented
second | Undocumented
msg | if msg is None, then the failure message will be '%r is %r' % (first, second)

def assertNoResult(self, deferred): (source)

Assert that `deferred` does not have a result at this point.

If the assertion succeeds, then the result of `deferred` is left unchanged. Otherwise, any `failure.Failure` result is swallowed.

Parameters
deferred:`Deferred` | A `Deferred` without a result. This means that neither `Deferred.callback` nor `Deferred.errback` has been called, or that the `Deferred` is waiting on another `Deferred` for a result.
Raises
`SynchronousTestCase.failureException` | If the `Deferred` has a result.

def assertNotAlmostEqual(self, first, second, places=7, msg=None, delta=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.

Notes
decimal places (from zero) is usually not the same as significant digits (measured from the most significant digit).
included for compatibility with PyUnit test cases

def assertNotEqual(self, first, second, msg=None): (source)

Fail the test if `first` == `second`.

Parameters
first | Undocumented
second | Undocumented
msg | if msg is None, then the failure message will be '%r == %r' % (first, second)

def assertNotIn(self, containee, container, msg=None): (source)

Fail the test if `containee` is found in `container`.

Parameters
containee | the value that should not be in `container`
container | a sequence type, or in the case of a mapping type, will follow semantics of 'if key in dict.keys()'
msg | if msg is None, then the failure message will be '%r in %r' % (first, second)

def assertNotIsInstance(self, instance, classOrTuple): (source)

Fail if `instance` is an instance of the given class or of one of the given classes.

Parameters
instance:any. | the object to test the type (first argument of the `isinstance` call).
classOrTuple:class, type, or tuple. | the class or classes to test against (second argument of the `isinstance` call).

def assertNotSubstring(self, substring, astring, msg=None): (source)

Fail if `astring` contains `substring`.

def assertRaises(self, exception, f=None, *args, **kwargs): (source)

Fail 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.

Parameters
exception | exception type that is to be expected
f | the function to call
*args | Undocumented
**kwargs | Undocumented
Returns
If `f` is `None`, a context manager which will make an assertion about the exception raised from the suite it manages. If `f` is not `None`, the exception raised by `f`.
Raises
`self.failureException` | Raised if the function call does not raise an exception or if it raises an exception of a different type.

def assertSubstring(self, substring, astring, msg=None): (source)

Fail if `substring` does not exist within `astring`.

def assertTrue(self, condition, msg=None): (source)

Fail the test if `condition` evaluates to False.

Parameters
condition | any object that defines __nonzero__
msg | Undocumented

def assertWarns(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.

Parameters
category | the category of the warning to check.
message | the output message of the warning to check.
filename | the filename where the warning should come from.
f:any callable. | the function which is supposed to generate the warning.
*args | the arguments to `f`.
**kwargs | the keywords arguments to `f`.
Returns
the result of the original function `f`.

def fail(self, msg=None): (source)

Absolutely fail the test. Do not pass go, do not collect $200.

Parameters
msg | the message that will be displayed as the reason for the failure

def failureResultOf(self, deferred, *expectedExceptionTypes): (source)

Return the current failure result of `deferred` or raise `self.failureException`.

Parameters
deferred:`Deferred` | A `Deferred` which has a failure result. This means `Deferred.callback` or `Deferred.errback` has been called on it and it has reached the end of its callback chain and the last callback or errback raised an exception or returned a `failure.Failure`.
*expectedExceptionTypes | Exception types to expect - if provided, and the exception wrapped by the failure result is not one of the types provided, then this test will fail.
Returns
`failure.Failure` | The failure result of `deferred`.
Raises
`SynchronousTestCase.failureException` | If the `Deferred` has no result, has a success result, or has an unexpected failure result.

def successResultOf(self, deferred): (source)

Return the current success result of `deferred` or raise `self.failureException`.

Parameters
deferred:`Deferred` | A `Deferred` which has a success result. This means `Deferred.callback` or `Deferred.errback` has been called on it and it has reached the end of its callback chain and the last callback or errback returned a non-`failure.Failure`.
Returns
The result of `deferred`.
Raises
`SynchronousTestCase.failureException` | If the `Deferred` has no result or has a failure result.