def get_data(self, message): """ Parameters ---------- message Returns ------- """ messg = ThreadCommand(message) if message == 'set_info': list_len = get_int(self.socket) path = [] for ind in range(list_len): path.append(get_string(self.socket)) param_xml = get_string(self.socket) messg.attributes = [path, param_xml] elif message == 'move_abs': position = get_scalar(self.socket) messg.attributes = [position] elif message == 'move_rel': position = get_scalar(self.socket) messg.attributes = [position] self.cmd_signal.emit(messg)
def get_data(self, message): """ Parameters ---------- message Returns ------- """ if self.socket is not None: messg = ThreadCommand(message) if message == 'set_info': path = self.socket.get_list() param_xml = self.socket.get_string() messg.attributes = [path, param_xml] elif message == 'move_abs': position = self.socket.get_scalar() messg.attributes = [position] elif message == 'move_rel': position = self.socket.get_scalar() messg.attributes = [position] self.cmd_signal.emit(messg)
def test_queue_command(self, mock_connection): mock_connection.side_effect = [Expected_1] command = ThreadCommand() command.attributes = { 'ipaddress': '0.0.0.0', 'port': 5544, 'path': [1, 2, 3], 'param': Parameter(name='test_param') } test_TCP_Client = TCPClient() test_TCP_Client.socket = Socket(MockPythonSocket()) command.command = 'ini_connection' with pytest.raises(Expected_1): test_TCP_Client.queue_command(command) test_TCP_Client = TCPClient() cmd_signal = mock.Mock() cmd_signal.emit.side_effect = [Expected_2, Expected_3] test_TCP_Client.cmd_signal = cmd_signal command.command = 'quit' with pytest.raises(Expected_2): test_TCP_Client.queue_command(command) test_TCP_Client.socket = Socket(MockPythonSocket()) with pytest.raises(Expected_3): test_TCP_Client.queue_command(command) assert test_TCP_Client.socket.socket._closed test_TCP_Client.socket = Socket(MockPythonSocket()) command.command = 'update_connection' test_TCP_Client.queue_command(command) assert test_TCP_Client.ipaddress == command.attributes['ipaddress'] assert test_TCP_Client.port == command.attributes['port'] command.command = 'send_info' test_TCP_Client.queue_command(command) assert test_TCP_Client.socket.get_string() == 'Info_xml' assert test_TCP_Client.socket.get_list() == command.attributes['path'] assert test_TCP_Client.socket.get_string() command.attributes = [{'data': [1, 1.1, 5]}] command.command = 'data_ready' test_TCP_Client.queue_command(command) assert test_TCP_Client.socket.get_string() == 'Done' assert test_TCP_Client.socket.get_list( ) == command.attributes[0]['data'] command.attributes = [10] command.command = 'position_is' test_TCP_Client.queue_command(command) assert test_TCP_Client.socket.get_string() == 'position_is' assert test_TCP_Client.socket.get_scalar() == command.attributes[0] command.command = 'move_done' test_TCP_Client.queue_command(command) assert test_TCP_Client.socket.get_string() == 'move_done' assert test_TCP_Client.socket.get_scalar() == command.attributes[0] command.attributes = [np.array([1, 2, 3])] command.command = 'x_axis' test_TCP_Client.queue_command(command) assert test_TCP_Client.socket.get_string() == 'x_axis' array = command.attributes[0] result = test_TCP_Client.socket.get_array() for val1, val2 in zip(array, result): assert val1 == val2 assert test_TCP_Client.socket.get_string() == '' assert test_TCP_Client.socket.get_string() == '' command.command = 'y_axis' test_TCP_Client.queue_command(command) assert test_TCP_Client.socket.get_string() == 'y_axis' result = test_TCP_Client.socket.get_array() for val1, val2 in zip(array, result): assert val1 == val2 assert test_TCP_Client.socket.get_string() == '' assert test_TCP_Client.socket.get_string() == '' command.command = 'x_axis' command.attributes = [{ 'data': np.array([1, 2, 3]), 'label': 'test', 'units': 'cm' }] test_TCP_Client.queue_command(command) assert test_TCP_Client.socket.get_string() == 'x_axis' array = command.attributes[0]['data'] result = test_TCP_Client.socket.get_array() for val1, val2 in zip(array, result): assert val1 == val2 assert test_TCP_Client.socket.get_string() == 'test' assert test_TCP_Client.socket.get_string() == 'cm' command.command = 'y_axis' test_TCP_Client.queue_command(command) assert test_TCP_Client.socket.get_string() == 'y_axis' result = test_TCP_Client.socket.get_array() for val1, val2 in zip(array, result): assert val1 == val2 assert test_TCP_Client.socket.get_string() == 'test' assert test_TCP_Client.socket.get_string() == 'cm' command.command = 'test' with pytest.raises(IOError): test_TCP_Client.queue_command(command)