-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathTests.qll
More file actions
47 lines (40 loc) · 1.29 KB
/
Tests.qll
File metadata and controls
47 lines (40 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import python
private import semmle.python.ApiGraphs
abstract class TestScope extends Scope { }
class UnitTestClass extends TestScope, Class {
UnitTestClass() {
exists(API::Node testCaseClass, string testCaseString |
testCaseString.matches("%TestCase") and
testCaseClass = any(API::Node mod).getMember(testCaseString)
|
this.getParent() = testCaseClass.getASubclass*().asSource().asExpr()
)
}
}
abstract class Test extends TestScope { }
/** A test function that uses the `unittest` framework */
class UnitTestFunction extends Test {
UnitTestFunction() {
this.getScope+() instanceof UnitTestClass and
this.(Function).getName().matches("test%")
}
}
class PyTestFunction extends Test {
PyTestFunction() {
exists(Module pytest | pytest.getName() = "pytest") and
this.(Function).getName().matches("test%")
}
}
class NoseTestFunction extends Test {
NoseTestFunction() {
exists(Module nose | nose.getName() = "nose") and
this.(Function).getName().matches("test%")
}
}
/** A function that is clearly a test, but doesn't belong to a specific framework */
class UnknownTestFunction extends Test {
UnknownTestFunction() {
this.(Function).getName().matches("test%") and
this.getEnclosingModule().getFile().getShortName().matches("test_%.py")
}
}