Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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)))
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 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()