[python-uk] Unit Testing Problem

Francis Moore Francis.Moore at shaws.co.uk
Fri Mar 26 08:07:57 EST 2004


Hi,

Trying to get my head around Unit Testing (and Python) and I've come
across a strange 
problem when adding some tests to the example from
pyunit-1.4.1\doc\PyUnit.html. 

class Widget:
    def __init__(self, widgetname, size=(50,50)):
        self.name = widgetname
        self._size = size
    def func(self):
        return 4
    def name(self):
        return self.name

class WidgetTestCase(unittest.TestCase):
    def setUp(self):
        self.widget = Widget("The widget")
    def testFunc(self):
        assert self.widget.func() == 3, 'Invalid value'
    def testName(self):
        assert self.widget.name() == "The widget", "Invalid name"

I'm getting the error "TypeError: 'str' object is not callable" when I
run my test suite. 
It's complaining about the last line of code. 
However, if I take the function call brackets off (assert
self.widget.name == "The widget", "Invalid name") 
it works fine. I expected it to work like the func() example above it.

I did a search on Google for the error string, which turned up a few
explanations but none which really 
helped. Can anyone explain what's happening?

Many thanks,
Francis.
 
CONFIDENTIALITY NOTICE

This communication contains information which is confidential and may
also be privileged. It is for the exclusive use of the intended
recipient(s). If you are not the intended recipient(s) please note that
any distribution, copying or use of this communication or the
information in it is strictly prohibited. If you have received this
communication in error please notify us by e-mail or by telephone
(+44(0) 1322 621100) and then delete the e-mail and any copies of it. 

This communication is from Shaw & Sons Limited whose registered office
is at Shaway House, 21 Bourne Park, Bourne Road, Crayford, Kent DA1 4BZ.
The views expressed in this communication may not be the views held by
Shaw & Sons Limited.

This message has been checked for all known viruses by McAfee VirusScan.




More information about the python-uk mailing list