mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Python: Autoformat tests
I guess these were never considered back when we switched to autoformatting everything.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import python
|
||||
|
||||
|
||||
select count(Ellipsis e)
|
||||
select count(Ellipsis e)
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
|
||||
import python
|
||||
|
||||
from ControlFlowNode p, ControlFlowNode s, string kind, string filename
|
||||
|
||||
where p.getASuccessor() = s and
|
||||
(
|
||||
where
|
||||
p.getASuccessor() = s and
|
||||
(
|
||||
p.getAnExceptionalSuccessor() = s and kind = "exception"
|
||||
or
|
||||
not p.getAnExceptionalSuccessor() = s and kind = "normal"
|
||||
) and filename = p.getLocation().getFile().getShortName() and
|
||||
not filename = "__future__.py"
|
||||
|
||||
select filename, p.getLocation().getStartLine(), p.toString(), s.getLocation().getStartLine(), s.toString(), kind
|
||||
) and
|
||||
filename = p.getLocation().getFile().getShortName() and
|
||||
not filename = "__future__.py"
|
||||
select filename, p.getLocation().getStartLine(), p.toString(), s.getLocation().getStartLine(),
|
||||
s.toString(), kind
|
||||
|
||||
@@ -3,4 +3,4 @@ import python
|
||||
from ModuleObject m
|
||||
/* Exclude the builtins module as it has a different name under 2 and 3. */
|
||||
where not m = theBuiltinModuleObject()
|
||||
select m.toString()
|
||||
select m.toString()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import python
|
||||
|
||||
from StrConst s
|
||||
select s, s.getText()
|
||||
select s, s.getText()
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
/**
|
||||
* Much of the QL library handling integral values assumes that
|
||||
* equivalence of the DB entities implies equivalence of the
|
||||
* Much of the QL library handling integral values assumes that
|
||||
* equivalence of the DB entities implies equivalence of the
|
||||
* Python object and vice-versa.
|
||||
* In Python 2, 1L == 1, which can cause problems, so we
|
||||
* normalise all longs to ints.
|
||||
* In Python 2, 1L == 1, which can cause problems, so we
|
||||
* normalise all longs to ints.
|
||||
*/
|
||||
|
||||
import python
|
||||
|
||||
from NumericObject n
|
||||
where
|
||||
exists(IntegerLiteral i |
|
||||
i.getLiteralObject() = n |
|
||||
exists(IntegerLiteral i | i.getLiteralObject() = n |
|
||||
i.getEnclosingModule().getFile().getShortName() = "test.py"
|
||||
)
|
||||
)
|
||||
select n.toString(), n.repr()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import python
|
||||
|
||||
where exists(theSysModuleObject())
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import python
|
||||
|
||||
from Module m
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import python
|
||||
|
||||
from SyntaxError s
|
||||
select s.toString()
|
||||
from SyntaxError s
|
||||
select s.toString()
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import python
|
||||
|
||||
|
||||
from AstNode ast, Location l
|
||||
where ast.getLocation() = l
|
||||
select ast.getAQlClass(), l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn()
|
||||
select ast.getAQlClass(), l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import python
|
||||
|
||||
from Module m
|
||||
select m.toString()
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
import python
|
||||
|
||||
from AnnAssign a, string value
|
||||
where
|
||||
value = a.getValue().toString() or not exists(a.getValue()) and value = "----"
|
||||
select a.getLocation().getStartLine(), a.toString(), a.getTarget().toString(), a.getAnnotation().toString(), value
|
||||
|
||||
where
|
||||
value = a.getValue().toString()
|
||||
or
|
||||
not exists(a.getValue()) and value = "----"
|
||||
select a.getLocation().getStartLine(), a.toString(), a.getTarget().toString(),
|
||||
a.getAnnotation().toString(), value
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import python
|
||||
|
||||
from AstNode a, Location l
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
import python
|
||||
|
||||
from ControlFlowNode p, ControlFlowNode s
|
||||
where p.getASuccessor() = s
|
||||
select p.getLocation().getStartLine(), p.getNode().toString(), s.getLocation().getStartLine(), s.getNode().toString()
|
||||
select p.getLocation().getStartLine(), p.getNode().toString(), s.getLocation().getStartLine(),
|
||||
s.getNode().toString()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
import python
|
||||
|
||||
from AsyncFor a
|
||||
select a.getLocation().getStartLine(), a.toString()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
import python
|
||||
|
||||
from AsyncWith aw
|
||||
select aw.getLocation().getStartLine(), aw.toString()
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import python
|
||||
import python
|
||||
|
||||
from Await a
|
||||
select a.getLocation().getStartLine(), a.toString()
|
||||
select a.getLocation().getStartLine(), a.toString()
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
|
||||
import python
|
||||
|
||||
from For f, string kind
|
||||
where
|
||||
f instanceof AsyncFor and kind = "async" or
|
||||
not f instanceof AsyncFor and kind = "normal"
|
||||
f instanceof AsyncFor and kind = "async"
|
||||
or
|
||||
not f instanceof AsyncFor and kind = "normal"
|
||||
select f.getLocation().getStartLine(), f.toString(), kind
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import python
|
||||
import python
|
||||
|
||||
from Await a
|
||||
select a.getLocation().getStartLine(), a.toString()
|
||||
select a.getLocation().getStartLine(), a.toString()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import python
|
||||
|
||||
from AstNode a, Location l
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
import python
|
||||
|
||||
from ControlFlowNode p, ControlFlowNode s
|
||||
where p.getASuccessor() = s and p.getScope().(Function).isAsync()
|
||||
select p.getLocation().getStartLine(), p.getNode().toString(), s.getLocation().getStartLine(), s.getNode().toString()
|
||||
select p.getLocation().getStartLine(), p.getNode().toString(), s.getLocation().getStartLine(),
|
||||
s.getNode().toString()
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
|
||||
import python
|
||||
|
||||
from Fstring str, int n, Expr e
|
||||
where e = str.getValue(n) and
|
||||
not exists(FormattedValue v | v.getFormatSpec() = str)
|
||||
where
|
||||
e = str.getValue(n) and
|
||||
not exists(FormattedValue v | v.getFormatSpec() = str)
|
||||
select str.getLocation().getStartLine(), str.toString(), n, e.toString()
|
||||
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
|
||||
import python
|
||||
|
||||
from FormattedValue val, string format, string typeconv
|
||||
where
|
||||
|
||||
(typeconv = val.getConversion() or not exists(val.getConversion()) and typeconv = " ")
|
||||
and
|
||||
(format = val.getFormatSpec().getValue(0).(StrConst).getText() or not exists(val.getFormatSpec()) and format = "")
|
||||
(
|
||||
typeconv = val.getConversion()
|
||||
or
|
||||
not exists(val.getConversion()) and typeconv = " "
|
||||
) and
|
||||
(
|
||||
format = val.getFormatSpec().getValue(0).(StrConst).getText()
|
||||
or
|
||||
not exists(val.getFormatSpec()) and format = ""
|
||||
)
|
||||
select val.getLocation().getStartLine(), val, format, val.getValue(), typeconv
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import python
|
||||
|
||||
from Expr e, Location l
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
|
||||
import python
|
||||
|
||||
string repr(AstNode a) {
|
||||
not a instanceof StrConst and result = a.toString()
|
||||
or
|
||||
result = "\"" + a.(StrConst).getText() + "\""
|
||||
not a instanceof StrConst and result = a.toString()
|
||||
or
|
||||
result = "\"" + a.(StrConst).getText() + "\""
|
||||
}
|
||||
|
||||
from ControlFlowNode p, ControlFlowNode s, BasicBlock b, int n
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
|
||||
import python
|
||||
|
||||
from Fstring str, int n, Expr e
|
||||
where e = str.getValue(n) and
|
||||
not exists(FormattedValue v | v.getFormatSpec() = str)
|
||||
where
|
||||
e = str.getValue(n) and
|
||||
not exists(FormattedValue v | v.getFormatSpec() = str)
|
||||
select str.getLocation().getStartLine(), str.toString(), n, e.toString()
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import python
|
||||
|
||||
from Expr e, Location l
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
|
||||
import python
|
||||
|
||||
string repr(AstNode a) {
|
||||
not a instanceof StrConst and result = a.toString()
|
||||
or
|
||||
result = "\"" + a.(StrConst).getText() + "\""
|
||||
not a instanceof StrConst and result = a.toString()
|
||||
or
|
||||
result = "\"" + a.(StrConst).getText() + "\""
|
||||
}
|
||||
|
||||
from ControlFlowNode p, ControlFlowNode s, BasicBlock b, int n
|
||||
|
||||
@@ -3,4 +3,4 @@ import python
|
||||
from ModuleObject m
|
||||
/* Exclude the builtins module as it has a different name under 2 and 3. */
|
||||
where not m = theBuiltinModuleObject()
|
||||
select m.toString()
|
||||
select m.toString()
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
|
||||
import python
|
||||
|
||||
from BinaryExpr b
|
||||
where b.getOp() instanceof MatMult
|
||||
select b.getLocation().getStartLine(), b.toString()
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import python
|
||||
|
||||
from StrConst s
|
||||
select s, s.getText()
|
||||
select s, s.getText()
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
|
||||
import python
|
||||
|
||||
from Num n
|
||||
select n.getLocation().getStartLine(), n.toString(), n.getN(), n.getText()
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import python
|
||||
|
||||
from Expr e, Location l
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
|
||||
import python
|
||||
|
||||
from AstNode a, int bl, int bc, int el, int ec
|
||||
where a.getLocation().hasLocationInfo(_, bl, bc, el, ec)
|
||||
select bl, bc, el, ec, a.toString()
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
|
||||
import python
|
||||
|
||||
from Call c, AstNode arg, int n, string what
|
||||
where
|
||||
what = "position" and arg = c.getPositionalArg(n)
|
||||
or
|
||||
what = "named" and arg = c.getNamedArg(n)
|
||||
select
|
||||
c.getLocation().getStartLine(), what, n, arg.toString()
|
||||
what = "position" and arg = c.getPositionalArg(n)
|
||||
or
|
||||
what = "named" and arg = c.getNamedArg(n)
|
||||
select c.getLocation().getStartLine(), what, n, arg.toString()
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
|
||||
import python
|
||||
|
||||
from Call c, Expr arg, string what
|
||||
where
|
||||
exists(int n |
|
||||
arg = c.getArg(n) and what = n.toString()
|
||||
)
|
||||
or
|
||||
arg = c.getStarargs() and what = "*"
|
||||
or
|
||||
arg = c.getKwargs() and what = "**"
|
||||
or
|
||||
exists(Keyword k |
|
||||
c.getAKeyword() = k |
|
||||
where
|
||||
exists(int n | arg = c.getArg(n) and what = n.toString())
|
||||
or
|
||||
arg = c.getStarargs() and what = "*"
|
||||
or
|
||||
arg = c.getKwargs() and what = "**"
|
||||
or
|
||||
exists(Keyword k | c.getAKeyword() = k |
|
||||
what = k.getArg() and
|
||||
arg = k.getValue()
|
||||
)
|
||||
|
||||
select c.getLocation().getStartLine(), arg, what
|
||||
)
|
||||
select c.getLocation().getStartLine(), arg, what
|
||||
|
||||
@@ -4,4 +4,3 @@ import semmle.python.TestUtils
|
||||
from AstNode p, AstNode c
|
||||
where p.getAChildNode() = c
|
||||
select compact_location(p), p.toString(), compact_location(c), c.toString()
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
import python
|
||||
|
||||
from AsyncFor a
|
||||
select a.getLocation().getStartLine(), a.toString()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
import python
|
||||
|
||||
from AsyncWith aw
|
||||
select aw.getLocation().getStartLine(), aw.toString()
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import python
|
||||
import python
|
||||
|
||||
from Await a
|
||||
select a.getLocation().getStartLine(), a.toString()
|
||||
select a.getLocation().getStartLine(), a.toString()
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
|
||||
import python
|
||||
|
||||
string async(Function f) {
|
||||
if f.isAsync() then
|
||||
result = "yes"
|
||||
else
|
||||
result = "no"
|
||||
}
|
||||
|
||||
string async(Function f) { if f.isAsync() then result = "yes" else result = "no" }
|
||||
|
||||
from Function f
|
||||
select f, async(f)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import python
|
||||
|
||||
from Scope s
|
||||
select s.toString(), count(BasicBlock bb | bb.getScope() = s)
|
||||
select s.toString(), count(BasicBlock bb | bb.getScope() = s)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import python
|
||||
|
||||
from Container path, string name
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import python
|
||||
|
||||
from Module m
|
||||
|
||||
@@ -2,7 +2,7 @@ import python
|
||||
|
||||
from Import imp, Alias al
|
||||
where
|
||||
al = imp.getAName() and
|
||||
imp.getLocation().getFile().getShortName() = "test.py"
|
||||
al = imp.getAName() and
|
||||
imp.getLocation().getFile().getShortName() = "test.py"
|
||||
select imp.getLocation().getStartLine(), imp.toString(), al.toString(), al.getValue().toString(),
|
||||
al.getAsname().toString()
|
||||
al.getAsname().toString()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import python
|
||||
|
||||
from EncodingError e
|
||||
select e.toString()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import python
|
||||
|
||||
from Module m
|
||||
select m.toString()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
|
||||
import python
|
||||
|
||||
from Name n, GlobalVariable v, boolean reachable
|
||||
where n.getVariable() = v and exists(ExprStmt s | s.getValue() = n) and
|
||||
if exists(ControlFlowNode f | f.getNode() = n) then reachable = true else reachable = false
|
||||
|
||||
where
|
||||
n.getVariable() = v and
|
||||
exists(ExprStmt s | s.getValue() = n) and
|
||||
if exists(ControlFlowNode f | f.getNode() = n) then reachable = true else reachable = false
|
||||
select n.getLocation().getStartLine(), v.getId(), reachable
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import python
|
||||
|
||||
from Module m
|
||||
select m.getName(), m.getFile().getAbsolutePath(), count(ControlFlowNode n | n.getScope().getEnclosingModule() = m)
|
||||
select m.getName(), m.getFile().getAbsolutePath(),
|
||||
count(ControlFlowNode n | n.getScope().getEnclosingModule() = m)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
|
||||
import external.Thrift
|
||||
|
||||
from string cls
|
||||
where any(ThriftElement t).getAQlClass() = cls
|
||||
select cls.prefix(6)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user