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 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)
class SamplerCallbackManagerTest(TestCase): def setUp(self): self.sampler = RecordingSampler((1, 2, 'a string')) self.handler = SamplerCallbackManager(self.sampler) 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 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 start_osc_server(self): # for i in 'AK': print ord(i) OSCServer('localhost', 6575, SamplerCallbackManager(self)) class ServerThread(Thread): def __init__(self): Thread.__init__(self, name='OSC Server Thread') def run(self): asyncore.loop() self.serverThread = ServerThread() self.serverThread.start()
class SamplerCallbackManagerTest(TestCase): def setUp(self): self.sampler = RecordingSampler((1,2,'a string')) self.handler = SamplerCallbackManager(self.sampler) 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 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);
self.bind((address, port)) self.response = None print '%s started at addr: %s:%i\n' % ( self.__class__.__name__, address, port) def handle_connect(self): pass def writable(self): return self.response is not None def handle_write(self): self.sendto(self.response.get_message(), 0, self.response.get_address()) self.response = None def handle_read(self): data, address = self.recvfrom(8192) resp_data = self._callbackMgr.handle(data) self.response = Envelope(address, resp_data) if __name__ == "__main__": parser = create_option_parser() options = parser.parse_args()[0] from aksy.device import Devices z48 = Devices.get_instance('mock_z48', None) server = OSCServer(options.address, options.port, SamplerCallbackManager(z48)) try: asyncore.loop() except KeyboardInterrupt: asyncore.close_all()
def setUp(self): self.sampler = RecordingSampler((1,2,'a string')) self.handler = SamplerCallbackManager(self.sampler)
def setUp(self): self.sampler = RecordingSampler((1, 2, 'a string')) self.handler = SamplerCallbackManager(self.sampler)