From f29e8894bffe6bf595325b921970af2017b7132b Mon Sep 17 00:00:00 2001 From: Rasmus Wriedt Larsen Date: Tue, 12 Sep 2023 15:15:19 +0200 Subject: [PATCH] Python: Adjust test-code predicate --- .../python/frameworks/internal/SubclassFinder.qll | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/python/ql/lib/semmle/python/frameworks/internal/SubclassFinder.qll b/python/ql/lib/semmle/python/frameworks/internal/SubclassFinder.qll index 5ab1dde5e14..20e60c6ad7b 100644 --- a/python/ql/lib/semmle/python/frameworks/internal/SubclassFinder.qll +++ b/python/ql/lib/semmle/python/frameworks/internal/SubclassFinder.qll @@ -112,10 +112,10 @@ module NotExposed { fullyQualifiedToApiGraphPath(fullyQualifiedName) = spec.getAlreadyModeledClass().getPath() } - predicate isNonTestProjectCode(AstNode ast) { - not ast.getScope*() instanceof TestScope and - not ast.getLocation().getFile().getRelativePath().matches("tests/%") and - not exists(ast.getLocation().getFile().getRelativePath()) + predicate isTestCode(AstNode ast) { + ast.getScope*() instanceof TestScope + or + ast.getLocation().getFile().getRelativePath().matches("tests/%") } predicate hasAllStatement(Module mod) { @@ -167,7 +167,7 @@ module NotExposed { mod.declaredInAll(importMember.getName()) ) and not alreadyExplicitlyModeled(spec, newAliasFullyQualified) and - isNonTestProjectCode(importMember) + not isTestCode(importMember) } /** same as `newDirectAlias` predicate, but handling `from import *`, considering all ``, where `.` belongs to `spec`. */ @@ -195,7 +195,7 @@ module NotExposed { mod.declaredInAll(relevantName) ) and not alreadyExplicitlyModeled(spec, newAliasFullyQualified) and - isNonTestProjectCode(importStar) + not isTestCode(importStar) } /** Holds if `classExpr` defines a new subclass that belongs to `spec`, which has the fully qualified name `newSubclassQualified`. */ @@ -208,6 +208,6 @@ module NotExposed { newSubclassQualified = mod.getName() + "." + classExpr.getName() and loc = classExpr.getLocation() and not alreadyExplicitlyModeled(spec, newSubclassQualified) and - isNonTestProjectCode(classExpr) + not isTestCode(classExpr) } }