Unit tests for manipulating as yet un-initialised base class in derived class __new__() and __init__().

This commit is contained in:
Graham Dumpleton
2013-09-12 20:46:04 +10:00
parent af9131ba96
commit 2dc69fc896

View File

@@ -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()