Beispiel #1
0
def test_nested_exists():
    console.banner("Nested Read")
    for create in [create_blackboards, create_namespaced_blackboards]:
        with create() as (foo, unused_bar, namespace):
            print("foo.exists('motley.nested') [{}][{}]".format(
                foo.exists("motley.nested"), True))
            assert (foo.exists("motley.nested"))
            print("foo.exists('motley.not_here') [{}][{}]".format(
                foo.exists("motley.not_here"), False))
            assert (not foo.exists("motley.not_here"))

            namespaced_name = "{}/motley.nested".format(namespace)
            print("Blackboard.exists({}) [{}][{}]".format(
                namespaced_name, Blackboard.exists(namespaced_name), True))
            assert (Blackboard.exists(namespaced_name))
def test_key_exists():
    console.banner("Key Exists")
    for create in [create_blackboards, create_namespaced_blackboards]:
        with create() as (foo, unused_bar, namespace):
            print("foo.exists('dude') [{}][{}]".format(foo.exists("dude"), True))
            assert(foo.exists("dude"))
            if namespace:
                print("Blackboard.exists('{}/dude') [{}][{}]".format(
                    namespace,
                    Blackboard.exists(name="{}/dude".format(namespace)),
                    True)
                )
                assert(Blackboard.exists(name="{}/dude".format(namespace)))
            with nose.tools.assert_raises_regexp(AttributeError, "does not have read/write access"):
                print("Expecting Attribute Error with substring 'does not have read/write access'")
                print("foo.exists('dude_not_here') [{}][{}]".format(foo.exists("dude_not_here"), False))
                assert(not foo.exists("dude_not_here"))
def test_remappings():
    console.banner("Remappings")
    blackboard = py_trees.blackboard.Client(name="Blackboard")
    blackboard.register_key(key="dude", access=py_trees.common.Access.WRITE)
    blackboard.register_key(key="/dudette", access=py_trees.common.Access.WRITE)
    blackboard.register_key(
        key="/foo/bar/wow",
        access=py_trees.common.Access.WRITE,
        remap_to="/parameters/anticipation"
    )
    print("setters & getters...")
    blackboard.set("/foo/bar/wow", "set")
    assert(Blackboard.storage["/parameters/anticipation"] == "set")
    blackboard.foo.bar.wow = "pythonic"
    print("  blackboard.foo.bar.wow == 'pythonic'")
    assert(blackboard.foo.bar.wow == "pythonic")
    print("  blackboard.get('/foo/bar/wow') == 'pythonic'")
    assert(blackboard.get("/foo/bar/wow") == "pythonic")
    print("  Blackboard.storage['/parameters/anticipation'] == 'pythonic'")
    assert(Blackboard.storage["/parameters/anticipation"] == "pythonic")

    print("exists....")
    print("  blackboard.exists('/foo/bar/wow')")
    assert(blackboard.exists('/foo/bar/wow'))
    print("  Blackboard.exists('/parameters/anticipation')")
    assert(Blackboard.exists("/parameters/anticipation"))

    print("unset...")
    blackboard.unset("/foo/bar/wow")
    print("  not blackboard.exists('/foo/bar/wow')")
    assert(not blackboard.exists('/foo/bar/wow'))
    print("  not Blackboard.exists('/parameters/anticipation')")
    assert(not Blackboard.exists("/parameters/anticipation"))

    print("unregister_key...")
    blackboard.foo.bar.wow = "pythonic"
    blackboard.unregister_key("/foo/bar/wow", clear=True)
    print("  not Blackboard.exists('/parameters/anticipation')")
    assert(not Blackboard.exists("/parameters/anticipation"))

    print(py_trees.display.unicode_blackboard())
    print(blackboard)
    blackboard.unregister(clear=True)
def test_namespaced_dot_access():
    console.banner("Namespaced Dot Access")
    blackboard = py_trees.blackboard.Client(name="Blackboard")
    blackboard.register_key(key="dude", access=py_trees.common.Access.WRITE)
    blackboard.register_key(key="/dudette", access=py_trees.common.Access.WRITE)
    blackboard.register_key(key="/foo/bar/wow", access=py_trees.common.Access.WRITE)
    print("Trying....'blackboard.dude = True'")
    blackboard.dude = True
    assert(blackboard.dude)
    print("Trying....'blackboard.dude = True'")
    blackboard.dudette = True
    assert(blackboard.dudette)
    print("Trying....'blackboard.foo.bar.wow = True'")
    blackboard.foo.bar.wow = True
    assert(Blackboard.exists("/foo/bar/wow"))
    assert(blackboard.foo.bar.wow)
    blackboard.unregister()