Skip to content

Commit dd4d002

Browse files
committed
Python: remaining class tests
1 parent 3949911 commit dd4d002

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

python/ql/test/experimental/dataflow/coverage/classes.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,20 @@ def test_set_name():
302302
with_set_name = With_set_name()
303303
type("Owner", (object,), dict(attr=with_set_name))
304304

305-
# 3.3.2.4. __slots__
305+
# 3.3.2.4. __slots__ // We are not testing the suppression of -weakref_ and _dict_ here
306306
# object.__slots__
307307
# __weakref__
308308
# __dict__
309309

310310
# 3.3.3. Customizing class creation
311311
# classmethod object.__init_subclass__(cls)
312+
class With_init_subclass:
313+
314+
def __init_subclass__(cls):
315+
OK()
316+
317+
def test_init_subclass():
318+
type("Subclass", (With_init_subclass,), {})
312319

313320
# 3.3.3.1. Metaclasses
314321
# By default, classes are constructed using type(). The class body is executed in a new namespace and the class name is bound locally to the result of type(name, bases, namespace).
@@ -318,13 +325,52 @@ def test_set_name():
318325

319326
# 3.3.3.4. Preparing the class namespace
320327
# metaclass.__prepare__(name, bases, **kwds)
328+
class With_prepare(type):
329+
330+
def __prepare__(name, bases, **kwds):
331+
OK()
332+
return kwds
333+
334+
335+
def test_prepare():
336+
class With_meta(metaclass=With_prepare):
337+
pass
321338

322339
# 3.3.4. Customizing instance and subclass checks
323340
# class.__instancecheck__(self, instance)
341+
class With_instancecheck:
342+
343+
def __instancecheck__(self, instance):
344+
OK()
345+
return True
346+
347+
def test_instancecheck():
348+
with_instancecheck = With_instancecheck()
349+
isinstance("", with_instancecheck)
350+
324351
# class.__subclasscheck__(self, subclass)
352+
class With_subclasscheck:
353+
354+
def __subclasscheck__(self, subclass):
355+
OK()
356+
return True
357+
358+
def test_subclasscheck():
359+
with_subclasscheck = With_subclasscheck()
360+
issubclass(object, with_subclasscheck)
361+
325362

326363
# 3.3.5. Emulating generic types
327364
# classmethod object.__class_getitem__(cls, key)
365+
class With_class_getitem:
366+
367+
def __class_getitem__(cls, key):
368+
OK()
369+
return object
370+
371+
def test_class_getitem():
372+
with_class_getitem = With_class_getitem[int]()
373+
328374

329375
# 3.3.6. Emulating callable objects
330376
# object.__call__(self[, args...])
@@ -1113,7 +1159,7 @@ async def atest_await():
11131159
await(with_await)
11141160

11151161

1116-
# # 3.4.2. Coroutine Objects
1162+
# # 3.4.2. Coroutine Objects // These should be handled as normal function calls
11171163
# # coroutine.send(value)
11181164
# # coroutine.throw(type[, value[, traceback]])
11191165
# # coroutine.close()

python/ql/test/experimental/dataflow/coverage/classesCallGraph.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
| classes.py:178:7:178:28 | ControlFlowNode for frozenset() | classes.py:178:7:178:28 | ControlFlowNode for frozenset() |
44
| classes.py:182:7:182:26 | ControlFlowNode for dict() | classes.py:182:7:182:26 | ControlFlowNode for dict() |
55
| classes.py:303:28:303:51 | ControlFlowNode for dict() | classes.py:303:28:303:51 | ControlFlowNode for dict() |
6-
| classes.py:420:12:420:24 | ControlFlowNode for Attribute() | classes.py:420:12:420:24 | ControlFlowNode for Attribute() |
6+
| classes.py:466:12:466:24 | ControlFlowNode for Attribute() | classes.py:466:12:466:24 | ControlFlowNode for Attribute() |

0 commit comments

Comments
 (0)