File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed
src/semmle/python/filters
test/library-tests/filters/tests Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -5,18 +5,17 @@ abstract class TestScope extends Scope { }
5
5
// don't extend Class directly to avoid ambiguous method warnings
6
6
class UnitTestClass extends TestScope {
7
7
UnitTestClass ( ) {
8
- exists ( ClassObject c | this = c . getPyClass ( ) |
9
- c . getASuperType ( ) = theUnitTestPackage ( ) .attr ( _)
8
+ exists ( ClassValue cls | this = cls . getScope ( ) |
9
+ cls . getABaseType + ( ) = Module :: named ( "unittest" ) .attr ( _)
10
10
or
11
- c . getASuperType ( ) .getName ( ) .toLowerCase ( ) = "testcase"
11
+ cls . getABaseType + ( ) .getName ( ) .toLowerCase ( ) = "testcase"
12
12
)
13
13
}
14
14
}
15
15
16
- PackageObject theUnitTestPackage ( ) { result .getName ( ) = "unittest" }
17
-
18
16
abstract class Test extends TestScope { }
19
17
18
+ /** Class of test function that uses the `unittest` framework */
20
19
class UnitTestFunction extends Test {
21
20
UnitTestFunction ( ) {
22
21
this .getScope + ( ) instanceof UnitTestClass and
@@ -37,3 +36,11 @@ class NoseTestFunction extends Test {
37
36
this .( Function ) .getName ( ) .matches ( "test%" )
38
37
}
39
38
}
39
+
40
+ /** Class of functions that are clearly tests, but don't belong to a specific framework */
41
+ class UnknownTestFunction extends Test {
42
+ UnknownTestFunction ( ) {
43
+ this .( Function ) .getName ( ) .matches ( "test%" ) and
44
+ this .getEnclosingModule ( ) .getFile ( ) .getShortName ( ) .matches ( "test_%.py" )
45
+ }
46
+ }
Original file line number Diff line number Diff line change 1
1
| test.py:4:1:4:23 | Class MyTest |
2
2
| test.py:6:5:6:21 | Function test_1 |
3
3
| test.py:9:5:9:21 | Function test_2 |
4
+ | test_foo.py:3:1:3:15 | Function test_foo |
5
+ | unittest_test.py:3:1:3:33 | Class FooTest |
6
+ | unittest_test.py:4:5:4:25 | Function test_valid |
You can’t perform that action at this time.
0 commit comments