def test_overloaded_meth_string(self): C = Instance("test", ROOT, {}, { 'foo': overload(meth(Meth([Char], Signed)), meth(Meth([String], Float)), resolver=OverloadingResolver), 'bar': overload(meth(Meth([Signed], Char)), meth(Meth([Float], String)), resolver=OverloadingResolver) }) def fn1(): return new(C).foo('a') def fn2(): return new(C).foo('aa') def fn3(x): return new(C).bar(x) a = RPythonAnnotator() assert isinstance(a.build_types(fn1, []), annmodel.SomeInteger) assert isinstance(a.build_types(fn2, []), annmodel.SomeFloat) assert isinstance(a.build_types(fn3, [int]), annmodel.SomeChar) assert isinstance(a.build_types(fn3, [float]), annmodel.SomeString)
def test_checkvirtual_simple(): A = Instance("A", ROOT) B = Instance("B", A) addMethods(A, {"foo": meth(Meth([], Void)), "bar": meth(Meth([], Void))}) addMethods(B, {"foo": meth(Meth([], Void))}) check_virtual_methods() assert A._methods["foo"]._virtual == True assert A._methods["bar"]._virtual == False assert B._methods["foo"]._virtual == False
def test_checkvirtual_brother(): A = Instance("A", ROOT) B1 = Instance("B1", A) B2 = Instance("B2", A) addMethods(A, {"foo": meth(Meth([], Void)), "bar": meth(Meth([], Void))}) addMethods(B1, {"foo": meth(Meth([], Void))}) check_virtual_methods() assert A._methods["foo"]._virtual == True assert A._methods["bar"]._virtual == False assert B1._methods["foo"]._virtual == False assert "foo" not in B2._methods
def test_checkvirtual_deep(): A = Instance("A", ROOT) B = Instance("B", A) C = Instance("C", B) addMethods(A, {"foo": meth(Meth([], Void)), "bar": meth(Meth([], Void))}) addMethods(C, {"foo": meth(Meth([], Void))}) check_virtual_methods() assert A._methods["foo"]._virtual == True assert A._methods["bar"]._virtual == False assert "foo" not in B._methods assert C._methods["foo"]._virtual == False
def test_nonvirtual(): A = Instance("A", ROOT) addMethods(A, {"foo": meth(Meth([], Void))}) check_virtual_methods() assert A._methods["foo"]._virtual == False