Skip to content

Commit fb6b8eb

Browse files
committed
Python: Add simple test of AttrRead/AttrWrite
1 parent 51bc6dc commit fb6b8eb

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| test.py:6:9:6:16 | ControlFlowNode for Attribute | test.py:6:9:6:12 | ControlFlowNode for self | foo |
2+
| test.py:9:1:9:9 | ControlFlowNode for Attribute | test.py:9:1:9:5 | ControlFlowNode for myobj | foo |
3+
| test.py:10:1:10:9 | ControlFlowNode for Attribute | test.py:10:1:10:5 | ControlFlowNode for myobj | foo |
4+
| test.py:13:1:13:21 | ControlFlowNode for getattr() | test.py:13:9:13:13 | ControlFlowNode for myobj | foo |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import python
2+
private import semmle.python.dataflow.new.DataFlow
3+
4+
from DataFlow::AttrRead read
5+
select read, read.getObject(), read.getAttributeName()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| test.py:5:9:5:16 | ControlFlowNode for __init__ | test.py:4:1:4:20 | ControlFlowNode for ClassExpr | __init__ | test.py:5:5:5:28 | ControlFlowNode for FunctionExpr |
2+
| test.py:6:9:6:16 | ControlFlowNode for Attribute | test.py:6:9:6:12 | ControlFlowNode for self | foo | test.py:6:20:6:22 | ControlFlowNode for foo |
3+
| test.py:9:1:9:9 | ControlFlowNode for Attribute | test.py:9:1:9:5 | ControlFlowNode for myobj | foo | test.py:9:13:9:17 | ControlFlowNode for Str |
4+
| test.py:12:1:12:25 | ControlFlowNode for setattr() | test.py:12:9:12:13 | ControlFlowNode for myobj | foo | test.py:12:23:12:24 | ControlFlowNode for IntegerLiteral |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import python
2+
private import semmle.python.dataflow.new.DataFlow
3+
4+
from DataFlow::AttrWrite write
5+
select write, write.getObject(), write.getAttributeName(), write.getValue()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This file is a simple test of which nodes are included with AttrRead/AttrWrite.
2+
# For actual data-flow tests, see fieldflow/ dir.
3+
4+
class MyObj(object):
5+
def __init__(self, foo):
6+
self.foo = foo
7+
8+
myobj = MyObj("foo")
9+
myobj.foo = "bar"
10+
myobj.foo
11+
12+
setattr(myobj, "foo", 42)
13+
getattr(myobj, "foo")

0 commit comments

Comments
 (0)