示例#1
0
def test_single_msg_to_gen():
    m = Msg('set', None, 0)

    m_list = [m for m in ensure_generator(m)]

    assert len(m_list) == 1
    assert m_list[0] == m
示例#2
0
def test_single_msg_to_gen():
    m = Msg('set', None, 0)

    m_list = [m for m in ensure_generator(m)]

    assert len(m_list) == 1
    assert m_list[0] == m
示例#3
0
    def _run(self, plan):
        plan = ensure_generator(plan)
        last_result = None
        _exception = None
        while True:
            try:
                if _exception is not None:
                    msg = plan.throw(_exception)
                    _exception = None
                else:
                    msg = plan.send(last_result)
            except StopIteration:
                break

            try:
                func = self.function_map[msg.command]
                last_result = yield from func(msg)

            except Exception as e:
                _exception = e
示例#4
0
def EchoRE(plan, *, debug=False, msg_list=None):
    '''An 'echo' RunEngine for testing.

    Always sends the message back into the plan as the result.

    Parameters
    ----------
    plan : iterable
        The plan to run through

    debug : bool, optional (False)
        print the messages on the way by

    msg_list : mutable sequence, optional
        If not None, mutate this object by appending messages.
        This is the easiest way to capture messages if the plan
        raises.

    Returns
    -------
    msg_list : list
        List of all the messages seen by the RE
    '''
    if msg_list is None:
        msg_list = deque()
    ret = None
    plan = ensure_generator(plan)
    while True:
        try:
            msg = plan.send(ret)
            if debug:
                print(msg)
            msg_list.append(msg)
            if msg.command == 'FAIL':
                plan.throw(EchoException(msg))
            ret = msg
        except StopIteration:
            break

    return list(msg_list)
示例#5
0
def EchoRE(plan, *, debug=False, msg_list=None):
    '''An 'echo' RunEngine for testing.

    Always sends the message back into the plan as the result.

    Parameters
    ----------
    plan : iterable
        The plan to run through

    debug : bool, optional (False)
        print the messages on the way by

    msg_list : mutable sequence, optional
        If not None, mutate this object by appending messages.
        This is the easiest way to capture messages if the plan
        raises.

    Returns
    -------
    msg_list : list
        List of all the messages seen by the RE
    '''
    if msg_list is None:
        msg_list = deque()
    ret = None
    plan = ensure_generator(plan)
    while True:
        try:
            msg = plan.send(ret)
            if debug:
                print(msg)
            msg_list.append(msg)
            if msg.command == 'FAIL':
                plan.throw(EchoException(msg))
            ret = msg
        except StopIteration:
            break

    return list(msg_list)