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
def test_analyze_tree_2():
    tree_2 = retry(child=inverter(child=action(hello)), max_retry=10)
    a_tree_2 = analyze(tree_2)

    printed_tree = """ --> retry:\n     max_retry: 10\n     --(child)--> inverter:\n         --(child)--> action:\n                      target: hello\n"""  # noqa: E501, B950

    assert stringify_analyze(a_tree_2) == printed_tree
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_node_str():
    node = analyze(alias(child=action(target=hello), name='a test'))
    printed_tree = """ --> a test:\n     --(child)--> action:\n                  target: hello\n"""
    assert str(node) == printed_tree
Exemplo n.º 5
0
class GripperInterface:
    def __init__(self):
        self._open = False

    def open(self):
        print("GripperInterface Open")
        self._open = True

    def close(self):
        print("GripperInterface Close")
        self._open = False


gripper = GripperInterface()

b_tree = bt.sequence(
    children=[
        bt.always_success(child=bt.action(target=say_hello, name="John")),
        bt.action(target=check_battery),
        check_again_battery,  # this will be encapsulated at runtime
        bt.always_success(child=bt.action(target=gripper.open)),
        bt.always_success(child=bt.action(target=approach_object, name="house")),
        bt.always_success(child=bt.action(target=gripper.close)),
    ]
)


if __name__ == '__main__':
    curio.run(b_tree)
Exemplo n.º 6
0
def test_action_results(kernel):
    async def compute(a, b):
        return a + b

    assert kernel.run(action(compute, a=1, b=1)) == 2
Exemplo n.º 7
0
def test_action_with_exception_is_falsy(kernel):
    async def generate_exception():
        raise Exception("Bing!")

    assert not kernel.run(action(generate_exception))