MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / assertLoopErrorHandlerCalled

Method assertLoopErrorHandlerCalled

asyncpg/_testbase/__init__.py:157–178  ·  view source on GitHub ↗
(self, msg_re: str)

Source from the content-addressed store, hash-verified

155
156 @contextlib.contextmanager
157 def assertLoopErrorHandlerCalled(self, msg_re: str):
158 contexts = []
159
160 def handler(loop, ctx):
161 contexts.append(ctx)
162
163 old_handler = self.loop.get_exception_handler()
164 self.loop.set_exception_handler(handler)
165 try:
166 yield
167
168 for ctx in contexts:
169 msg = ctx.get('message')
170 if msg and re.search(msg_re, msg):
171 return
172
173 raise AssertionError(
174 'no message matching {!r} was logged with '
175 'loop.call_exception_handler()'.format(msg_re))
176
177 finally:
178 self.loop.set_exception_handler(old_handler)
179
180 def loop_exception_handler(self, loop, context):
181 self.__unhandled_exceptions.append(context)

Calls 1

getMethod · 0.80