How to use the dpath.segments.walk function in dpath

To help you get started, we’ve selected a few dpath examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github akesterson / dpath-python / tests / test_segments.py View on Github external
def test_walk(thing):
    '''
    Given a thing to walk, walk should yield key, value pairs where key
    is a tuple of non-zero length.
    '''
    for k, v in api.walk(thing):
        assert isinstance(k, tuple)
        assert len(k) > 0
github akesterson / dpath-python / tests / test_segments.py View on Github external
def test_has(node):
    '''
    Given a node, has should return True for all paths, False otherwise.
    '''
    for k, v in api.walk(node):
        assert api.has(node, k) is True

        # If we are at a leaf, then we can create a value that isn't
        # present easily.
        if api.leaf(v):
            assert api.has(node, k + (0,)) is False
github akesterson / dpath-python / tests / test_segments.py View on Github external
def random_walk(draw):
    node = draw(random_mutable_node)
    found = tuple(api.walk(node))
    assume(len(found) > 0)
    return (node, draw(st.sampled_from(found)))
github akesterson / dpath-python / tests / test_segments.py View on Github external
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
github akesterson / dpath-python / dpath / util.py View on Github external
def yielder():
            for segments, found in dpath.segments.walk(obj):
                if keeper(segments, found):
                    yield (separator.join(map(dpath.segments.int_str, segments)), found)
        return yielder()