[Tutor] I don't get it

Magnus Lycka magnus@thinkware.se
Fri, 20 Sep 2002 22:12:48 +0200


At 11:47 2002-09-20 -0700, Sean 'Shaleh' Perry wrote:
>def div(top, bottom):
>     return top / bottom
>
>def test_div():
>     ret =3D div(0,1)
>     assert(ret =3D=3D 0)
>
>     try:
>         ret =3D div(1,0)
>     except:
>         pass
>     else:
>         assert(0) # should have thrown an exception
>
>     ret =3D div(4,2)
>     assert(ret =3D=3D 2)
>#end test_div

But with the unittest module you get some nice methods
that makes at least the exception test a bit shorter.
You can do things like

     ...
     self.assertRaises(ZeroDivisionError, div(1,0))
     ...




--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se