Error while running test case

2024/7/7 6:32:14

I need to test my code below. I am using one test to see if it is working or not. but dont know what exactly I should pass as a parameter in the test code. Please see the test code at the end and please guide me what value I should pass here? Because whatever I write here, it throws me an error.

from brisa.core.reactors import install_default_reactor
reactor = install_default_reactor()import os
import unittestfrom brisa.upnp.device import Device, Service
from brisa.upnp.device.service import StateVariableclass SwitchPower(Service):def __init__(self):Service.__init__(self,'SwitchPower','urn:schemas-upnp-org:service:SwitchPower:1','',os.getcwd() + '/SwitchPower-scpd.xml')self.target = Falseself.status = Falsedef SetTarget(self, *args, **kwargs):self.target = kwargs['NewTargetValue']self.status = self.targetself.set_state_variable('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(object):def __init__(self):self.server_name = 'Binary Light device'self.device = Nonedef _create_device(self):project_page = 'https://garage.maemo.org/projects/brisa'self.device = Device('urn:schemas=upnp-org:device:BinaryLight:1',self.server_name,manufacturer = 'Ankit',model_name = 'Binary Light Device',model_description = 'Test Device',model_number = '1.0',model_url=project_page)def _add_service(self):switch = SwitchPower()self.device.add_service(switch)def start(self):self._create_device()self._add_services()self.device.start()reactor.add_after_stop_func(self.device.stop)reactor.main()# Here's our "unit tests".class IsOddTests(unittest.TestCase):def testOne(self):self.failUnless(_create_device('urn:schemas=upnp-org:device:BinaryLight:1'))if __name__ == '__main__':unittest.main()      if __name__ == '__main__':device = BinaryLight()device.start()   Ran 1 test in 0.000s

The Error is:-

ERROR: testOne (__main__.IsOddTests)
----------------------------------------------------------------------
Traceback (most recent call last):File "binary_light.py", line 67, in testOneself.failUnless(_create_device('urn:schemas=upnp-org:device:BinaryLight:1'))
NameError: global name '_create_device' is not defined----------------------------------------------------------------------
Answer

In your testOne() method, you're calling _create_device(), which isn't a global function it's a method on SwitchPower objects.

You probably want to create a new SwitchPower object.

https://en.xdnf.cn/q/120154.html

Related Q&A

How to run something on each line of txt file?

I am trying to get this to run on each line of a .txt file.D1 =int(lines[0])*10 D2 =int(lines[1])*9 D3 =int(lines[2])*8 D4 =int(lines[3])*7 D5 =int(lines[4])*6 D6 =int(lines[5])*5 D7 =int(lines[6])*4 D…

Python np.nditer() - ValueError: Too many operands

I have a few methods which pass different amount of messy data to this function to combine headers with data and return a list of dictionaries:def zip_data(self, indicator_names, indicator_values):valu…

Python 3 - Find the Mode of a List

def mode(L):shows = []modeList = []L.sort()length = len(L)for num in L:count = L.count(num)shows.append(count)print List = , LmaxI = shows.index(max(shows))for i in shows:if i == maxI:if modeList == []…

Create list of sublists [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 9 years ago.Improve…

Python error - list index out of range?

Anyone help me see why I keep getting "list index out of range" as an error ?? def printInfo(average):average.sort() # sorts the list of tuples average.reverse() # reverses the list of tu…

Access strings inside a list

A Python list has [12:30,12:45] and I want to access the 12:30 for the first iteration, and on the second iteration I should get 12:45.my_list=[12:30,12:45] for each_value in my_list:print(each_value[0…

How do I install NumPy under Windows 8.1?

How do I install NumPy under Windows 8.1 ? Similar questions/answers on overflow hasnt helped.

Design In-Memory File System - Python - Trie - Leetcode Error

I am trying to solve the below leetcode problem Design a data structure that simulates an in-memory file system. Implement the FileSystem class: FileSystem() Initializes the object of the system. List …

OpenTurns Error when trying to use kernel build [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

How to write data to excel with header using Pandas?

I want to write the excel file with the header isI have data and I want to fill out the excel file. Then the expected result isThis is my code but it does not show as my expected. Could you help me to …