Skip to content

Commit b7a67b1

Browse files
authored
Merge pull request github#16910 from github/koesie10/python-exclude-test-files
Python: Exclude probable test files in model editor
2 parents 3ae4cb2 + 779795b commit b7a67b1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

python/ql/lib/modeling/Util.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,22 @@ private import python
66
private import semmle.python.ApiGraphs
77
private import semmle.python.filters.Tests
88

9+
/**
10+
* A file that probably contains tests.
11+
*/
12+
class TestFile extends File {
13+
TestFile() {
14+
this.getRelativePath().regexpMatch(".*(test|spec|examples).+") and
15+
not this.getAbsolutePath().matches("%/ql/test/%") // allows our test cases to work
16+
}
17+
}
18+
919
/** A class to represent scopes that the user might want to model. */
1020
class RelevantScope extends Scope {
1121
RelevantScope() {
1222
this.isPublic() and
1323
not this instanceof TestScope and
24+
not this.getLocation().getFile() instanceof TestFile and
1425
exists(this.getLocation().getFile().getRelativePath())
1526
}
1627
}

0 commit comments

Comments
 (0)