

def test_supers(self):

    class A(object):

        def meth(self, a):
            return ('A(%r)' % a)
    self.assertEqual(A().meth(1), 'A(1)')

    class B(A):

        def __init__(self):
            self.__super = super(B, self)

        def meth(self, a):
            return (('B(%r)' % a) + self.__super.meth(a))
    self.assertEqual(B().meth(2), 'B(2)A(2)')

    class C(A):

        def meth(self, a):
            return (('C(%r)' % a) + self.__super.meth(a))
    C._C__super = super(C)
    self.assertEqual(C().meth(3), 'C(3)A(3)')

    class D(C, B):

        def meth(self, a):
            return (('D(%r)' % a) + super(D, self).meth(a))
    self.assertEqual(D().meth(4), 'D(4)C(4)B(4)A(4)')
    try:
        super(D, 42)
    except TypeError:
        pass
    else:
        self.fail("shouldn't allow super(D, 42)")
    try:
        super(D, C())
    except TypeError:
        pass
    else:
        self.fail("shouldn't allow super(D, C())")
    try:
        super(D).__get__(12)
    except TypeError:
        pass
    else:
        self.fail("shouldn't allow super(D).__get__(12)")
    try:
        super(D).__get__(C())
    except TypeError:
        pass
    else:
        self.fail("shouldn't allow super(D).__get__(C())")

    class DDbase(object):

        def getx(self):
            return 42
        x = property(getx)

    class DDsub(DDbase):

        def getx(self):
            return 'hello'
        x = property(getx)
    dd = DDsub()
    self.assertEqual(dd.x, 'hello')
    self.assertEqual(super(DDsub, dd).x, 42)

    class Base(object):
        aProp = property((lambda self: 'foo'))

    class Sub(Base):

        @classmethod
        def test(klass):
            return super(Sub, klass).aProp
    self.assertEqual(Sub.test(), Base.aProp)
    try:
        super(Base, kw=1)
    except TypeError:
        pass
    else:
        self.assertEqual("super shouldn't accept keyword args")

dataset/ETHPy150Open PythonCharmers/python-future/tests/test_future/test_super.py TestSuperFromTestDescrDotPy.test_supers/original