Error in running Test case
I changed the code and try to run the test case but still could get better situation. Please see the code and error and guide me in getting rid of it.
from brisa.core.reactors import install_default_reactor
reactor = install_default_reactor()
import os
import unittest
from brisa.upnp.device import Device, Service
from brisa.upnp.device.service import StateVariable
class SwitchPower(Service):
def __init__(self):
Service.__init__(self,
'SwitchPower',
'urn:schemas-upnp-org:service:SwitchPower:1',
'',
os.getcwd() + '/SwitchPower-scpd.xml')
self.target = False
self.status = False
def SetTarget(self, *args, **kwargs):
self.target = kwargs['NewTargetValue']
self.status = self.target
print 'Light switched ', {'1': 'on', '0': 'off'}.get(self.target, None)
return {}
def GetTarget(self, *args, **kwargs):
return {'RetTargetValue': self.target}
def soap_GetStatus(self, *args, **kwargs):
return {'ResultStatus': self.status}
class BinaryLight(Device):
def __init__(self):
Device.__init__(self,
'urn:schemas=upnp-org:device:BinaryLight:1',
'Binary Light Device')
# Here's our "unit tests".
class IsOddTests(unittes开发者_如何学Pythont.TestCase):
def testOne(self):
b1 = SwitchPower()
self.failUnless(b1.SetTarget('NewTargetValue'))
if __name__ == '__main__':
unittest.main()
if __name__ == '__main__':
device = BinaryLight()
device += BinaryLight()
device.start()
reactor.add_after_stop_func(device.stop)
reactor.main()
Error:
ERROR: testOne (__main__.IsOddTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "binary_light.py", line 54, in testOne
self.failUnless(b1.SetTarget('NewTargetValue'))
File "binary_light.py", line 25, in SetTarget
self.target = kwargs['NewTargetValue']
KeyError: 'NewTargetValue'
You're not passing in a keyword list into SetTarget
. Do it like:
self.failUnless(b1.SetTarget(NewTargetValue='something'))
Error with this:
Traceback (most recent call last):
File "binary_light.py", line 54, in testOne
self.failUnless(b1.SetTarget(NewTargetValue= 'something'))
AssertionError
精彩评论