MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / assert_array_result

Function assert_array_result

test/functional/test_framework/util.py:143–170  ·  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

141 "String %r contains invalid characters for a hash." % string)
142
143def assert_array_result(object_array, to_match, expected, should_not_find=False):
144 """
145 Pass in array of JSON objects, a dictionary with key/value pairs
146 to match against, and another dictionary with expected key/value
147 pairs.
148 If the should_not_find flag is true, to_match should not be found
149 in object_array
150 """
151 if should_not_find:
152 assert_equal(expected, {})
153 num_matched = 0
154 for item in object_array:
155 all_match = True
156 for key, value in to_match.items():
157 if item[key] != value:
158 all_match = False
159 if not all_match:
160 continue
161 elif should_not_find:
162 num_matched = num_matched + 1
163 for key, value in expected.items():
164 if item[key] != value:
165 raise AssertionError("%s : expected %s=%s" % (str(item), str(key), str(value)))
166 num_matched = num_matched + 1
167 if num_matched == 0 and not should_not_find:
168 raise AssertionError("No objects matched %s" % (str(to_match)))
169 if num_matched > 0 and should_not_find:
170 raise AssertionError("Objects were found %s" % (str(to_match)))
171
172# Utility functions
173###################

Callers 5

test_no_blockhashMethod · 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.85
itemsMethod · 0.80

Tested by 1

test_no_blockhashMethod · 0.72