test/utils: Return non-__slot__ subclasses from make_object.
[jelmer/dulwich-libgit2.git] / dulwich / tests / utils.py
index f2ae54ac07cd8f8213c6c184a2a32d0ee57b6503..f581a124933fc0e8c5eb3d2cf5ab3b9406f64961 100644 (file)
@@ -57,10 +57,23 @@ def tear_down_repo(repo):
 def make_object(cls, **attrs):
     """Make an object for testing and assign some members.
 
+    This method creates a new subclass to allow arbitrary attribute
+    reassignment, which is not otherwise possible with objects having __slots__.
+
     :param attrs: dict of attributes to set on the new object.
     :return: A newly initialized object of type cls.
     """
-    obj = cls()
+
+    class TestObject(cls):
+        """Class that inherits from the given class, but without __slots__.
+
+        Note that classes with __slots__ can't have arbitrary attributes monkey-
+        patched in, so this is a class that is exactly the same only with a
+        __dict__ instead of __slots__.
+        """
+        pass
+
+    obj = TestObject()
     for name, value in attrs.iteritems():
         setattr(obj, name, value)
     return obj