def setUp(self, mock_gazebo): self.m_ziputil = MockUtil.fakeit( self, 'hbp_nrp_cleserver.server.CLEGazeboSimulationAssembly.ZipUtil') self.mock_gazebo = mock_gazebo self.m_sim_util = MockUtil.fakeit( self, 'hbp_nrp_cleserver.server.CLEGazeboSimulationAssembly.SimUtil') self.m_sim_util.find_file_in_paths.return_value = '/a/robot/under/the/rainbow/model.sdf' self.m_simconf = MagicMock() self.m_simconf.sim_id = 123 self.m_simconf.token = 123 self.m_simconf.experiment_id = 'experiment' self.m_simconf.timeout = 'YYYY-MM-DD-HH:MM:SS' self.m_simconf.timeout_type = 'real' self.m_simconf.sim_dir = '/my/experiment' self.m_simconf.gzserver_host = 'local' self.m_simconf.ros_notificator = 'real' self.m_simconf.world_model.resource_path.abs_path = '/my/experiment/world.sdf' self.m_simconf.brain_model.is_custom = False self.m_simconf.brain_model.resource_path.rel_path = 'brain.sdf' self.m_simconf.brain_model.resource_path.abs_path = '/my/experiment/brain.sdf' # alternate set is_custom in individual test self.m_simconf.brain_model.zip_path.rel_path = 'brains/brain.zip' self.m_simconf.brain_model.zip_path.abs_path = '/my/experiment/brains/brain.sdf' self.m_simconf.robot_models = { 'bb8': Robot('bb8', '/my/experiment/bb8/model.sdf', 'my bb8', Mock(), False, 'my/roslauch/path', 'modelname'), 'r2d2': Robot('r2d2', '/my/experiment/r2d2/model.zip', 'my r2d2', Mock(), True, '/my/experiment/ros.launch', 'modelname') } self.m_simconf.retina_config = 'retina_configuration' self.m_simconf.ext_robot_controller = 'xyz.model' self.m_simconf.ros_launch_abs_path = '/my/experiment/ros.launch' self.patch_cleserver = patch( "hbp_nrp_cleserver.server.CLEGazeboSimulationAssembly.ROSCLEServer" ) self.mocked_cleserver = self.patch_cleserver.start() #self.mocked_cleserver._robotHandler.download_custom_robot.return_value = "somewhere/over/the/rainbow" self.mocked_cleserver.return_value._robotHandler.prepare_custom_robot.return_value = ( True, '/my/experiment/r2d2/model.sdf') self.patch_robotManager = patch( "hbp_nrp_cleserver.server.GazeboSimulationAssembly.RobotManager") self.mocked_robotManager = self.patch_robotManager.start() self.mocked_robotManager.return_value.scene_handler.return_value.parse_gazebo_world_file.return_value = {}, {} with patch( "hbp_nrp_cleserver.server.GazeboSimulationAssembly.rospy" ), patch("hbp_nrp_cleserver.server.GazeboSimulationAssembly.rosnode"): self.launcher = CLEGazeboSimulationAssembly(self.m_simconf)
def setUp(self): # mock os self.m_os = MockUtil.fakeit(self, _base_path + 'os') # restore os.path.join and os.path.dirname self.m_os.path.join = os.path.join self.m_os.path.dirname = os.path.dirname self.m_settings = MockUtil.fakeit(self, _base_path + 'Settings') self.m_shutil = MockUtil.fakeit(self, _base_path + 'shutil') self.m_tempfile = MockUtil.fakeit(self, _base_path + 'tempfile')
def setUp(self): # mock os self.m_os = MockUtil.fakeit(self, _base_path + 'os') # restore os.path.join and os.path.dirname self.m_os.path.join = os.path.join self.m_os.path.dirname = os.path.dirname self.m_os.environ = { 'HOME': '/home/dir', 'HBP': '/hbp/dir', 'NRP_SIMULATION_DIR': '/sim/dir', 'NRP_MODELS_DIRECTORY': '/models/dir' }
def setUp(self): # Mock all external imported modules self.m_os = MockUtil.fakeit(self, _base_ + 'os') self.m_storage = MockUtil.fakeit(self, _base_ + 'StorageClient') self.m_ziputil = MockUtil.fakeit(self, _base_ + 'ZipUtil') # Prepare dummy data for the instance self.simulation = Mock() self.simulation.sim_id = 42 self.simulation.experiment_conf = "ExDXMLExample.xml" self.simulation.experiment_id = 'my_awesome_exp' self.simulation.state_machines = [] self.simulation.playback_path = "a/path/to/some.zip" self.simulation.private = None # Mock the base cass of PlaybackSimulationLifecycle self.m_base = MockUtil.fake_base(self, PlaybackSimulationLifecycle) self.m_base.simulation.return_value = self.simulation self.playback_lifecycle = PlaybackSimulationLifecycle(self.simulation)
def setUp(self): self.m_ziputil = MockUtil.fakeit( self, 'hbp_nrp_cleserver.server.CLEGazeboSimulationAssembly.ZipUtil') self.m_simconf = MagicMock() self.m_simconf.sim_id = 123 self.m_simconf.token = 123 self.m_simconf.experiment_id = 'experiment' self.m_simconf.timeout = 'YYYY-MM-DD-HH:MM:SS' self.m_simconf.timeout_type = 'real' self.m_simconf.sim_dir = '/my/experiment' self.m_simconf.gzserver_host = 'local' self.m_simconf.ros_notificator = 'real' self.m_simconf.world_model.resource_path.abs_path = '/my/experiment/world.sdf' self.m_simconf.brain_model.is_custom = False self.m_simconf.brain_model.resource_path.rel_path = 'brain.sdf' self.m_simconf.brain_model.resource_path.abs_path = '/my/experiment/brain.sdf' # alternate set is_custom in individual test self.m_simconf.brain_model.zip_path.rel_path = 'brains/brain.zip' self.m_simconf.brain_model.zip_path.abs_path = '/my/experiment/brains/brain.sdf' self.m_simconf.robot_models = { 'bb8': Robot(rid='bb8', sdf_abs_path='/my/experiment/bb8/model.sdf', display_name='my bb8', is_custom=False, pose=Mock(), roslaunch_abs_path='/my/experiment/ros.launch', model='model_name'), 'r2d2': Robot(rid='r2d2', sdf_abs_path='/my/experiment/bb8/model.sdf', display_name='my r2d2', pose=Mock(), is_custom=True, roslaunch_abs_path='/my/experiment/ros.launch', model='model_name') } self.m_simconf.retina_config = 'retina_configuration' self.m_simconf.ext_robot_controller = 'xyz.model' with patch( "hbp_nrp_cleserver.server.CLEGazeboSimulationAssembly.StorageClient" ): self.launcher = SynchronousNestSimulation(self.m_simconf)
def setUp(self): self.simulation = Mock() self.simulation.sim_id = 42 self.simulation.experiment_conf = "ExDXMLExample.xml" self.simulation.experiment_id = None self.simulation.state_machines = [] self.simulation.playback_path = None self.simulation.private = True caller_id = patch("hbp_nrp_commons.simulation_lifecycle.get_caller_id", return_value="test_client") caller_id.start() self.addCleanup(caller_id.stop) self.rospy_mock = MockUtil.fakeit(self, _base_path + 'rospy') self.cle_factory_mock = MockUtil.fakeit(self, _base_path + 'ROSCLEClient') self.storage_mock = MockUtil.fakeit(self, _base_path + 'StorageClient') self.zip_util = MockUtil.fakeit(self, _base_path + 'ZipUtil') self.mocked_os = MockUtil.fakeit(self, _base_path + 'os') self.exp_mocked = MockUtil.fakeit(self, _base_path + 'exp_conf_api_gen') self.factory_mock = MockUtil.fakeit(self, _base_path + 'ROSCLESimulationFactoryClient') self.playback_mock = MockUtil.fakeit(self, 'hbp_nrp_backend.cle_interface.PlaybackClient.PlaybackClient') self.storage_mock.get_model.return_value = None self.storage_mock.get_model_path.return_value = None self.zip_util.extractall.return_value = None self.mocked_os.path.join.return_value = "/some/tmp/dir/" self.mocked_os.path.exists.return_value = True self.mocked_os.path.makedirs.return_value = None self.exp_mocked.CreateFromDocument.return_value.timeout.value.return_value = 1 with patch("hbp_nrp_commons.simulation_lifecycle.Publisher"): with patch("hbp_nrp_commons.simulation_lifecycle.Subscriber"): self.lifecycle = BackendSimulationLifecycle(self.simulation) self.lifecycle.experiment_path = PATH self.assertEqual(None, self.lifecycle.sim_dir)
def setUp(self): # mock os self.m_os = MockUtil.fakeit(self, _base_path + 'os') # restore os.path.join and os.path.dirname self.m_os.path.join = os.path.join self.m_os.path.dirname = os.path.dirname self.m_robot = MockUtil.fakeit(self, _base_path + 'Robot') self.m_exc_parser = MockUtil.fakeit(self, _base_path + 'exc_parser') self.m_bibi_parser = MockUtil.fakeit(self, _base_path + 'bibi_parser') self.m_sconf_util = MockUtil.fakeit(self, _base_path + 'SimConfUtil') self.m_gentf = MockUtil.fakeit(self, _base_path + 'generate_tf') self.m_gettfname = MockUtil.fakeit(self, _base_path + 'get_tf_name') self.m_exc = MagicMock() self.m_exc_parser.CreateFromDocument.return_value = self.m_exc self.m_bibi = MagicMock() self.m_bibi_parser.CreateFromDocument.return_value = self.m_bibi