Skip to content

Commit 419449f

Browse files
committed
Python: default value for argN
1 parent 2409a78 commit 419449f

File tree

3 files changed

+93
-88
lines changed

3 files changed

+93
-88
lines changed

python/ql/test/experimental/dataflow/TestUtil/RoutingTest.qll

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,20 @@ abstract class RoutingTest extends InlineExpectationsTest {
2525
element = fromNode.toString() and
2626
(
2727
tag = this.flowTag() and
28-
value = "\"" + prettyNode(fromNode).replaceAll("\"", "'") + "\""
28+
if "\"" + tag + "\"" = fromValue(fromNode) then value = "" else value = fromValue(fromNode)
2929
or
3030
tag = "func" and
31-
not fromFunc(fromNode) = toFunc(toNode) and
32-
value = toFunc(toNode)
31+
value = toFunc(toNode) and
32+
not value = fromFunc(fromNode)
3333
)
3434
)
3535
}
3636

37+
pragma[inline]
38+
private string fromValue(DataFlow::Node fromNode) {
39+
result = "\"" + prettyNode(fromNode).replaceAll("\"", "'") + "\""
40+
}
41+
3742
pragma[inline]
3843
private string fromFunc(DataFlow::ArgumentNode fromNode) {
3944
result = fromNode.getCall().getNode().(CallNode).getFunction().getNode().(Name).getId()

python/ql/test/experimental/dataflow/coverage/argumentPassing.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ def argument_passing(
8686

8787
@expects(7)
8888
def test_argument_passing1():
89-
argument_passing(arg1, *(arg2, arg3, arg4), e=arg5, **{"f": arg6, "g": arg7}) #$ arg1="arg1" arg7="arg7" func=argument_passing MISSING: arg2="arg2" arg3="arg3 arg4="arg4" arg5="arg5" arg6="arg6"
89+
argument_passing(arg1, *(arg2, arg3, arg4), e=arg5, **{"f": arg6, "g": arg7}) #$ arg1 arg7 func=argument_passing MISSING: arg2 arg3="arg3 arg4 arg5 arg6
9090

9191

9292
@expects(7)
9393
def test_argument_passing2():
94-
argument_passing(arg1, arg2, arg3, f=arg6) #$ arg1="arg1" arg2="arg2" arg3="arg3"
94+
argument_passing(arg1, arg2, arg3, f=arg6) #$ arg1 arg2 arg3
9595

9696

9797
def with_pos_only(a, /, b):
@@ -101,9 +101,9 @@ def with_pos_only(a, /, b):
101101

102102
@expects(6)
103103
def test_pos_only():
104-
with_pos_only(arg1, arg2) #$ arg1="arg1" arg2="arg2"
105-
with_pos_only(arg1, b=arg2) #$ arg1="arg1" arg2="arg2"
106-
with_pos_only(arg1, *(arg2,)) #$ arg1="arg1" MISSING: arg2="arg2"
104+
with_pos_only(arg1, arg2) #$ arg1 arg2
105+
with_pos_only(arg1, b=arg2) #$ arg1 arg2
106+
with_pos_only(arg1, *(arg2,)) #$ arg1 MISSING: arg2
107107

108108

109109
def with_multiple_kw_args(a, b, c):
@@ -114,10 +114,10 @@ def with_multiple_kw_args(a, b, c):
114114

115115
@expects(12)
116116
def test_multiple_kw_args():
117-
with_multiple_kw_args(b=arg2, c=arg3, a=arg1) #$ arg1="arg1" arg2="arg2" arg3="arg3"
118-
with_multiple_kw_args(arg1, *(arg2,), arg3) #$ arg1="arg1" MISSING: arg2="arg2" arg3="arg3"
119-
with_multiple_kw_args(arg1, **{"c": arg3}, b=arg2) #$ arg1="arg1" arg3="arg3" func=with_multiple_kw_args MISSING: arg2="arg2"
120-
with_multiple_kw_args(**{"b": arg2}, **{"c": arg3}, **{"a": arg1}) #$ arg1="arg1" arg2="arg2" arg3="arg3" func=with_multiple_kw_args
117+
with_multiple_kw_args(b=arg2, c=arg3, a=arg1) #$ arg1 arg2 arg3
118+
with_multiple_kw_args(arg1, *(arg2,), arg3) #$ arg1 MISSING: arg2 arg3
119+
with_multiple_kw_args(arg1, **{"c": arg3}, b=arg2) #$ arg1 arg3 func=with_multiple_kw_args MISSING: arg2
120+
with_multiple_kw_args(**{"b": arg2}, **{"c": arg3}, **{"a": arg1}) #$ arg1 arg2 arg3 func=with_multiple_kw_args
121121

122122

123123
def with_default_arguments(a=arg1, b=arg2, c=arg3): # Need a mechanism to test default arguments
@@ -129,9 +129,9 @@ def with_default_arguments(a=arg1, b=arg2, c=arg3): # Need a mechanism to test
129129
@expects(12)
130130
def test_default_arguments():
131131
with_default_arguments()
132-
with_default_arguments(arg1) #$ arg1="arg1"
133-
with_default_arguments(b=arg2) #$ arg2="arg2"
134-
with_default_arguments(**{"c": arg3}) #$ arg3="arg3" func=with_default_arguments
132+
with_default_arguments(arg1) #$ arg1
133+
with_default_arguments(b=arg2) #$ arg2
134+
with_default_arguments(**{"c": arg3}) #$ arg3 func=with_default_arguments
135135

136136

137137
# Nested constructor pattern
@@ -157,55 +157,55 @@ def grab_baz(baz):
157157

158158
@expects(4)
159159
def test_grab():
160-
grab_foo_bar_baz(baz=arg3, bar=arg2, foo=arg1) #$ arg1="arg1" arg2="arg2" arg3="arg3" func=grab_bar_baz func=grab_baz
160+
grab_foo_bar_baz(baz=arg3, bar=arg2, foo=arg1) #$ arg1 arg2 arg3 func=grab_bar_baz func=grab_baz
161161

162162

163163
# All combinations
164164
def test_pos_pos():
165165
def with_pos(a):
166166
SINK1(a)
167167

168-
with_pos(arg1) #$ arg1="arg1" func=test_pos_pos.with_pos
168+
with_pos(arg1) #$ arg1 func=test_pos_pos.with_pos
169169

170170

171171
def test_pos_pos_only():
172172
def with_pos_only(a, /):
173173
SINK1(a)
174174

175-
with_pos_only(arg1) #$ arg1="arg1" func=test_pos_pos_only.with_pos_only
175+
with_pos_only(arg1) #$ arg1 func=test_pos_pos_only.with_pos_only
176176

177177

178178
def test_pos_star():
179179
def with_star(*a):
180180
if len(a) > 0:
181181
SINK1(a[0])
182182

183-
with_star(arg1) #$ arg1="arg1" func=test_pos_star.with_star
183+
with_star(arg1) #$ arg1 func=test_pos_star.with_star
184184

185185

186186
def test_pos_kw():
187187
def with_kw(a=""):
188188
SINK1(a)
189189

190-
with_kw(arg1) #$ arg1="arg1" func=test_pos_kw.with_kw
190+
with_kw(arg1) #$ arg1 func=test_pos_kw.with_kw
191191

192192

193193
def test_kw_pos():
194194
def with_pos(a):
195195
SINK1(a)
196196

197-
with_pos(a=arg1) #$ arg1="arg1" func=test_kw_pos.with_pos
197+
with_pos(a=arg1) #$ arg1 func=test_kw_pos.with_pos
198198

199199

200200
def test_kw_kw():
201201
def with_kw(a=""):
202202
SINK1(a)
203203

204-
with_kw(a=arg1) #$ arg1="arg1" func=test_kw_kw.with_kw
204+
with_kw(a=arg1) #$ arg1 func=test_kw_kw.with_kw
205205

206206

207207
def test_kw_doublestar():
208208
def with_doublestar(**a):
209209
SINK1(a["a"])
210210

211-
with_doublestar(a=arg1) #$ arg1="arg1" func=test_kw_doublestar.with_doublestar
211+
with_doublestar(a=arg1) #$ arg1 func=test_kw_doublestar.with_doublestar

0 commit comments

Comments
 (0)