-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support and tests for callables (#108)
- Loading branch information
Showing
12 changed files
with
252 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class C: | ||
|
||
def __call__(self, x): | ||
return x * x | ||
|
||
|
||
c = C() | ||
a = c.__call__(5) | ||
assert a == 25 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class C: | ||
|
||
def __call__(self, x): | ||
return x * x | ||
|
||
|
||
c = C() | ||
a = c(5) | ||
assert a == 25 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class C(object): | ||
|
||
def __call__(self, x): | ||
return x * x | ||
|
||
|
||
c = C() | ||
a = c.__call__(5) | ||
assert a == 25 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class C(object): | ||
|
||
def __call__(self, x): | ||
return x * x | ||
|
||
|
||
c = C() | ||
a = c(5) | ||
assert a == 25 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class D: | ||
pass | ||
|
||
|
||
class C(D): | ||
|
||
def __call__(self, x): | ||
return x * x | ||
|
||
|
||
c = C() | ||
a = c.__call__(5) | ||
assert a == 25 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class D: | ||
pass | ||
|
||
|
||
class C(D): | ||
|
||
def __call__(self, x): | ||
return x * x | ||
|
||
|
||
c = C() | ||
a = c(5) | ||
assert a == 25 |
59 changes: 59 additions & 0 deletions
59
com.ibm.wala.cast.python.test/source/com/ibm/wala/cast/python/test/TestCallables.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.ibm.wala.cast.python.test; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import com.ibm.wala.ipa.callgraph.CGNode; | ||
import com.ibm.wala.ipa.callgraph.CallGraph; | ||
import com.ibm.wala.ipa.cha.ClassHierarchyException; | ||
import com.ibm.wala.util.CancelException; | ||
import java.io.IOException; | ||
import java.util.Iterator; | ||
import java.util.logging.Logger; | ||
import org.junit.Test; | ||
|
||
public class TestCallables extends TestPythonCallGraphShape { | ||
|
||
private static Logger logger = Logger.getLogger(TestCallables.class.getName()); | ||
|
||
@Test | ||
public void testCallables() | ||
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { | ||
final String[] testFileNames = { | ||
"callables.py", | ||
"callables2.py", | ||
"callables3.py", | ||
"callables4.py", | ||
"callables5.py", | ||
"callables6.py" | ||
}; | ||
|
||
for (String fileName : testFileNames) { | ||
CallGraph CG = process(fileName); | ||
boolean found = false; | ||
|
||
for (CGNode node : CG) { | ||
if (node.getMethod() | ||
.getDeclaringClass() | ||
.getName() | ||
.toString() | ||
.equals("Lscript " + fileName)) { | ||
|
||
for (Iterator<CGNode> it = CG.getSuccNodes(node); it.hasNext(); ) { | ||
CGNode callee = it.next(); | ||
|
||
logger.info("Found callee: " + callee.getMethod().getSignature()); | ||
|
||
if (callee | ||
.getMethod() | ||
.getDeclaringClass() | ||
.getName() | ||
.toString() | ||
.equals("L$script " + fileName + "/C/__call__")) found = true; | ||
} | ||
} | ||
} | ||
|
||
assertTrue("Expecting to find __call__ method trampoline in: " + fileName + ".", found); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.