def test_rosservicewrapper_constructor(self, service_proxy_mock): # Case when the service is correctly subscribed service_wrapper = ROSCLEClient.ROSCLEServiceWrapper( 'service_name', Empty, None) self.assertEquals('service_name', service_proxy_mock.call_args[0][0]) self.assertIsInstance(service_proxy_mock.call_args[0][1], type(Empty)) args, kwargs = service_wrapper.handler.wait_for_service.call_args_list[ 0] self.assertEquals( kwargs['timeout'], ROSCLEClient.ROSCLEServiceWrapper.ROS_SERVICE_TIMEOUT) # Case when the service timeouts service_proxy_mock.side_effect = rospy.ROSException() self.assertRaises(ROSCLEClient.ROSCLEClientException, ROSCLEClient.ROSCLEServiceWrapper, 'service_name', Empty, None)
def test_get_csv_files(self, service_proxy_mock, mock_cle_recorded_file): mock_cle_recorded_file.return_value = ("bar1", ["bar1 header\n"], ['data1', 'data2\n']) client = ROSCLEClient.ROSCLEClient(0) files = Mock() files.files = [CSVRecordedFile(), CSVRecordedFile()] client._ROSCLEClient__cle_get_CSV_recorders_files = Mock( return_value=files) self.assertEqual(client.get_simulation_CSV_recorders_files(), files.files) client.stop_communication("Test stop") self.assertEqual(client.get_simulation_CSV_recorders_files(), files.files)
def test_set_brain(self, service_proxy_mock): msg = SetBrain() resp = msg._response_class(error_message='error message', error_line=-1, error_column=-1) client = ROSCLEClient.ROSCLEClient(0) client._ROSCLEClient__cle_set_brain = MagicMock(return_value=resp) self.assertEquals( client.set_simulation_brain('py', 'text', 'data', '{"population_1": 2}'), resp) client._ROSCLEClient__cle_set_brain.assert_called_once_with( 'py', 'data', 'text', '{"population_1": 2}') client.stop_communication("Test stop") with self.assertRaises(ROSCLEClientException): client.set_simulation_brain('py', 'text', 'data', '{"population_1": 2}')
def test_get_populations(self): client = ROSCLEClient.ROSCLEClient(0) populations = Mock() populations.neurons = [ PopulationInfo("foo", "bar", [ NeuronParameter("p", 42.0) ], [0, 8, 15], range(0, 3)) ] client._ROSCLEClient__cle_get_populations = Mock(return_value=populations) self.assertEqual(client.get_populations(), { 'populations': [ { 'name': 'foo', 'neuron_model': 'bar', 'parameters': [{ 'parameterName': 'p', 'value': 42.0}], 'gids': [0,8,15], 'indices': range(0, 3) } ] })
def test_roscleclient_constructor(self, service_wrapper_mock): client = ROSCLEClient.ROSCLEClient(0) listened_services = [ x[0][0] for x in service_wrapper_mock.call_args_list ] expected_services = [ SERVICE_SIM_RESET_ID(0), SERVICE_GET_TRANSFER_FUNCTIONS(0), SERVICE_EDIT_TRANSFER_FUNCTION(0), SERVICE_ADD_TRANSFER_FUNCTION(0), SERVICE_DELETE_TRANSFER_FUNCTION(0), SERVICE_GET_BRAIN(0), SERVICE_SET_BRAIN(0), SERVICE_GET_POPULATIONS(0), SERVICE_GET_CSV_RECORDERS_FILES(0), SERVICE_SIMULATION_RECORDER(0), SERVICE_CONVERT_TRANSFER_FUNCTION_RAW_TO_STRUCTURED(0) ] self.assertNotIn(False, [x in listened_services for x in expected_services])
def test_reset(self, service_proxy_mock): client = ROSCLEClient.ROSCLEClient(0) simulation_recorder = Mock() reset_resp = Mock() reset_resp.success = True reset = Mock(return_value=reset_resp) client._ROSCLEClient__simulation_recorder = simulation_recorder client._ROSCLEClient__cle_reset = reset pop1 = Mock() pop2 = Mock() pop1.name = u'foo' pop1.step = 1 pop2.name = 'bar' pop2.step = 0 client.reset(ResetSimulationRequest.RESET_FULL, populations=[pop1, pop2]) simulation_recorder.assert_has_calls( call(SimulationRecorderRequest.CANCEL)) simulation_recorder.assert_has_calls( call(SimulationRecorderRequest.RESET)) self.assertEqual(pop1.name, 'foo') self.assertEqual(pop2.name, 'bar') self.assertEqual(pop1.step, 1) self.assertEqual(pop2.step, 1) self.assertTrue(reset.called) reset_resp.success = False reset_resp.error_message = "Foobar" self.assertRaises(ROSCLEClientException, client.reset, ResetSimulationRequest.RESET_FULL) client.stop_communication("Test stop") self.assertRaises(ROSCLEClientException, client.reset, ResetSimulationRequest.RESET_FULL)