def test_mutable_bases():
    if verbose:
        print "Testing mutable bases..."
    # stuff that should work:
    class C(object):
        pass
    class C2(object):
        def __getattribute__(self, attr):
            if attr == 'a':
                return 2
            else:
                return super(C2, self).__getattribute__(attr)
        def meth(self):
            return 1
    class D(C):
        pass
    class E(D):
        pass
    d = D()
    e = E()
    D.__bases__ = (C,)
    D.__bases__ = (C2,)
    vereq(d.meth(), 1)
    vereq(e.meth(), 1)
    vereq(d.a, 2)
    vereq(e.a, 2)
    vereq(C2.__subclasses__(), [D])

    # stuff that shouldn't:
    class L(list):
        pass

    try:
        L.__bases__ = (dict,)
    except TypeError:
        pass
    else:
        raise TestFailed, "shouldn't turn list subclass into dict subclass"

    try:
        list.__bases__ = (dict,)
    except TypeError:
        pass
    else:
        raise TestFailed, "shouldn't be able to assign to list.__bases__"

    try:
        del D.__bases__
    except TypeError:
        pass
    else:
        raise TestFailed, "shouldn't be able to delete .__bases__"

    try:
        D.__bases__ = ()
    except __HOLE__, msg:
        if str(msg) == "a new-style class can't have only classic bases":
            raise TestFailed, "wrong error message for .__bases__ = ()"
    else:
        raise TestFailed, "shouldn't be able to set .__bases__ to ()"

    try:
        D.__bases__ = (D,)
    except TypeError:
        pass
    else:
        # actually, we'll have crashed by here...
        raise TestFailed, "shouldn't be able to create inheritance cycles"

    try:
        D.__bases__ = (C, C)
    except TypeError:
        pass
    else:
        raise TestFailed, "didn't detect repeated base classes"

    try:
        D.__bases__ = (E,)
    except TypeError:
        pass
    else:
        raise TestFailed, "shouldn't be able to create inheritance cycles"

    # let's throw a classic class into the mix:
    class Classic:
        def meth2(self):
            return 3

    D.__bases__ = (C, Classic)

    vereq(d.meth2(), 3)
    vereq(e.meth2(), 3)
    try:
        d.a
    except AttributeError:
        pass
    else:
        raise TestFailed, "attribute should have vanished"

    try:
        D.__bases__ = (Classic,)
    except TypeError:
        pass
    else:
        raise TestFailed, "new-style class must have a new-style base"
dataset/ETHPy150Open azoft-dev-team/imagrium/env/Lib/test/test_descr.py/test_mutable_bases