Unit test failing please help

lblake treleven.lloyd at gmail.com
Fri Aug 26 11:35:30 EDT 2011


Hi I am new to python I am at bit lost as to why my unit test is
failing below is the code and the unit test:

class Centipede(object):
    legs, stomach
    def __init__(self):


    def __str__(self):
        return ','.join(self.stomach)


    def __call__(self,*args):
        [self.stomach.append(arg) for arg in args]
        #self.stomach.append(args)

    def __repr__(self):
        return ','.join(self.legs)

      def __setattr__(self, key, value):
        print("setting %s to %s" % (key, repr(value)))
        if key in ([]):
            self.legs.append(key)
            super(Centipede, self).__setattr__(self, key,value)

unit test code:

import unittest
from centipede import Centipede

class TestBug(unittest.TestCase):

    def test_stomach(self):
        ralph = Centipede()
        ralph('chocolate')
        ralph('bbq')
        ralph('cookies')
        ralph('salad')
        self.assertEquals(ralph.__str__(),
'chocolate,bbq,cookies,salad')


    def test_legs(self):
        ralph = Centipede()
        ralph.friends = ['Steve', 'Daniel', 'Guido']
        ralph.favorite_show = "Monty Python's Flying Circus"
        ralph.age = '31'
 
self.assertEquals(ralph.__repr__(),'<friends,favorite_show,age>' )



if __name__ == "__main__":
    unittest.main()


error message generated when running the test:

AttributeError: 'Centipede' object has no attribute 'legs'

AttributeError: 'Centipede' object has no attribute 'stomach'

Any suggestions as to where I am going wrong?




More information about the Python-list mailing list