@@ -78,19 +78,19 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
7878
7979
8080def test_exception_swallowing ():
81- class SwallowingReentrantContextManager ( ReentrantContextManager ):
81+ class SwallowingContextManager ( ContextManager ):
8282 def __init__ (self ):
8383 self .times_entered = 0
8484 self .times_exited = 0
85- def reentrant_enter (self ):
85+ def __enter__ (self ):
8686 self .times_entered += 1
8787 return self
88- def reentrant_exit (self , exc_type , exc_value , exc_traceback ):
88+ def __exit__ (self , exc_type , exc_value , exc_traceback ):
8989 self .times_exited += 1
9090 if isinstance (exc_value , MyException ):
9191 return True
9292
93- swallowing_rcm = SwallowingReentrantContextManager ( )
93+ swallowing_rcm = as_reentrant ( SwallowingContextManager () )
9494
9595 my_set = set ()
9696
@@ -118,34 +118,35 @@ def test_order_of_depth_modification():
118118
119119 depth_log = queue_module .Queue ()
120120
121- class JohnnyReentrantContextManager ( ReentrantContextManager ):
122- def reentrant_enter (self ):
121+ class JohnnyContextManager ( ContextManager ):
122+ def __enter__ (self ):
123123 depth_log .put (self .depth )
124124 return self
125- def reentrant_exit (self , exc_type , exc_value , exc_traceback ):
125+ def __exit__ (self , exc_type , exc_value , exc_traceback ):
126126 depth_log .put (self .depth )
127127
128- johnny_reentrant_context_manager = JohnnyReentrantContextManager ( )
128+ johnny_reentrant_context_manager = as_reentrant ( JohnnyContextManager () )
129129 assert johnny_reentrant_context_manager .depth == 0
130130 with johnny_reentrant_context_manager :
131131 assert johnny_reentrant_context_manager .depth == 1
132132
133- # `reentrant_enter ` saw a depth of 0, because the depth increment
134- # happens *after* `reentrant_enter ` is called:
133+ # `.__wrapped__.__enter__ ` saw a depth of 0, because the depth
134+ # increment happens *after* `.__wrapped__.__enter__ ` is called:
135135 assert depth_log .get (block = False ) == 0
136136
137137 with johnny_reentrant_context_manager :
138138
139139 assert johnny_reentrant_context_manager .depth == 2
140140 assert depth_log .qsize () == 0 # We're in a depth greater than 1,
141- # so `reentrant_enter ` wasn't even
142- # called.
141+ # so `.__wrapped__.__enter__ ` wasn't
142+ # even called.
143143
144144 assert johnny_reentrant_context_manager .depth == 1
145145
146146 assert depth_log .qsize () == 0 # We came out of a depth greater than 1,
147- # so `reentrant_exit` wasn't even called.
147+ # so `.__wrapped__.__enter__` wasn't even
148+ # called.
148149
149- # `reentrant_exit ` saw a depth of 1, because the depth decrement happens
150- # *after* `reentrant_exit ` is called:
150+ # `.__wrapped__.__enter__ ` saw a depth of 1, because the depth decrement
151+ # happens *after* `.__wrapped__.__enter__ ` is called:
151152 assert depth_log .get (block = False ) == 1
0 commit comments