Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"d": 0,
"e": 1,
"f": 2
}
}
}
}
paths = [
'a',
'a;b',
'a;b;c',
'a;b;c;d',
'a;b;c;e',
'a;b;c;f'
]
for (path, value) in dpath.util.search(dict, '/**', yielded=True, separator=";"):
assert(path in paths)
for (path, value) in dpath.util.search(dict, ['**'], yielded=True, separator=";"):
assert(path in paths)
def test_search_list_key_with_separator():
tdict = {
"a": {
"b": {
"d": 'failure'
},
"/b/d": 'success'
}
}
res = dpath.util.search(tdict, ['a', '/b/d'])
assert(not 'b' in res['a'])
assert(res['a']['/b/d'] == 'success')
def test_search_return_list_globbed():
tdict = {
"a": {
"b": [
0,
1,
2]
}
}
res = dpath.util.search(tdict, '/a/b/[02]')
assert(isinstance(res['a']['b'], list))
assert(len(res['a']['b']) == 2)
assert(res['a']['b'] == [0, 2])
res = dpath.util.search(tdict, ['a', 'b', '[02]'])
assert(isinstance(res['a']['b'], list))
assert(len(res['a']['b']) == 2)
assert(res['a']['b'] == [0, 2])
def test_search_return_list_head():
tdict = {
"a": {
"b": [
0,
1,
2]
}
}
res = dpath.util.search(tdict, '/a/b')
assert(isinstance(res['a']['b'], list))
assert(len(res['a']['b']) == 3)
assert(res['a']['b'] == [0, 1, 2])
res = dpath.util.search(tdict, ['a', 'b'])
assert(isinstance(res['a']['b'], list))
assert(len(res['a']['b']) == 3)
assert(res['a']['b'] == [0, 1, 2])
def test_search_return_dict_head():
tdict = {
"a": {
"b": {
0: 0,
1: 1,
2: 2}
}
}
res = dpath.util.search(tdict, '/a/b')
assert(isinstance(res['a']['b'], dict))
assert(len(res['a']['b']) == 3)
assert(res['a']['b'] == {0: 0, 1: 1, 2: 2})
res = dpath.util.search(tdict, ['a', 'b'])
assert(isinstance(res['a']['b'], dict))
assert(len(res['a']['b']) == 3)
assert(res['a']['b'] == {0: 0, 1: 1, 2: 2})
"e": 1,
"f": 2
}
}
}
}
paths = [
'a/b/c/e',
'a/b/c/f'
]
for (path, value) in dpath.util.search(dict, '/**', yielded=True, afilter=afilter):
assert(path in paths)
assert("view_failure" not in dpath.util.search(dict, '/**', afilter=afilter)['a'])
assert("d" not in dpath.util.search(dict, '/**', afilter=afilter)['a']['b']['c'])
for (path, value) in dpath.util.search(dict, ['**'], yielded=True, afilter=afilter):
assert(path in paths)
assert("view_failure" not in dpath.util.search(dict, ['**'], afilter=afilter)['a'])
assert("d" not in dpath.util.search(dict, ['**'], afilter=afilter)['a']['b']['c'])
def run(req):
# Validate presence of partial dicts in response json
for path in list(req.test['outcomes']['response_json_contains'].keys()):
expected_value = req.test['outcomes']['response_json_contains'][path]
actual_value = dpath.util.search(req.req.json(), path)[path]
if expected_value == actual_value:
return req.pass_test("Body contains expected json value at path \"{0}\"".format(path))
else:
return req.fail_test("Invalid json value {0} at path \"{1}\", expecting {2}".format(actual_value, path, expected_value))
def search(self, path):
for p, d in dpath.util.search(self.data, list(path), True, self.separator):
yield tuple(p.split(self.separator)), d
def CreatePreInPostFixGrammar(definitions):
# partition by type of operator
infix = dpath.util.search(definitions, '/*/infix')
prefix = dpath.util.search(definitions, '/*/prefix')
postfix = dpath.util.search(definitions, '/*/postfix')
alternatives = dpath.util.search(definitions, '/*/alternatives')
# get the precedence orders
orders = list(set(dpath.util.values(definitions, '/*/*/order')))
orders.sort()
previousOrder = dict(zip(orders + ['max'], ['min'] + orders))
text = ''
# create grammar for alternatives
text += '\n# function names alternatives\n'
for key, value in alternatives.iteritems():
text += key + \