Python: Autoformat tests

I guess these were never considered back when we switched to
autoformatting everything.
This commit is contained in:
Taus
2024-04-15 15:27:21 +00:00
parent 25cb52aa52
commit 82057e2e46
49 changed files with 96 additions and 127 deletions

View File

@@ -1,4 +1,3 @@
import python
select count(Ellipsis e)
select count(Ellipsis e)

View File

@@ -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

View File

@@ -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()

View File

@@ -1,4 +1,4 @@
import python
from StrConst s
select s, s.getText()
select s, s.getText()

View File

@@ -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()

View File

@@ -1,4 +1,3 @@
import python
where exists(theSysModuleObject())

View File

@@ -1,4 +1,3 @@
import python
from Module m

View File

@@ -1,4 +1,4 @@
import python
from SyntaxError s
select s.toString()
from SyntaxError s
select s.toString()

View File

@@ -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()

View File

@@ -1,3 +1,4 @@
import python
from Module m
select m.toString()

View File

@@ -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

View File

@@ -1,4 +1,3 @@
import python
from AstNode a, Location l

View File

@@ -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()

View File

@@ -1,4 +1,4 @@
import python
from AsyncFor a
select a.getLocation().getStartLine(), a.toString()

View File

@@ -1,5 +1,4 @@
import python
from AsyncWith aw
select aw.getLocation().getStartLine(), aw.toString()

View File

@@ -1,4 +1,4 @@
import python
import python
from Await a
select a.getLocation().getStartLine(), a.toString()
select a.getLocation().getStartLine(), a.toString()

View File

@@ -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

View File

@@ -1,4 +1,4 @@
import python
import python
from Await a
select a.getLocation().getStartLine(), a.toString()
select a.getLocation().getStartLine(), a.toString()

View File

@@ -1,4 +1,3 @@
import python
from AstNode a, Location l

View File

@@ -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()

View File

@@ -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()

View File

@@ -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

View File

@@ -1,4 +1,3 @@
import python
from Expr e, Location l

View File

@@ -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

View File

@@ -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()

View File

@@ -1,4 +1,3 @@
import python
from Expr e, Location l

View File

@@ -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

View File

@@ -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()

View File

@@ -1,7 +1,5 @@
import python
from BinaryExpr b
where b.getOp() instanceof MatMult
select b.getLocation().getStartLine(), b.toString()

View File

@@ -1,4 +1,4 @@
import python
from StrConst s
select s, s.getText()
select s, s.getText()

View File

@@ -1,6 +1,4 @@
import python
from Num n
select n.getLocation().getStartLine(), n.toString(), n.getN(), n.getText()

View File

@@ -1,4 +1,3 @@
import python
from Expr e, Location l

View File

@@ -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()

View File

@@ -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()

View File

@@ -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

View File

@@ -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()

View File

@@ -1,4 +1,4 @@
import python
from AsyncFor a
select a.getLocation().getStartLine(), a.toString()

View File

@@ -1,5 +1,4 @@
import python
from AsyncWith aw
select aw.getLocation().getStartLine(), aw.toString()

View File

@@ -1,4 +1,4 @@
import python
import python
from Await a
select a.getLocation().getStartLine(), a.toString()
select a.getLocation().getStartLine(), a.toString()

View File

@@ -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)

View File

@@ -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)

View File

@@ -1,4 +1,3 @@
import python
from Container path, string name

View File

@@ -1,4 +1,3 @@
import python
from Module m

View File

@@ -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()

View File

@@ -1,3 +1,4 @@
import python
from EncodingError e
select e.toString()

View File

@@ -1,3 +1,4 @@
import python
from Module m
select m.toString()

View File

@@ -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

View File

@@ -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)

View File

@@ -1,7 +1,5 @@
import external.Thrift
from string cls
where any(ThriftElement t).getAQlClass() = cls
select cls.prefix(6)