Files
codeql/python/ql/test/library-tests/frameworks/internal-ql-helpers/PoorMansFunctionResolutionTest.ql
Taus ac5a74448f Python: Fix tests
With `ModuleVariableNode`s now appearing for _all_ global variables (not
just the ones that actually seem to be used), some of the tests changed
a bit. Mostly this was in the form of new flow (because of new nodes
that popped into existence). For some inline expectation tests, I opted
to instead exclude these results, as there was no suitable location to
annotate. For the normal tests, I just accepted the output (after having
vetted it carefully, of course).
2026-01-30 12:50:25 +00:00

33 lines
1.3 KiB
Plaintext

private import python
private import semmle.python.dataflow.new.DataFlow
private import semmle.python.frameworks.internal.PoorMansFunctionResolution
import utils.test.InlineExpectationsTest
module InlinePoorMansFunctionResolutionTest implements TestSig {
string getARelevantTag() { result = "resolved" }
predicate hasActualResult(Location location, string element, string tag, string value) {
exists(location.getFile().getRelativePath()) and
exists(Function func, DataFlow::Node ref |
ref = poorMansFunctionTracker(func) and
not ref.asExpr() instanceof FunctionExpr and
// exclude the name of a defined function
not exists(FunctionDef def | def.getDefinedFunction() = func |
ref.asExpr() = def.getATarget()
) and
// exclude decorator calls (which with our extractor rewrites does reference the
// function)
not ref.asExpr() = func.getDefinition().(FunctionExpr).getADecoratorCall() and
// exclude ModuleVariableNodes (which have location 0:0:0:0)
not ref instanceof DataFlow::ModuleVariableNode
|
value = func.getName() and
tag = "resolved" and
element = ref.toString() and
location = ref.getLocation()
)
}
}
import MakeTest<InlinePoorMansFunctionResolutionTest>