def test_error_level(p_mock): with ExceptionToHABApp(log, logging.WARNING): 1 / 0 p_mock.assert_called_once() assert p_mock.call_args[0][0] == HABApp.core.const.topics.WARNINGS p_mock.reset_mock() with ExceptionToHABApp(log): 1 / 0 p_mock.assert_called_once() assert p_mock.call_args[0][0] == HABApp.core.const.topics.ERRORS
def test_error_catch(p_mock): p_mock.assert_not_called() with ExceptionToHABApp(log, logging.WARNING): pass p_mock.assert_not_called() with ExceptionToHABApp(log, logging.WARNING): 1 / 0 p_mock.assert_called_once() assert p_mock.call_args[0][0] == HABApp.core.const.topics.WARNINGS
def test_exception_format(p_mock): async def test(): async with aiohttp.ClientSession( timeout=aiohttp.ClientTimeout(0.01)) as session: async with session.get('http://localhost:12345'): pass with ExceptionToHABApp(log): asyncio.get_event_loop().run_until_complete(test()) tb = p_mock.call_args[0][1].traceback # verbose asyncio assert 'self = <ProactorEventLoop running=False closed=False debug=True>' not in tb # verbose aiohttp assert 'async def __aenter__(self) -> _RetType:' not in tb
def setup_plugins(): for p in PLUGINS: with ExceptionToHABApp(log, ignore_exception=True): p.setup() log.debug(f'Setup {p.__class__.__name__} complete')
def on_disconnect(): PluginBase.IS_CONNECTED = False for p in PLUGINS: with ExceptionToHABApp(log, ignore_exception=True): p.on_disconnect()