From 2dc69fc8968e62443d862aa60da99bcc9c7669af Mon Sep 17 00:00:00 2001 From: Graham Dumpleton Date: Thu, 12 Sep 2013 20:46:04 +1000 Subject: [PATCH] Unit tests for manipulating as yet un-initialised base class in derived class __new__() and __init__(). --- tests/test_object_proxy.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_object_proxy.py b/tests/test_object_proxy.py index aa5677a..dcc8373 100644 --- a/tests/test_object_proxy.py +++ b/tests/test_object_proxy.py @@ -1178,5 +1178,36 @@ class TestObjectRepresentationObjectProxy(unittest.TestCase): self.assertNotEqual(repr(value).find('ObjectProxy at'), -1) +class TestDerivedClassCreation(unittest.TestCase): + + def test_derived_new(self): + + class DerivedObjectProxy(wrapt.ObjectProxy): + + def __new__(cls, wrapped): + instance = super(DerivedObjectProxy, cls).__new__(cls, wrapped) + instance.__init__(wrapped) + + def __init__(self, wrapped): + super(DerivedObjectProxy, self).__init__(wrapped) + + def function(): + pass + + obj = DerivedObjectProxy(function) + + def test_derived_setattr(self): + + class DerivedObjectProxy(wrapt.ObjectProxy): + + def __init__(self, wrapped): + self._self_attribute = True + super(DerivedObjectProxy, self).__init__(wrapped) + + def function(): + pass + + obj = DerivedObjectProxy(function) + if __name__ == '__main__': unittest.main()