def test_all_actions_are_matched(): """Test that all execution complete events are matched.""" an_action = LogInfo(msg='some message') other_action = LogInfo(msg='other message') event_handler = OnExecutionComplete(on_completion=lambda *args: None) assert event_handler.matches(ExecutionComplete(action=an_action)) assert event_handler.matches(ExecutionComplete(action=other_action))
def test_single_action_is_matched(): """Test that only the target action execution complete event is matched.""" an_action = LogInfo(msg='some message') event_handler = OnExecutionComplete(target_action=an_action, on_completion=lambda *args: None) other_action = LogInfo(msg='other message') assert event_handler.matches(ExecutionComplete(action=an_action)) assert not event_handler.matches(ExecutionComplete(action=other_action))
def test_bad_construction(): """Test bad construction parameters.""" with pytest.raises(ValueError): OnExecutionComplete(target_action='not-an-action', on_completion=lambda *args: None) with pytest.raises(ValueError): OnExecutionComplete( target_action=LogInfo(msg='some message'), on_completion='not-a-callable-nor-an-action-iterable')
def add_test_action(self, launch_description, action): """ Add action used for testing. If either all test actions have completed or a process action has exited with a non-zero return code, a shutdown event is emitted. """ test_name = 'test_{}'.format(id(action)) if isinstance(action, ExecuteProcess): def on_test_process_exit(event, context): if event.returncode != 0: process_name = event.action.process_details['name'] self.__processes_rc[process_name] = event.returncode return self._fail( test_name, reason='{} test failed!'.format(process_name)) return self._succeed(test_name) launch_description.add_action( RegisterEventHandler( OnProcessExit(target_action=action, on_exit=on_test_process_exit))) else: def on_test_completion(event, context): future = event.action.get_asyncio_future() if future is not None: if future.cancelled(): return self._drop(test_name) exc = future.exception() if exc is not None: return self._fail(test_name, str(exc)) return self._succeed(test_name) launch_description.add_action( RegisterEventHandler( OnExecutionComplete(target_action=action, on_completion=on_test_completion))) launch_description.add_action(action) self._arm(test_name) return action