Python: Add simple test of AttrRead/AttrWrite

This commit is contained in:
Rasmus Wriedt Larsen
2022-02-02 10:45:21 +01:00
parent 51bc6dcf7e
commit fb6b8eb394
5 changed files with 31 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
| test.py:6:9:6:16 | ControlFlowNode for Attribute | test.py:6:9:6:12 | ControlFlowNode for self | foo |
| test.py:9:1:9:9 | ControlFlowNode for Attribute | test.py:9:1:9:5 | ControlFlowNode for myobj | foo |
| test.py:10:1:10:9 | ControlFlowNode for Attribute | test.py:10:1:10:5 | ControlFlowNode for myobj | foo |
| test.py:13:1:13:21 | ControlFlowNode for getattr() | test.py:13:9:13:13 | ControlFlowNode for myobj | foo |

View File

@@ -0,0 +1,5 @@
import python
private import semmle.python.dataflow.new.DataFlow
from DataFlow::AttrRead read
select read, read.getObject(), read.getAttributeName()

View File

@@ -0,0 +1,4 @@
| 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 |
| 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 |
| 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 |
| 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 |

View File

@@ -0,0 +1,5 @@
import python
private import semmle.python.dataflow.new.DataFlow
from DataFlow::AttrWrite write
select write, write.getObject(), write.getAttributeName(), write.getValue()

View File

@@ -0,0 +1,13 @@
# This file is a simple test of which nodes are included with AttrRead/AttrWrite.
# For actual data-flow tests, see fieldflow/ dir.
class MyObj(object):
def __init__(self, foo):
self.foo = foo
myobj = MyObj("foo")
myobj.foo = "bar"
myobj.foo
setattr(myobj, "foo", 42)
getattr(myobj, "foo")