← Back to team overview

dulwich-users team mailing list archive

[PATCH 6/8] test/utils: Return non-__slot__ subclasses from make_object.

 

From: Dave Borowitz <dborowitz@xxxxxxxxxx>

Change-Id: I4808d93cd78d2ace4c30ad0b5e10e3c47cb05978
---
 dulwich/tests/utils.py |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/dulwich/tests/utils.py b/dulwich/tests/utils.py
index f2ae54a..f581a12 100644
--- a/dulwich/tests/utils.py
+++ b/dulwich/tests/utils.py
@@ -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
-- 
1.7.1




References