diff options
author | Rick Harris <rick.harris@rackspace.com> | 2011-03-14 20:38:05 +0000 |
---|---|---|
committer | Rick Harris <rick.harris@rackspace.com> | 2011-03-14 20:38:05 +0000 |
commit | 7fe5052f9e8dbaebce45b44a545be9707f6480a6 (patch) | |
tree | 012adf91b0805f592e54ebf0a0c99414c4c48dbb /nova/test.py | |
parent | 7fde254ec53aeb88301e5592853961b2b9c87ef4 (diff) | |
download | nova-7fe5052f9e8dbaebce45b44a545be9707f6480a6.tar.gz nova-7fe5052f9e8dbaebce45b44a545be9707f6480a6.tar.xz nova-7fe5052f9e8dbaebce45b44a545be9707f6480a6.zip |
Adding instance_id as Glance image_property
Diffstat (limited to 'nova/test.py')
-rw-r--r-- | nova/test.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/nova/test.py b/nova/test.py index d8a47464f..c41551bf3 100644 --- a/nova/test.py +++ b/nova/test.py @@ -150,3 +150,34 @@ class TestCase(unittest.TestCase): _wrapped.func_name = self.originalAttach.func_name rpc.Consumer.attach_to_eventlet = _wrapped + + # Useful assertions + def assertDictMatch(self, d1, d2): + """Assert two dicts are equivalent. + + This is a 'deep' match in the sense that it handles nested + dictionaries appropriately. + """ + def raise_assertion(msg): + d1str = str(d1) + d2str = str(d2) + base_msg = ("Dictionaries do not match. %(msg)s d1: %(d1str)s " + "d2: %(d2str)s" % locals()) + raise AssertionError(base_msg) + + d1keys = set(d1.keys()) + d2keys = set(d2.keys()) + if d1keys != d2keys: + d1only = d1keys - d2keys + d2only = d2keys - d1keys + raise_assertion("Keys in d1 and not d2: %(d1only)s. " + "Keys in d2 and not d1: %(d2only)s" % locals()) + + for key in d1keys: + d1value = d1[key] + d2value = d2[key] + if hasattr(d1value, 'keys') and hasattr(d2value, 'keys'): + self.assertDictMatch(d1value, d2value) + elif d1value != d2value: + raise_assertion("d1['%(key)s']=%(d1value)s != " + "d2['%(key)s']=%(d2value)s" % locals()) |