Skip to content

Commit

Permalink
Add another calls test.
Browse files Browse the repository at this point in the history
Like calls1 but replace Foo.foo with Foo.__call__.
  • Loading branch information
khatchad committed Nov 30, 2023
1 parent f0f7679 commit 7062aac
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
57 changes: 57 additions & 0 deletions com.ibm.wala.cast.python.test/data/calls9.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
base_init = 10

def id(x):
return x

def call(x, y):
return x(y)

def foo(a,b):
return call(id, a+b)

class Foo(object):
base = base_init

def __call__(self, a, b):
self.contents = id(a+b+self.base)
return self.contents

print(Foo)

print(Foo.__call__)
print(Foo.base)

print(foo)
print(foo(1,2))

instance = Foo()
print(Foo.__call__(instance, 2,3))
print(instance.__call__(2,3))

f = instance.__call__
print(f);
print(f(3,4))

instance.f = foo
print(instance.f(4,5))
print(instance.f);

instance.__call__ = foo;
print(instance.__call__(5,6))
print(instance.__call__);

foo.x = foo;
print(foo.x(6,7));
print(foo.x);

x = Foo
print(x)
y = x()
print(y)
print(y.__call__(7,8))

def nothing():
return 0

z = id(nothing)
z()
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,35 @@ public Void performAnalysis(PropagationCallGraphBuilder builder) throws CancelEx
CG);
}

protected static final Object[][] assertionsCalls9 =
new Object[][] {
new Object[] {ROOT, new String[] {"script calls9.py"}},
new Object[] {
"script calls9.py",
new String[] {
"script calls9.py/Foo",
"script calls9.py/foo",
"$script calls9.py/Foo/__call__:trampoline3",
"script calls9.py/id",
"script calls9.py/nothing"
}
},
new Object[] {
"$script calls9.py/Foo/__call__:trampoline3",
new String[] {"script calls9.py/Foo/__call__"}
},
new Object[] {"script calls9.py/call", new String[] {"script calls9.py/id"}},
new Object[] {"script calls9.py/Foo/__call__", new String[] {"script calls9.py/id"}},
new Object[] {"script calls9.py/foo", new String[] {"script calls9.py/call"}}
};

@Test
public void testCalls9()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
CallGraph CG = process("calls9.py");
verifyGraphAssertions(CG, assertionsCalls9);
}

protected static final Object[][] assertionsDefaultValues =
new Object[][] {
new Object[] {ROOT, new String[] {"script defaultValuesTest.py"}},
Expand Down

0 comments on commit 7062aac

Please sign in to comment.