def testEncodeDecodeIterable(self): m = OSCMessage() m.append((False, (1L, ))) self.assertEquals(['', ',[F[h]]', [ False, [ 1, ], ]], decodeOSC(m.getBinary()))
def testDispatchUnknownCommand(self): message = OSCMessage() message.setAddress("/sample/play") sampler = RecordingSampler((1,2,'a string'), AttributeError('a')) handler = SamplerCallbackManager(sampler) # should not throw resp = handler.handle(message.getBinary()) self.assertEquals(resp, "/sampler/error\x00\x00,ss\x00Failed to execute command /sample/play\x00\x00a\x00\x00\x00") self.assertEquals([], self.sampler.recorded);
def testDispatchInvalidAddress(self): message = OSCMessage() message.setAddress("/sample/play/invalid") # should not throw resp = self.handler.handle(message.getBinary()) self.assertEquals(str(resp), "/sampler/error\x00\x00,ss\x00Execution failed\x00\x00\x00\x00" "Invalid address: '/sample/play/invalid', should have two components\x00") self.assertEquals([], self.sampler.recorded);
def testDispatchInvalidAddress(self): message = OSCMessage() message.setAddress("/sample/play/invalid") # should not throw resp = self.handler.handle(message.getBinary()) self.assertEquals( str(resp), "/sampler/error\x00\x00,ss\x00Execution failed\x00\x00\x00\x00" "Invalid address: '/sample/play/invalid', should have two components\x00" ) self.assertEquals([], self.sampler.recorded)
def testDispatchUnknownCommand(self): message = OSCMessage() message.setAddress("/sample/play") sampler = RecordingSampler((1, 2, 'a string'), AttributeError('a')) handler = SamplerCallbackManager(sampler) # should not throw resp = handler.handle(message.getBinary()) self.assertEquals( resp, "/sampler/error\x00\x00,ss\x00Failed to execute command /sample/play\x00\x00a\x00\x00\x00" ) self.assertEquals([], self.sampler.recorded)
def create_response_msg(address, result): msg = OSCMessage() msg.setAddress(address) if not hasattr(result, '__iter__'): result = [result] for arg in result: msg.append(arg) return msg.getBinary()
def testEncodeDecodeNone(self): m = OSCMessage() m.append(None) self.assertEquals(['', ',N', None], decodeOSC(m.getBinary()))
def testEncodeDecodeTrue(self): m = OSCMessage() m.append(True) self.assertEquals(['', ',T', True], decodeOSC(m.getBinary()))
def testEncodeDecodeFalse(self): m = OSCMessage() m.append(False) self.assertEquals(['', ',F', False], decodeOSC(m.getBinary()))
def snd_recv(cmd): m = OSCMessage() m.setAddress(cmd) s.sendall(m.getBinary()) print decodeOSC(s.recv(8192))
def testAppendDecodeIterableEmpty(self): m = OSCMessage() m.append([]) self.assertEquals(['',',[]',[]], decodeOSC(m.getBinary()))
def create_msg(command, args): m = OSCMessage() m.setAddress("/" + command.section + "/" + command.name) for arg in args: m.append(arg) return m.getBinary()
def testDispatch(self): message = OSCMessage() message.setAddress("/transfertools/get") message.append("test.wav") response = self.handler.handle(message.getBinary()) self.assertEquals([["transfertools", "get", ["test.wav"]]], self.sampler.recorded) expected = OSCMessage() expected.setAddress("/transfertools/get") expected.append(1) expected.append(2) expected.append('a string') self.assertEquals(str(expected), response)
def testEncodeDecodeBinaryString(self): m = OSCMessage() m.append("\x00\x01\x02") self.assertEquals(['', ',b', "\x00\x01\02"], decodeOSC(m.getBinary()))
def testEncodeDecodeInt(self): m = OSCMessage() m.append(1) self.assertEquals(['', ',i', 1], decodeOSC(m.getBinary()))
def testAppendDecodeIterableEmpty(self): m = OSCMessage() m.append([]) self.assertEquals(['', ',[]', []], decodeOSC(m.getBinary()))
def testEncodeDecodeFloat(self): m = OSCMessage() m.append(1.0) self.assertEquals(['', ',f', 1.0], decodeOSC(m.getBinary()))
def create_error_msg(text, exception): msg = OSCMessage() msg.setAddress('/sampler/error') msg.append(text) msg.append(str(exception)) return msg.getBinary()
def testEncodeDecodeIterable(self): m = OSCMessage() m.append((False, (1L,))) self.assertEquals(['', ',[F[h]]', [False, [1,],]], decodeOSC(m.getBinary()))
def testEncodeDecodeString(self): m = OSCMessage() m.append("abc") self.assertEquals(['', ',s', "abc"], decodeOSC(m.getBinary()))
def create_alt_req_msg(handle, commands, args, index): bundle = OSCMessage() bundle.setAddress("") bundle.append('#bundle') bundle.append(0) bundle.append(0) alt_req = OSCMessage() alt_req.setAddress('/altoperations') alt_req.append(handle) alt_req.append(index) bundle.append(alt_req.getBinary(), 'b') args = list(args) for cmd in commands: if len(cmd.arg_types) > 0: arg = args.pop(0) else: arg = [] bundle.append(OSCConnector.create_msg(cmd, arg), 'b') return bundle.message
def testEncodeDecodeLong(self): m = OSCMessage() m.append(1L) self.assertEquals(['', ',h', 1L], decodeOSC(m.getBinary()))