Skip to content

Commit 8f599fa

Browse files
committed
Python: Rewrite inline expectation tests to use parameterized module
1 parent 49993b0 commit 8f599fa

File tree

28 files changed

+105
-84
lines changed

28 files changed

+105
-84
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
failures
2+
testFailures

python/ql/test/experimental/dataflow/calls/DataFlowCallTest.ql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ import semmle.python.dataflow.new.internal.DataFlowDispatch as DataFlowDispatch
44
import TestUtilities.InlineExpectationsTest
55
private import semmle.python.dataflow.new.internal.PrintNode
66

7-
class DataFlowCallTest extends InlineExpectationsTest {
8-
DataFlowCallTest() { this = "DataFlowCallTest" }
9-
10-
override string getARelevantTag() {
7+
module DataFlowCallTest implements TestSig {
8+
string getARelevantTag() {
119
result in ["call", "callType"]
1210
or
1311
result = "arg[" + any(DataFlowDispatch::ArgumentPosition pos).toString() + "]"
1412
}
1513

16-
override predicate hasActualResult(Location location, string element, string tag, string value) {
14+
predicate hasActualResult(Location location, string element, string tag, string value) {
1715
exists(location.getFile().getRelativePath()) and
1816
exists(DataFlowDispatch::DataFlowCall call |
1917
location = call.getLocation() and
@@ -35,3 +33,5 @@ class DataFlowCallTest extends InlineExpectationsTest {
3533
)
3634
}
3735
}
36+
37+
import MakeTest<DataFlowCallTest>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
failures
2+
testFailures

python/ql/test/experimental/dataflow/global-flow/accesses.ql

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import python
22
import semmle.python.dataflow.new.DataFlow
33
import TestUtilities.InlineExpectationsTest
44

5-
class GlobalReadTest extends InlineExpectationsTest {
6-
GlobalReadTest() { this = "GlobalReadTest" }
5+
module GlobalReadTest implements TestSig {
6+
string getARelevantTag() { result = "reads" }
77

8-
override string getARelevantTag() { result = "reads" }
9-
10-
override predicate hasActualResult(Location location, string element, string tag, string value) {
8+
predicate hasActualResult(Location location, string element, string tag, string value) {
119
exists(DataFlow::ModuleVariableNode n, DataFlow::Node read |
1210
read = n.getARead() and
1311
value = n.getVariable().getId() and
@@ -19,12 +17,10 @@ class GlobalReadTest extends InlineExpectationsTest {
1917
}
2018
}
2119

22-
class GlobalWriteTest extends InlineExpectationsTest {
23-
GlobalWriteTest() { this = "GlobalWriteTest" }
24-
25-
override string getARelevantTag() { result = "writes" }
20+
module GlobalWriteTest implements TestSig {
21+
string getARelevantTag() { result = "writes" }
2622

27-
override predicate hasActualResult(Location location, string element, string tag, string value) {
23+
predicate hasActualResult(Location location, string element, string tag, string value) {
2824
exists(DataFlow::ModuleVariableNode n, DataFlow::Node read |
2925
read = n.getAWrite() and
3026
value = n.getVariable().getId() and
@@ -34,3 +30,5 @@ class GlobalWriteTest extends InlineExpectationsTest {
3430
)
3531
}
3632
}
33+
34+
import MakeTest<MergeTests<GlobalReadTest, GlobalWriteTest>>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
failures
2+
testFailures

python/ql/test/experimental/dataflow/sensitive-data/TestSensitiveDataSources.ql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ import TestUtilities.InlineExpectationsTest
88
import semmle.python.dataflow.new.SensitiveDataSources
99
private import semmle.python.ApiGraphs
1010

11-
class SensitiveDataSourcesTest extends InlineExpectationsTest {
12-
SensitiveDataSourcesTest() { this = "SensitiveDataSourcesTest" }
11+
module SensitiveDataSourcesTest implements TestSig {
12+
string getARelevantTag() { result in ["SensitiveDataSource", "SensitiveUse"] }
1313

14-
override string getARelevantTag() { result in ["SensitiveDataSource", "SensitiveUse"] }
15-
16-
override predicate hasActualResult(Location location, string element, string tag, string value) {
14+
predicate hasActualResult(Location location, string element, string tag, string value) {
1715
exists(location.getFile().getRelativePath()) and
1816
exists(SensitiveDataSource source |
1917
location = source.getLocation() and
@@ -32,6 +30,8 @@ class SensitiveDataSourcesTest extends InlineExpectationsTest {
3230
}
3331
}
3432

33+
import MakeTest<SensitiveDataSourcesTest>
34+
3535
class SensitiveUseConfiguration extends TaintTracking::Configuration {
3636
SensitiveUseConfiguration() { this = "SensitiveUseConfiguration" }
3737

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
failures
2+
testFailures

python/ql/test/experimental/dataflow/variable-capture/CaptureTest.ql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ import semmle.python.dataflow.new.DataFlow
33
import TestUtilities.InlineExpectationsTest
44
import experimental.dataflow.testConfig
55

6-
class CaptureTest extends InlineExpectationsTest {
7-
CaptureTest() { this = "CaptureTest" }
6+
module CaptureTest implements TestSig {
7+
string getARelevantTag() { result = "captured" }
88

9-
override string getARelevantTag() { result = "captured" }
10-
11-
override predicate hasActualResult(Location location, string element, string tag, string value) {
9+
predicate hasActualResult(Location location, string element, string tag, string value) {
1210
exists(DataFlow::Node sink | exists(TestConfiguration cfg | cfg.hasFlowTo(sink)) |
1311
location = sink.getLocation() and
1412
tag = "captured" and
@@ -17,3 +15,5 @@ class CaptureTest extends InlineExpectationsTest {
1715
)
1816
}
1917
}
18+
19+
import MakeTest<CaptureTest>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
failures
2+
testFailures

python/ql/test/experimental/import-resolution/importflow.ql

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,10 @@ private class ImportConfiguration extends DataFlow::Configuration {
7272
}
7373
}
7474

75-
class ResolutionTest extends InlineExpectationsTest {
76-
ResolutionTest() { this = "ResolutionTest" }
75+
module ResolutionTest implements TestSig {
76+
string getARelevantTag() { result = "prints" }
7777

78-
override string getARelevantTag() { result = "prints" }
79-
80-
override predicate hasActualResult(Location location, string element, string tag, string value) {
78+
predicate hasActualResult(Location location, string element, string tag, string value) {
8179
(
8280
exists(DataFlow::PathNode source, DataFlow::PathNode sink, ImportConfiguration config |
8381
config.hasFlowPath(source, sink) and
@@ -105,12 +103,10 @@ private string getTagForVersion(int version) {
105103
version = major_version()
106104
}
107105

108-
class VersionSpecificResolutionTest extends InlineExpectationsTest {
109-
VersionSpecificResolutionTest() { this = "VersionSpecificResolutionTest" }
110-
111-
override string getARelevantTag() { result = getTagForVersion(_) }
106+
module VersionSpecificResolutionTest implements TestSig {
107+
string getARelevantTag() { result = getTagForVersion(_) }
112108

113-
override predicate hasActualResult(Location location, string element, string tag, string value) {
109+
predicate hasActualResult(Location location, string element, string tag, string value) {
114110
(
115111
exists(DataFlow::PathNode source, DataFlow::PathNode sink, ImportConfiguration config |
116112
config.hasFlowPath(source, sink) and
@@ -130,3 +126,5 @@ class VersionSpecificResolutionTest extends InlineExpectationsTest {
130126
)
131127
}
132128
}
129+
130+
import MakeTest<MergeTests<ResolutionTest, VersionSpecificResolutionTest>>

0 commit comments

Comments
 (0)