MCPcopy Create free account
hub / github.com/ElementsProject/elements / assert_array_result

Function assert_array_result

test/functional/test_framework/util.py:178–205  ·  view source on GitHub ↗

Pass in array of JSON objects, a dictionary with key/value pairs to match against, and another dictionary with expected key/value pairs. If the should_not_find flag is true, to_match should not be found in object_array

(object_array, to_match, expected, should_not_find=False)

Source from the content-addressed store, hash-verified

176
177
178def assert_array_result(object_array, to_match, expected, should_not_find=False):
179 """
180 Pass in array of JSON objects, a dictionary with key/value pairs
181 to match against, and another dictionary with expected key/value
182 pairs.
183 If the should_not_find flag is true, to_match should not be found
184 in object_array
185 """
186 if should_not_find:
187 assert_equal(expected, {})
188 num_matched = 0
189 for item in object_array:
190 all_match = True
191 for key, value in to_match.items():
192 if item[key] != value:
193 all_match = False
194 if not all_match:
195 continue
196 elif should_not_find:
197 num_matched = num_matched + 1
198 for key, value in expected.items():
199 if item[key] != value:
200 raise AssertionError("%s : expected %s=%s" % (str(item), str(key), str(value)))
201 num_matched = num_matched + 1
202 if num_matched == 0 and not should_not_find:
203 raise AssertionError("No objects matched %s" % (str(to_match)))
204 if num_matched > 0 and should_not_find:
205 raise AssertionError("Objects were found %s" % (str(to_match)))
206
207
208# Utility functions

Callers 6

test_no_blockhashMethod · 0.90
assert_categoryMethod · 0.90
run_testMethod · 0.90
run_rbf_opt_in_testMethod · 0.90
run_testMethod · 0.90
run_testMethod · 0.90

Calls 2

assert_equalFunction · 0.70
itemsMethod · 0.45

Tested by 1

test_no_blockhashMethod · 0.72