summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Stachowski <peter@tesora.com>2015-09-14 11:29:12 -0400
committerPeter Stachowski <peter@tesora.com>2015-09-14 12:01:00 -0400
commit7a9e02a1fa50fdccf0d06e9706a4bec25f127c5c (patch)
treea7523f42feff6487d3eb85c47e7f56ff4d608914
parent0c813d068b0d69fd141697378d5854389d22e282 (diff)
downloadtrove-7a9e02a1fa50fdccf0d06e9706a4bec25f127c5c.tar.gz
Fix get_flavors test by sorting json output
The get_flavors unit test sometimes fails as the list can come back in a different order. This causes the json comparison to inacurately claim that the content is different. Since we don't care what order the json data is stored, this comparison is now done on a sorted data set. Closes-Bug: #1437179 Change-Id: I92eaa1c98f5a58ce124210f2b6a2136dfc573a29
-rw-r--r--trove/tests/examples/client.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/trove/tests/examples/client.py b/trove/tests/examples/client.py
index f8fa1a01..98522379 100644
--- a/trove/tests/examples/client.py
+++ b/trove/tests/examples/client.py
@@ -193,15 +193,26 @@ class SnippetWriter(object):
fail('Error: output files differ for %s:\n%s'
% (filename, diff))
+ def order_json(json_obj):
+ """Sort the json object so that it can be compared properly."""
+ if isinstance(json_obj, list):
+ return sorted(order_json(elem) for elem in json_obj)
+ if isinstance(json_obj, dict):
+ return sorted(
+ (key, order_json(value))
+ for key, value in json_obj.items())
+ else:
+ return json_obj
+
def assert_json_matches(original):
try:
- expected = json.loads(original)
- actual = json.loads(output)
+ expected_json = json.loads(original)
+ actual_json = json.loads(output)
except ValueError:
fail('Invalid json!\nExpected: %s\nActual: %s'
% (original, output))
- if expected != actual:
+ if order_json(expected_json) != order_json(actual_json):
# Re-Use the same failure output if the json is different
assert_file_matches(original)