How do I unit-test a specific case of a home-rolled exception ?
__peter__ at web.de
Fri Jun 27 13:33:32 CEST 2008
Ken Starks wrote:
> I have an exception class, and I want to check that
> a particular instance of it has been raised; or
> more accurately that one is raised that is equal to
> an instance I specify.
> In the example below, I can check that a
> 'LongRationalError' is raised, but I want
> to check that it is specifically a
> 'LongrationalError('1') or a 'LongRationalError('2')
> How do I do that?
except LongRationalError, e:
Alternatively you can subclass LongRationalError...
...and then check for the specialized exception:
self.assertRaises(LongRationalDenominatorError, LongRational, 1, "7")
Personally, I'd probably throw a plain old TypeError for incompatible types
of both numerator and denominator.
More information about the Python-list