Skip to content

Commit 0247877

Browse files
committed
Python: tests for context managers
1 parent 5b7c7f9 commit 0247877

File tree

1 file changed

+22
-17
lines changed
  • python/ql/test/experimental/dataflow/coverage

1 file changed

+22
-17
lines changed

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

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,29 +1224,34 @@ def test_ceil():
12241224
math.ceil(with_ceil) # edit to effect call
12251225

12261226

1227-
# # 3.3.9. With Statement Context Managers
1228-
# # object.__enter__(self)
1229-
# class With_enter:
1227+
# 3.3.9. With Statement Context Managers
1228+
# object.__enter__(self)
1229+
class With_enter:
12301230

1231-
# def __enter__(self):
1232-
# OK()
1233-
# return "" # edit to match type
1231+
def __enter__(self):
1232+
OK()
1233+
return
12341234

1235-
# def test_enter():
1236-
# with_enter = With_enter()
1237-
# enter(with_enter) # edit to effect call
1235+
def __exit__(self, exc_type, exc_value, traceback):
1236+
return
12381237

1239-
# # object.__exit__(self, exc_type, exc_value, traceback)
1240-
# class With_exit:
1238+
def test_enter():
1239+
with With_enter():
1240+
pass
12411241

1242-
# def __exit__(self, exc_type, exc_value, traceback):
1243-
# OK()
1244-
# return "" # edit to match type
1242+
# object.__exit__(self, exc_type, exc_value, traceback)
1243+
class With_exit:
1244+
1245+
def __enter__(self):
1246+
return
12451247

1246-
# def test_exit():
1247-
# with_exit = With_exit()
1248-
# exit(with_exit) # edit to effect call
1248+
def __exit__(self, exc_type, exc_value, traceback):
1249+
OK()
1250+
return
12491251

1252+
def test_exit():
1253+
with With_exit():
1254+
pass
12501255

12511256
# # 3.4.1. Awaitable Objects
12521257
# # object.__await__(self)

0 commit comments

Comments
 (0)