Convert Python qlref tests to inline expectations

This commit is contained in:
Owen Mansel-Chan
2026-06-15 11:06:48 +01:00
parent d6ade8fe95
commit 0c2df7c7e9
475 changed files with 1612 additions and 1382 deletions

View File

@@ -1 +1,2 @@
Classes/WrongNameForArgumentInClassInstantiation.ql
query: Classes/WrongNameForArgumentInClassInstantiation.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1 +1,2 @@
Classes/WrongNumberArgumentsInClassInstantiation.ql
query: Classes/WrongNumberArgumentsInClassInstantiation.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -34,22 +34,22 @@ class F7(object):
# Too few arguments
F0()
F1()
F2()
F3()
F4()
F5()
F6(1)
F7(1,2)
F0() # $ Alert[py/call/wrong-number-class-arguments]
F1() # $ Alert[py/call/wrong-number-class-arguments]
F2() # $ Alert[py/call/wrong-number-class-arguments]
F3() # $ Alert[py/call/wrong-number-class-arguments]
F4() # $ Alert[py/call/wrong-number-class-arguments]
F5() # $ Alert[py/call/wrong-number-class-arguments]
F6(1) # $ Alert[py/call/wrong-number-class-arguments]
F7(1,2) # $ Alert[py/call/wrong-number-class-arguments]
#Too many arguments
F0(1,2)
F1(1,2,3)
F5(1,2,3)
F6(1,2,3)
F6(1,2,3,4)
F0(1,2) # $ Alert[py/call/wrong-number-class-arguments]
F1(1,2,3) # $ Alert[py/call/wrong-number-class-arguments]
F5(1,2,3) # $ Alert[py/call/wrong-number-class-arguments]
F6(1,2,3) # $ Alert[py/call/wrong-number-class-arguments]
F6(1,2,3,4) # $ Alert[py/call/wrong-number-class-arguments]
#OK
@@ -62,9 +62,9 @@ F2(1,2,3,4,5,6)
#Illegal name
F0(y=1)
F1(z=1)
F2(x=0, y=1)
F0(y=1) # $ Alert[py/call/wrong-named-class-argument]
F1(z=1) # $ Alert[py/call/wrong-named-class-argument]
F2(x=0, y=1) # $ Alert[py/call/wrong-named-class-argument]
#Ok name
@@ -82,12 +82,12 @@ t3 = (1,2,3)
f(*t2)
#Too many
F6(*(1,2,3))
F6(*t3)
F6(*(1,2,3)) # $ Alert[py/call/wrong-number-class-arguments]
F6(*t3) # $ Alert[py/call/wrong-number-class-arguments]
#Ok
F6(**{'x':1, 'y':2})
#Illegal name
F6(**{'x':1, 'y':2, 'z':3})
F6(**{'x':1, 'y':2, 'z':3}) # $ Alert[py/call/wrong-named-class-argument]

View File

@@ -1 +1,2 @@
Classes/ConflictingAttributesInBaseClasses.ql
query: Classes/ConflictingAttributesInBaseClasses.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -23,7 +23,7 @@ class CB2(Common):
return 0
class Conflict(CB1, CB2):
class Conflict(CB1, CB2): # $ Alert
pass
class Override1(Common):

View File

@@ -1 +1,2 @@
Classes/MutatingDescriptor.ql
query: Classes/MutatingDescriptor.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -7,7 +7,7 @@ class MutatingDescriptor(object):
def __get__(self, obj, obj_type):
#Modified state is visible to all instances.
self.my_obj = obj
self.my_obj = obj # $ Alert
return self
def __call__(self, *args):
@@ -22,4 +22,4 @@ class MutatingDescriptor(object):
def not_ok(self, value):
#Modified state is visible to all instances.
self.my_obj = value
self.my_obj = value # $ Alert

View File

@@ -1 +1,2 @@
Classes/DefineEqualsWhenAddingAttributes.ql
query: Classes/DefineEqualsWhenAddingAttributes.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -18,7 +18,7 @@ class Point(object):
def __hash__(self):
return hash((self._x, self._y))
class BadColorPoint(Point):
class BadColorPoint(Point): # $ Alert
def __init__(self, x, y, color):
Point.__init__(self, x, y)

