Skip to content

Commit

Permalink
Merge pull request #16910 from github/koesie10/python-exclude-test-files
Browse files Browse the repository at this point in the history
Python: Exclude probable test files in model editor
  • Loading branch information
koesie10 authored Jul 5, 2024
2 parents 3ae4cb2 + 779795b commit b7a67b1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions python/ql/lib/modeling/Util.qll
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@ private import python
private import semmle.python.ApiGraphs
private import semmle.python.filters.Tests

/**
* A file that probably contains tests.
*/
class TestFile extends File {
TestFile() {
this.getRelativePath().regexpMatch(".*(test|spec|examples).+") and
not this.getAbsolutePath().matches("%/ql/test/%") // allows our test cases to work
}
}

/** A class to represent scopes that the user might want to model. */
class RelevantScope extends Scope {
RelevantScope() {
this.isPublic() and
not this instanceof TestScope and
not this.getLocation().getFile() instanceof TestFile and
exists(this.getLocation().getFile().getRelativePath())
}
}
Expand Down

0 comments on commit b7a67b1

Please sign in to comment.