Skip to content

Commit 3ce93b2

Browse files
committed
-
1 parent 81167d3 commit 3ce93b2

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

source_py3/test_python_toolbox/test_context_management/test_as_reentrant.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,32 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
147147

148148
# `.__wrapped__.__enter__` saw a depth of 1, because the depth decrement
149149
# happens *after* `.__wrapped__.__enter__` is called:
150-
assert depth_log.get(block=False) == 1
150+
assert depth_log.get(block=False) == 1
151+
152+
def test_decorator():
153+
class Meow(ContextManager):
154+
n = 0
155+
156+
@as_reentrant
157+
def manage_context(self):
158+
self.n += 1
159+
try:
160+
yield
161+
finally:
162+
self.n -= 1
163+
164+
165+
meow = Meow()
166+
assert meow.n == 0
167+
with meow:
168+
assert meow.n == 1
169+
with meow:
170+
assert meow.n == 1
171+
with meow:
172+
assert meow.n == 1
173+
assert meow.n == 1
174+
assert meow.n == 1
175+
assert meow.n == 0
176+
177+
178+

0 commit comments

Comments
 (0)