

def test_inheritance_and_super(self):

    class MyClass1():

        def __init__(self):
            self.bar = 7

        def add(self, x=1):
            self.bar += x

        def addTwo(self):
            self.bar += 2

    class MyClass2(MyClass1):

        def addTwo(self):
            super().addTwo()
            self.bar += 1

    class MyClass3(MyClass2):

        def addTwo(self):
            super().addTwo()
            self.bar += 1

        def addFour(self):
            super(MyClass3, self).add(4)
    code = ((py2js(MyClass1) + py2js(MyClass2)) + py2js(MyClass3))
    code += 'var m1=new MyClass1(), m2=new MyClass2(), m3=new MyClass3();'
    assert (evaljs((code + 'm1.bar;')) == '7')
    assert (evaljs((code + 'm1.add();m1.bar;')) == '8')
    assert (evaljs((code + 'm1.addTwo();m1.bar;')) == '9')
    assert (evaljs((code + 'm2.bar;')) == '7')
    assert (evaljs((code + 'm2.add();m2.bar;')) == '8')
    assert (evaljs((code + 'm2.addTwo();m2.bar;')) == '10')
    assert (evaljs((code + 'm3.bar;')) == '7')
    assert (evaljs((code + 'm3.add();m3.bar;')) == '8')
    assert (evaljs((code + 'm3.addTwo();m3.bar;')) == '11')
    assert (evaljs((code + 'm3.addFour();m3.bar;')) == '11')
    assert (evaljs((code + 'm1 instanceof MyClass3;')) == 'false')
    assert (evaljs((code + 'm1 instanceof MyClass2;')) == 'false')
    assert (evaljs((code + 'm1 instanceof MyClass1;')) == 'true')
    assert (evaljs((code + 'm1 instanceof Object;')) == 'true')
    assert (evaljs((code + 'm2 instanceof MyClass3;')) == 'false')
    assert (evaljs((code + 'm2 instanceof MyClass2;')) == 'true')
    assert (evaljs((code + 'm2 instanceof MyClass1;')) == 'true')
    assert (evaljs((code + 'm2 instanceof Object;')) == 'true')
    assert (evaljs((code + 'm3 instanceof MyClass3;')) == 'true')
    assert (evaljs((self + 'm3 instanceof MyClass2;')) == 'true')
    assert (evaljs((code + 'm3 instanceof MyClass1;')) == 'true')
    assert (evaljs((code + 'm3 instanceof Object;')) == 'true')

dataset/ETHPy150Open zoofIO/flexx/flexx/pyscript/tests/test_parser2.py TestClasses.test_inheritance_and_super/VarMisuse@457/771 `code`->`self`