failUnlessAssignRaises(testCase,
exception,
object,
property,
value)
| source code
|
Equivalent of failUnlessRaises , but used for property
assignments instead.
It's nice to be able to use failUnlessRaises to check
that a method call raises the exception that you expect. Unfortunately,
this method can't be used to check Python propery assignments, even
though these property assignments are actually implemented underneath as
methods.
This function (which can be easily called by unit test classes)
provides an easy way to wrap the assignment checks. It's not pretty, or
as intuitive as the original check it's modeled on, but it does work.
Let's assume you make this method call:
testCase.failUnlessAssignRaises(ValueError, collectDir, "absolutePath", absolutePath)
If you do this, a test case failure will be raised unless the
assignment:
collectDir.absolutePath = absolutePath
fails with a ValueError exception. The failure message
differentiates between the case where no exception was raised and the
case where the wrong exception was raised.
- Parameters:
testCase - PyUnit test case object (i.e. self).
exception - Exception that is expected to be raised.
object - Object whose property is to be assigned to.
property - Name of the property, as a string.
value - Value that is to be assigned to the property.
Note:
Internally, the missed and instead
variables are used rather than directly calling
testCase.fail upon noticing a problem because the act
of "failure" itself generates an exception that would be
caught by the general except clause.
See Also:
unittest.TestCase.failUnlessRaises
|