[Tutor] Unexpected Behavior in unittest
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Tue Feb 28 23:56:54 CET 2006
> I wish it were that simple. 'test3.py' is the name of the file
> containing the test case class. I left the invocation out of my output
> excerpt. It should look like this:
Hi Barry,
Ok.
But still go back and make sure you're running the right file. The error
message says that:
> Traceback (most recent call last):
> File "J:\My Documents\Projects\Mongoose\symgen\test3.py", line 25, in
> test_cs
So Python's running a program that has at least 25 lines in it.
But the test3.py file you've shown us at the bottom of:
http://mail.python.org/pipermail/tutor/2006-February/045423.html
just simply doesn't have that many lines. Let's look again at the program
you're showing us as 'test3.py':
###########################################
#!/usr/bin/python2.3
from lblgen import *
import unittest
class cs_tryout(unittest.TestCase):
def test_cs(self):
lg = lblgen(t = 'Any string here')
msg = ('Generator cs is incorrect.\nExpected %3.1f; got %3.1f' %
(1.0, lg.cs))
self.assertEqual(1.0, lg.cs, msg)
lbl = lg.generate()
msg = 'txtlst entry %d is incorrect.\nExpected %3.1f; got %3.1f'
for ndx, got in enumerate(lbl.txtlst[lbl.chlen::lbl.chlen]):
self.assertEqual(1.0, got, msg % (ndx, 1.0, got))
lg.cs = 2.5
msg = ('Generator cs is incorrect.\nExpected %3.1f; got %3.1f' %
(2.5, lg.cs))
self.assertEqual(2.5, lg.cs, msg)
lbl = lg.generate()
msg = 'txtlst entry %d is incorrect.\nExpected %3.1f; got %3.1f'
for ndx, got in enumerate(lbl.txtlst[lbl.chlen::lbl.chlen]):
self.assertEqual(2.5, got, msg % (ndx, 2.5, got))
if __name__=='__main__':
unittest.main( )
###########################################
What you're showing us above --- what you think is test3.py --- and what
the error message is saying here:
#########################################################################
Traceback (most recent call last):
File "J:\My Documents\Projects\Mongoose\symgen\test3.py", line 25, in
test_cs
self.assertEqual(expect, lg.cs, msg)
File "C:\PROGRA~1\Python23\lib\unittest.py", line 302, in
failUnlessEqual
raise self.failureException, \
#########################################################################
presents two inconsistent views of what should be the same exact program.
We can look at this more closely: the error message has a reference to an
'expect' variable name, but this doesn't exist in the program you're
showing us. Python isn't magical, so I have to assume that some program,
different than the one you've shown us, is being executed.
Does this make sense?
More information about the Tutor
mailing list