unittest assertRises question
Leazen
leazen at uol.com.ar
Fri Dec 27 17:01:40 EST 2002
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I'm using unittest and have a problem when trying to raise an
exception when creating an object.
What I understood from the traceback is that I should be giving one
more parameter in the last argument of assertRaises. Is it asking for
self? I don't get it. Could anyone please explain what's going on?
The following bit of code:
def testPriorities(self):
"""Priorities should be [0,2]."""
for i in range(-10, 0) + range(3, 10):
self.assertRaises(log.InvalidPriority, log.LogEvent, (i,
self.msg))
produces the following error:
======================================================================
ERROR: Priorities should be [0,2].
- ----------------------------------------------------------------------
Traceback (most recent call last):
File "E:\Trabajos\Sesamo\Admin-v4.0.0\logtest.py", line 25, in
testPriorities
self.assertRaises(log.InvalidPriority, log.LogEvent, (i, self.msg))
File "C:\Python22\lib\unittest.py", line 273, in failUnlessRaises
apply(callableObj, args, kwargs)
TypeError: __init__() takes at least 3 arguments (2 given)
LogEvent is:
class LogEvent:
def __init__(self, priority, msg, eventTime = None):
self.priority = priority
self.message = msg
if eventTime is None:
import time
self.time = time.time()
elif 0.0 <= eventTime:
self.time = eventTime
else:
raise InvalidTime, "The given time was invalid."
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE+DM2+hcKLjUu3XMkRAqMeAJ0WspOFtZnL3JcZiGxLRaLxhs2DeQCdHu+Y
Lzk7mBr2TPfHyf8u4WP89iU=
=Pl7F
-----END PGP SIGNATURE-----
More information about the Python-list
mailing list