def test_view(walkable):
    '''
    Given a walkable location, view that location.
    '''
    (node, (segments, found)) = walkable
    assume(found == found)  # Hello, nan! We don't want you here.

    view = api.view(node, segments)
    assert api.get(view, segments) == api.get(node, segments)
def test_get(node):
    '''
    Given a node, get should return the exact value given a key for all
    key, value pairs in the node.
    '''
    for k, v in api.walk(node):
        assert api.get(node, k) is v
def test_set_walkable(walkable, value):
    '''
    Given a walkable location, set should be able to update any value.
    '''
    (node, (segments, found)) = walkable
    api.set(node, segments, value)
    assert api.get(node, segments) is value
def test_types(node):
    '''
    Given a node, types should yield a tuple of key, type pairs and the
    type indicated should equal the type of the value.
    '''
    for k, v in api.walk(node):
        ts = api.types(node, k)
        ta = ()
        for tk, tt in ts:
            ta += (tk, )
            assert type(api.get(node, ta)) is tt
def test_set_create_missing(walkable, kstr, kint, value, extension):
    '''
    Given a walkable non-leaf, set should be able to create missing
    nodes and set a new value.
    '''
    (node, (segments, found)) = walkable
    assume(api.leaf(found))

    parent_segments = segments[:-1]
    parent = api.get(node, parent_segments)

    if isinstance(parent, list):
        assume(len(parent) < kint)
        destination = parent_segments + (kint, ) + tuple(extension)
    elif isinstance(parent, dict):
        assume(kstr not in parent)
        destination = parent_segments + (kstr, ) + tuple(extension)
    else:
        raise Exception('mad mad world')

    api.set(node, destination, value)
    assert api.get(node, destination) is value