diff options
author | Peter Stachowski <peter@tesora.com> | 2015-09-14 11:29:12 -0400 |
---|---|---|
committer | Tony Breeds <tony@bakeyournoodle.com> | 2016-04-07 14:26:41 +1000 |
commit | 9f5de06a2d9071ecb8c797fcb772f54bc62f5fa4 (patch) | |
tree | 072709560f3c28d03122b30dc6a699bdaad3fde8 | |
parent | 299d2de4fa1f46be8a023207568dbf81cd67b530 (diff) | |
download | trove-9f5de06a2d9071ecb8c797fcb772f54bc62f5fa4.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
(cherry picked from commit 7a9e02a1fa50fdccf0d06e9706a4bec25f127c5c)
-rw-r--r-- | trove/tests/examples/client.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/trove/tests/examples/client.py b/trove/tests/examples/client.py index 5d4a38e1..04512e5a 100644 --- a/trove/tests/examples/client.py +++ b/trove/tests/examples/client.py @@ -192,15 +192,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) |