View File

@@ -1 +1,2 @@
Classes/InitCallsSubclass/InitCallsSubclassMethod.ql
query: Classes/InitCallsSubclass/InitCallsSubclassMethod.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -5,7 +5,7 @@ def bad1():
def __init__(self, arg):
self._state = "Not OK"
self.set_up(arg) # BAD: set_up is overriden.
self.set_up(arg) # $ Alert # BAD: set_up is overriden.
self._state = "OK"
def set_up(self, arg):
@@ -29,7 +29,7 @@ def bad2():
self.a = arg
# BAD: postproc is called after initialization. This is still an issue
# since it may still occur before all initialization on a subclass is complete.
self.postproc()
self.postproc() # $ Alert
def postproc(self):
if self.a == 1:
@@ -72,4 +72,4 @@ def good4():
class Sub(Super):
def _set_b(self):
self.b = self.a+1
self.b = self.a+1

View File

@@ -1 +1,2 @@
Classes/OverwritingAttributeInSuperClass.ql
query: Classes/OverwritingAttributeInSuperClass.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -2,7 +2,7 @@
class C(object):
def __init__(self):
self.var = 0
self.var = 0 # $ Alert
class D(C):
@@ -20,4 +20,4 @@ class F(E):
def __init__(self):
E.__init__(self)
self.var = 1
self.var = 1 # $ Alert

View File

@@ -1 +1,2 @@
Classes/ShouldBeContextManager.ql
query: Classes/ShouldBeContextManager.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1,6 +1,6 @@
#Should be context manager
class MegaDel(object):
class MegaDel(object): # $ Alert
def __del__(self):
a = self.x + self.y
@@ -13,7 +13,7 @@ class MegaDel(object):
sum += a
print(sum)
class MiniDel(object):
class MiniDel(object): # $ Alert
def close(self):
pass

View File

@@ -1 +1,2 @@
Classes/MaybeUndefinedClassAttribute.ql
query: Classes/MaybeUndefinedClassAttribute.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1 +1,2 @@
Classes/UndefinedClassAttribute.ql
query: Classes/UndefinedClassAttribute.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -21,10 +21,10 @@ class Attributes(object):
print (self.local_exists)
def neca1(self):
print (self.not_exists)
print (self.not_exists) # $ Alert[py/undefined-attribute]
def neca2(self):
print (self.may_exist)
print (self.may_exist) # $ Alert[py/maybe-undefined-attribute]
#This is OK
class SetViaDict(object):
@@ -106,7 +106,7 @@ class DecoratedInit(object):
class NoInit(object):
def use_y(self):
return self.y
return self.y # $ Alert[py/undefined-attribute]
#This is also OK
class SetLocally2(object):
@@ -181,7 +181,7 @@ class Test1(object):
self.return_queue = frame.method.queue
def use_it(self):
return self.return_queue
return self.return_queue # $ Alert[py/maybe-undefined-attribute]
#Check for FPs when overriding builtin methods
@@ -247,15 +247,15 @@ class Customer1(object):
class Odasa4619a(object):
def call(self):
host = self.glance_host
port = self.glance_port
host = self.glance_host # $ Alert[py/undefined-attribute]
port = self.glance_port # $ Alert[py/undefined-attribute]
class Odasa4619b(object):
def call(self):
host = self.glance_host
port = self.glance_port
host = self.glance_host # $ Alert[py/maybe-undefined-attribute]
port = self.glance_port # $ Alert[py/maybe-undefined-attribute]
@decorator
def foo(self):

View File

@@ -1 +1,2 @@
Classes/UselessClass.ql
query: Classes/UselessClass.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -25,7 +25,7 @@ class Useful2(object):
pass
class Useless1(object):
class Useless1(object): # $ Alert
def __init__(self):
pass
@@ -34,7 +34,7 @@ class Useless1(object):
pass
class Useless2(object):
class Useless2(object): # $ Alert
def do_something(self):
pass