def test007_cbrx_connection_open_device_twice(self): print "\ntest007_cbrx_connection_open_device_twice ", result = cbrxapi.cbrx_discover("local") if result: device = result[0] handle1 = cbrxapi.cbrx_connection_open(device) self.assertNotEqual(handle1, "") self.assertNotEqual(handle1, False) handle2 = cbrxapi.cbrx_connection_open(device) self.assertNotEqual(handle2, "") self.assertNotEqual(handle2, False) cbrxapi.cbrx_connection_close(handle2) cbrxapi.cbrx_connection_close(handle1)
def test0012_cbrx_connection_open_locked(self): print "\ntest0012_cbrx_connection_open_locked ", result = cbrxapi.cbrx_discover("local") if result: device = result[0] gotException = False errorCode = 0 handle = "" result = cbrxapi.cbrx_connection_closeandlock(device) self.assertEqual(result, True) try: handle = cbrxapi.cbrx_connection_open(device) except jsonrpc.RPCFault as e: gotException = True errorCode = e.error_code self.assertEqual(gotException, True) self.assertEqual(errorCode, CBRXAPI_ERRORCODE_NODEVICETHREAD) self.assertEqual(handle, "") result = cbrxapi.cbrx_connection_unlock(device) self.assertEqual(result, True)
def test0041_cbrx_connection_set_invalid_tag(self): print "\ntest0041_cbrx_connection_set ", result = cbrxapi.cbrx_discover("local") if result: device = result[0] handle = cbrxapi.cbrx_connection_open(device) gotException = False errorCode = 0 result = "" try: result = cbrxapi.cbrx_connection_set(handle, "INVALID_TAG", "INVALID") except jsonrpc.RPCFault as e: gotException = True errorCode = e.error_code print "Result: ", print result, print " " self.assertEqual(gotException, True) self.assertEqual(errorCode, CBRXAPI_ERRORCODE_ERRORSETTINGVALUE) self.assertEqual(result, "") result = cbrxapi.cbrx_connection_close(handle)
def test0030_cbrx_connection_get(self): print "\ntest0030_cbrx_connection_get ", result = cbrxapi.cbrx_discover("local") if result: device = result[0] handle = cbrxapi.cbrx_connection_open(device) result = cbrxapi.cbrx_connection_get(handle, "nrOfPorts") self.assertNotEqual(result, 0) result = cbrxapi.cbrx_connection_close(handle)
def test005_cbrx_connection_close(self): print "\ntest005_cbrx_connection_close ", result = cbrxapi.cbrx_discover("local") if result: device = result[0] handle = cbrxapi.cbrx_connection_open(device) result = cbrxapi.cbrx_connection_close(handle) self.assertEqual(result, True)
def test0010_cbrx_connection_open_valid(self): print "\ntest0010_cbrx_connection_open_valid ", result = cbrxapi.cbrx_discover("local") if result: device = result[0] handle = cbrxapi.cbrx_connection_open(device) self.assertNotEqual(handle, "") self.assertNotEqual(handle, False) cbrxapi.cbrx_connection_close(handle)
def test0020_cbrx_connection_getdictionary(self): print "\ntest0020_cbrx_connection_getdictionary ", result = cbrxapi.cbrx_discover("local") if result: device = result[0] handle = cbrxapi.cbrx_connection_open(device) dictionary = cbrxapi.cbrx_connection_getdictionary(handle) self.assertNotEqual(dictionary, "") self.assertNotEqual(dictionary, False) handle = cbrxapi.cbrx_connection_close(handle)
def test0040_cbrx_connection_set(self): print "\ntest0040_cbrx_connection_set ", result = cbrxapi.cbrx_discover("local") if result: device = result[0] handle = cbrxapi.cbrx_connection_open(device) result = cbrxapi.cbrx_connection_set(handle, "Port.3.mode", "c") print "\nResult: ", print result self.assertEqual(result, True) result = cbrxapi.cbrx_connection_close(handle)
def test006_cbrx_connection_open_baddevice(self): print "\ntest006_cbrx_connection_open ", device = "baddevice" gotException = False errorCode = 0 handle = "" try: handle = cbrxapi.cbrx_connection_open(device) except jsonrpc.RPCFault as e: gotException = True errorCode = e.error_code self.assertEqual(gotException, True) self.assertEqual(errorCode, CBRXAPI_ERRORCODE_IDNOTFOUND) self.assertEqual(handle, "") self.assertNotEqual(handle, "baddevice")
def test0011_cbrx_connection_open_invalid(self): print "\ntest0011_cbrx_connection_open_invalid ", result = cbrxapi.cbrx_discover("local") if result: device = result[0] gotException = False errorCode = 0 handle = "" try: handle = cbrxapi.cbrx_connection_open("BADDEVICE") except jsonrpc.RPCFault as e: gotException = True errorCode = e.error_code self.assertEqual(gotException, True) self.assertEqual(errorCode, CBRXAPI_ERRORCODE_IDNOTFOUND) self.assertEqual(handle, "")
def test008_cbrx_connection_close_handle_twice(self): print "\ntest008_cbrx_connection_close_handle_twice ", result = cbrxapi.cbrx_discover("local") if result: device = result[0] handle1 = cbrxapi.cbrx_connection_open(device) self.assertNotEqual(handle1, "") self.assertNotEqual(handle1, False) cbrxapi.cbrx_connection_close(handle1) try: cbrxapi.cbrx_connection_close(handle1) except jsonrpc.RPCFault as e: gotException = True errorCode = e.error_code self.assertEqual(gotException, True) self.assertEqual(errorCode, CBRXAPI_ERRORCODE_INVALIDHANDLE)
def test0033_cbrx_connection_get_missing_tag(self): print "\ntest0032_cbrx_connection_get_missing_tag ", result = cbrxapi.cbrx_discover("local") if result: device = result[0] handle = cbrxapi.cbrx_connection_open(device) gotException = False errorCode = 0 result = "" try: result = cbrxapi.cbrx_connection_get(handle) except jsonrpc.RPCFault as e: gotException = True errorCode = e.error_code self.assertEqual(gotException, True) self.assertEqual(errorCode, JSONRPC_ERRORCODE_INVALIDPARAMETERS) self.assertEqual(result, "") result = cbrxapi.cbrx_connection_close(handle)
def test0031_cbrx_connection_get_invalid_tag(self): print "\ntest0031_cbrx_connection_get_invalid_tag ", result = cbrxapi.cbrx_discover("local") if result: device = result[0] handle = cbrxapi.cbrx_connection_open(device) gotException = False errorCode = 0 result = "" try: result = cbrxapi.cbrx_connection_get(handle, "INVALID") except jsonrpc.RPCFault as e: gotException = True errorCode = e.error_code self.assertEqual(gotException, True) self.assertEqual(errorCode, CBRXAPI_ERRORCODE_KEYNOTFOUND) self.assertEqual(result, "") result = cbrxapi.cbrx_connection_close(handle)
def test0021_cbrx_connection_getdictionary_invalidhandle(self): print "\ntest0021_cbrx_connection_getdictionary_invalidhandle ", result = cbrxapi.cbrx_discover("local") if result: device = result[0] handle = cbrxapi.cbrx_connection_open(device) badhandle = "INVALID" gotException = False errorCode = 0 dictionary = "" try: dictionary = cbrxapi.cbrx_connection_getdictionary(badhandle) except jsonrpc.RPCFault as e: gotException = True errorCode = e.error_code self.assertEqual(gotException, True) self.assertEqual(errorCode, CBRXAPI_ERRORCODE_INVALIDHANDLE) self.assertEqual(dictionary, "") cbrxapi.cbrx_connection_close(handle)
def test0034_cbrx_connection_get_invalid_handle(self): print "\ntest0034_cbrx_connection_get_invalid_handle ", result = cbrxapi.cbrx_discover("local") if result: device = result[0] handle = cbrxapi.cbrx_connection_open(device) badhandle = "INVALID" gotException = False errorCode = 0 result = "" try: result = cbrxapi.cbrx_connection_get(badhandle, "nrOfPorts") except jsonrpc.RPCFault as e: gotException = True errorCode = e.error_code self.assertEqual(gotException, True) self.assertEqual(errorCode, CBRXAPI_ERRORCODE_INVALIDHANDLE) self.assertEqual(result, "") result = cbrxapi.cbrx_connection_close(handle)
def setUp(self): TestDictionary.handle = cbrxapi.cbrx_connection_open( TestDictionary.device)
import sys from cbrxapi import cbrxapi result = cbrxapi.cbrx_discover("local") if result==False: print "No Cambrionix unit found." sys.exit(0) unitId = result[0] handle = cbrxapi.cbrx_connection_open(unitId) for i in range(1, 17): serial = cbrxapi.cbrx_connection_get(handle, "Port." + str(i) + ".SerialNumber") if serial != "" : output = str(i) + ":" + str(serial) print output cbrxapi.cbrx_connection_close(handle)
self.assertEqual(value, False) def test_get_Profile_5_enabled(self): # Profile.5.enabled : False tag = "Profile.5.enabled" print tag value = cbrxapi.cbrx_connection_get(TestDictionary.handle, tag) print value self.assertEqual(value, False) if __name__ == '__main__': # find first local cambrionix device result = cbrxapi.cbrx_discover("local") if result: TestDictionary.device = result[0] else: TestDictionary.device = False if not TestDictionary.device: print "No device found, cannot run test" sys.exit() TestDictionary.handle = cbrxapi.cbrx_connection_open(TestDictionary.device) cbrxapi.cbrx_connection_getdictionary(TestDictionary.handle) cbrxapi.cbrx_connection_close(TestDictionary.handle) print "Running tests" unittest.main()