def test_analyze_tree_1():

    tree_1 = alias(child=repeat_until(child=action(hello), condition=success_until_zero), name="btree_1")

    a_tree_1 = analyze(tree_1)

    printed_tree = """ --> btree_1:\n     --(child)--> repeat_until:\n         --(condition)--> success_until_zero:\n         --(child)--> action:\n                      target: hello\n"""  # noqa: E501, B950
    assert stringify_analyze(a_tree_1) == printed_tree
def test_analyze_sequence():

    a_tree = analyze(
        alias(
            child=repeat_until(
                child=sequence(children=[action(hello), action(hello), action(hello)]), condition=success_until_zero
            ),
            name="btree_1",
        )
    )
    print_test = """ --> btree_1:\n     --(child)--> repeat_until:\n         --(condition)--> success_until_zero:\n         --(child)--> sequence:\n                      succes_threshold: 3\n             --(children)--> action:\n                             target: hello\n             --(children)--> action:\n                             target: hello\n             --(children)--> action:\n                             target: hello\n"""  # noqa: E501, B950
    assert stringify_analyze(a_tree) == print_test
Пример #3
0
def test_repeat_until_return_last_result(kernel):

    counter = ContextVar('tick_test_repeat_until_return_last_result',
                         default=5)

    async def tick():
        value = counter.get()
        counter.set(value - 1)
        if value <= 0:
            return FAILURE
        return SUCCESS

    result = kernel.run(repeat_until(condition=tick, child=exception_func))
    assert counter.get() == -1
    assert isinstance(result, ExceptionDecorator)
Пример #4
0
def test_repeat_until_falsy_condition(kernel):

    counter = ContextVar('counter', default=5)

    async def tick():
        value = counter.get()
        counter.set(value - 1)
        if value <= 0:
            return FAILURE
        if value == 3:
            raise RuntimeError('3')
        return SUCCESS

    assert kernel.run(repeat_until(
        condition=tick, child=a_func)) == 'a', 'return last sucess result'
    assert counter.get() == 2