Thanks a lot.
Sean Allen
On Tue, 2002-01-29 at 20:14, Changjune Kim wrote:
It's simple and easy.
--------
import unittest
class J:
def __init__(self,someArg1,someArg2):
if someArg1<0 or someArg2<0:
raise Exception
print "foobar!"
class TestJay(unittest.TestCase):
def testBounds(self):
self.assertRaises(Exception, J, -30, 20)
if __name__=3D=3D'__main__':
unittest.main()
---------
----- Original Message -----=20
From: "Sean Allen"=20
To: "PyUnit"=20
Sent: Wednesday, January 30, 2002 9:00 AM
Subject: [Pyunit-interest] Unit testing constructors
Hello, sorry if this has been covered before
Currently, I am trying to implement a test suite for some objects.
The objects need to do bounds checking based on arguments to their
__init__() ctor. If the object is given initialization parameters that
are out of bounds, an Exception must be thrown.
So far, So good.
I am having a great deal of difficulty trying to get a test case to work
that does something like
(pseudo code)
...
self.assertRaise(Exception, (attempt to create the object), (args))
...
which basically tells me I have to supply an instance of the object I'm
trying to create as first argument, which is not really possible under
these conditions. The code works well in interactive testing, it's just
how to write the unit test
Any ideas? =20
Sean Allen
|