mirror of
https://github.com/github/codeql.git
synced 2026-05-02 04:05:14 +02:00
move equals attr test to equals attr folder
This commit is contained in:
@@ -0,0 +1 @@
|
||||
| attr_eq_test.py:21:1:21:27 | class BadColorPoint | The class 'BadColorPoint' does not override $@, but adds the new attribute $@. | attr_eq_test.py:10:5:10:28 | Function Point.__eq__ | '__eq__' | attr_eq_test.py:25:9:25:19 | Attribute | _color |
|
||||
|
||||
107
python/ql/test/query-tests/Classes/equals-attr/attr_eq_test.py
Normal file
107
python/ql/test/query-tests/Classes/equals-attr/attr_eq_test.py
Normal file
@@ -0,0 +1,107 @@
|
||||
class Point(object):
|
||||
|
||||
def __init__(self, x, y):
|
||||
self._x = x
|
||||
self._y = y
|
||||
|
||||
def __repr__(self):
|
||||
return 'Point(%r, %r)' % (self._x, self._y)
|
||||
|
||||
def __eq__(self, other):
|
||||
if not isinstance(other, Point):
|
||||
return False
|
||||
return self._x == other._x and self._y == other._y
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
def __hash__(self):
|
||||
return hash((self._x, self._y))
|
||||
|
||||
class BadColorPoint(Point):
|
||||
|
||||
def __init__(self, x, y, color):
|
||||
Point.__init__(self, x, y)
|
||||
self._color = color
|
||||
|
||||
def __repr__(self):
|
||||
return 'ColorPoint(%r, %r)' % (self._x, self._y, self._color)
|
||||
|
||||
class GoodColorPoint(Point):
|
||||
|
||||
def __init__(self, x, y, color):
|
||||
Point.__init__(self, x, y)
|
||||
self._color = color
|
||||
|
||||
def __repr__(self):
|
||||
return 'ColorPoint(%r, %r)' % (self._x, self._y, self._color)
|
||||
|
||||
def __eq__(self, other):
|
||||
if not isinstance(other, GoodColorPoint):
|
||||
return False
|
||||
return Point.__eq__(self, other) and self._color == other._color
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
def __hash__(self):
|
||||
return hash((self._x, self._y, self._color))
|
||||
|
||||
class GenericPoint(object):
|
||||
|
||||
def __init__(self, x, y):
|
||||
self._x = x
|
||||
self._y = y
|
||||
|
||||
def __repr__(self):
|
||||
return 'Point(%r, %r)' % (self._x, self._y)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.__class__ == other.__class__ and self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
def __hash__(self):
|
||||
return hash((self._x, self._y))
|
||||
|
||||
class GoodGenericColorPoint(GenericPoint):
|
||||
|
||||
def __init__(self, x, y, color):
|
||||
GenericPoint.__init__(self, x, y)
|
||||
self._color = color
|
||||
|
||||
class RedefineEq(object):
|
||||
|
||||
def __init__(self, x, y):
|
||||
self._x = x
|
||||
self._y = y
|
||||
|
||||
def __eq__(self, other):
|
||||
return self is other
|
||||
|
||||
class OK1(RedefineEq):
|
||||
|
||||
def __init__(self, x, y, z):
|
||||
RedefineEq.__init__(self, x, y)
|
||||
self.z = z
|
||||
|
||||
class OK2(GenericPoint):
|
||||
|
||||
def __init__(self, x, y, color):
|
||||
GenericPoint.__init__(self, x, y)
|
||||
self._color = color
|
||||
|
||||
def __eq__(self, other):
|
||||
return self is other
|
||||
|
||||
class ExpectingAttribute(object):
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.x == other.x
|
||||
|
||||
class OK3(ExpectingAttribute):
|
||||
|
||||
def __init__(self):
|
||||
self.x = 4
|
||||
|
||||
Reference in New Issue
Block a user