开发者

What does this error mean?

开发者 https://www.devze.com 2023-02-10 14:35 出处:网络
what does this error mean?? Ran 1 test in 0.002s FAILED (failures=1) ankit@ubuntu:~/Desktop$ python binary_light.py

what does this error mean??

Ran 1 test in 0.002s

FAILED (failures=1)
ankit@ubuntu:~/Desktop$ python binary_light.py
Light switched  None
F
======================================================================
FAIL: testOne (__main__.IsOddTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "binary_light.py", line 54, in testOne
    self.failUnless(b1.SetTarget(NewTargetValue = 'something'))
AssertionError

The Code is:

from brisa.core.reactors import install_default_reactor
reactor = install_default_reactor()

import os
import unittest
from brisa.upnp.device import Device, Service

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(unittest.TestCase):

    def testOne(self):
        b1 = SwitchPower()
        self.failUnless(b1.SetTarget(NewTargetValue = 'something'))



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



if __name__ == '__main__':
    device = BinaryLight()
    device += BinaryLight()
    device.start()
    reactor.add_after_stop_func(device.stop)
    r开发者_如何学运维eactor.main()

Error:

ankit@ubuntu:~/Desktop$ python binary_light.py
E
======================================================================
ERROR: testOne (__main__.IsOddTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "binary_light.py", line 54, in testOne
    self.failUnless(b1.SetTarget()=={})
  File "binary_light.py", line 25, in SetTarget
    self.target = kwargs['NewTargetValue']
KeyError: 'NewTargetValue'

----------------------------------------------------------------------
Ran 1 test in 0.002s

FAILED (errors=1)


An AssertionError is documented under http://docs.python.org/library/exceptions.html#exceptions.AssertionError:

Raised when an assert statement fails.

Your unittest is asserting that SetTarget will return something that is boolean True; however, your method is returning {}, which is equivalent to boolean False, causing the AssertionError. To fix this, either test if SetTarget has returned {} or change it to return something that will be interpreted as True.

If you're wondering why the device code is not working, it's because you're running your unittests before starting the device - and if a unittest fails, your script will stop there.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号