in shims/qpid-proton-python/src/amqp_complex_types_test/Receiver.py [0:0]
def check_maps_equal(map1, map2):
"""
Check two Proton maps are equal. Equality ignores map element ordering, and must make allowances
for floating point indexes that may have small rounding error differences.
eg {1.23: 'a', 25: 'b'} and {25: 'b', 1.230000001234: 'a'} are equal.
NOTE: At this point, map indexes may only be AMQP simple types, as the current Proton Python implementation
does not support them.
"""
# Check params are maps
if not isinstance(map1, dict) or not isinstance(map2, dict):
return False
# Check list sizes equal
if len(map1) != len(map2):
return False
# Compare key sets of maps
key_list_1 = list(map1.keys())
key_list_2 = list(map2.keys())
try:
map1_to_map2_index = AmqpComplexTypesTestReceiver.check_map_keys_equal(key_list_1, key_list_2)
except InteropTestError as err:
print('Receiver: %s' % err, file=sys.stderr)
return False
# Compare values of maps
# We need to use the actual keys from each map otherwise KeyError failures will occur for float keys
# which have small rounding differences between them. map1_to_map2_index provides a mapping for the
# keys in map2 relative to the keys in map1 (as the map element ordering may not be the same).
for key1_index, key1 in enumerate(key_list_1):
val1 = map1[key1]
val2 = map2[key_list_2[map1_to_map2_index[key1_index]]]
if isinstance(val1, proton.Array):
if not AmqpComplexTypesTestReceiver.check_arrays_equal(val1, val2):
return False
elif isinstance(val1, list):
if not AmqpComplexTypesTestReceiver.check_lists_equal(val1, val2):
return False
elif isinstance(val1, dict):
if not AmqpComplexTypesTestReceiver.check_maps_equal(val1, val2):
return False
else:
if not AmqpComplexTypesTestReceiver.check_simple_values_equal(val1, val2):
return False
return True