Skip to content

Commit 597a841

Browse files
committed
Python: Add test of API::moduleImport with dots
This is currently semi-works -- the import is allowed, but doesn't always work when used :|
1 parent e0c74d4 commit 597a841

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
moduleImportWithDots
2+
| file://:0:0:0:0 | ModuleImport moduleImport("a").getMember("b").getMember("c").getMember("d") |
3+
doesntFullyWork
4+
| test.py:28:10:28:17 | ControlFlowNode for method() |
5+
works
6+
| test.py:25:6:25:18 | ControlFlowNode for Attribute() |
7+
| test.py:28:10:28:17 | ControlFlowNode for method() |
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
private import python
2+
private import semmle.python.ApiGraphs
3+
4+
query API::Node moduleImportWithDots() { result = API::moduleImport("a.b.c.d") }
5+
6+
query API::CallNode doesntFullyWork() {
7+
result = API::moduleImport("a.b.c.d").getMember("method").getACall()
8+
}
9+
10+
query API::CallNode works() {
11+
result =
12+
API::moduleImport("a")
13+
.getMember("b")
14+
.getMember("c")
15+
.getMember("d")
16+
.getMember("method")
17+
.getACall()
18+
}

python/ql/test/library-tests/ApiGraphs/py3/test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
x5 = abcd.method() #$ use=moduleImport("a").getMember("b").getMember("c").getMember("d").getMember("method").getReturn()
2626

27+
from a.b.c.d import method
28+
x5_alt = method() #$ use=moduleImport("a").getMember("b").getMember("c").getMember("d").getMember("method").getReturn()
29+
2730
from a6 import m6 #$ use=moduleImport("a6").getMember("m6")
2831

2932
x6 = m6().foo().bar() #$ use=moduleImport("a6").getMember("m6").getReturn().getMember("foo").getReturn().getMember("bar").getReturn()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
// Note: This is not using standard inline-expectation tests, so will not alert if you
2+
// have not manually added an annotation to a line!
13
import TestUtilities.VerifyApiGraphs

0 commit comments

Comments
 (0)