summary refs log tree commit diff
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2014-09-17 15:56:40 +0100
committerPaul "LeoNerd" Evans <paul@matrix.org>2014-09-17 15:56:40 +0100
commit7aacd6834a17c84dacba875f362a8236aaaa2fb0 (patch)
tree97873b859dc5f34820451616cadabfa41eeedd04
parentMore RoomStore tests (diff)
downloadsynapse-7aacd6834a17c84dacba875f362a8236aaaa2fb0.tar.xz
Added a useful unit test primitive for asserting object attributes
-rw-r--r--tests/unittest.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/unittest.py b/tests/unittest.py
index fb97fb1148..a9c0e05541 100644
--- a/tests/unittest.py
+++ b/tests/unittest.py
@@ -71,6 +71,17 @@ class TestCase(unittest.TestCase):
             logging.getLogger().setLevel(level)
             return orig()
 
+    def assertObjectHasAttributes(self, attrs, obj):
+        """Asserts that the given object has each of the attributes given, and
+        that the value of each matches according to assertEquals."""
+        for (key, value) in attrs.items():
+            if not hasattr(obj, key):
+                raise AssertionError("Expected obj to have a '.%s'" % key)
+            try:
+                self.assertEquals(attrs[key], getattr(obj, key))
+            except AssertionError as e:
+                raise (type(e))(e.message + " for '.%s'" % key)
+
 
 def DEBUG(target):
     """A decorator to set the .loglevel attribute to logging.DEBUG.