def test_log_model(): """Test the log model buff_size handling. """ model = LogModel(buff_size=4) for i in range(5): model.add_message('%d\n' % i) check = ''.join(['%d\n' % i for i in range(5)]) assert model.text == check model.add_message('%d' % 5) assert model.text == check.partition('\n')[-1] + '%d\n' % 5 model.clean_text() for i in range(4): model.add_message('%d\n' % i) assert model.text == ''.join(['%d\n' % i for i in range(4)])
def test_gui_handler(app, logger, monkeypatch): """Test the gui handler. """ model = LogModel() handler = GuiHandler(model) logger.addHandler(handler) logger.info('test') process_app_events() assert model.text == 'test\n' model.clean_text() logger.debug('test') process_app_events() assert model.text == 'DEBUG: test\n' model.clean_text() logger.warn('test') process_app_events() assert model.text == 'WARNING: test\n' model.clean_text() logger.error('test') process_app_events() assert model.text == 'ERROR: test\n' model.clean_text() logger.critical('test') process_app_events() answer = 'An error occured please check the log file for more details.\n' assert model.text == answer model.clean_text() def err(record): raise Exception monkeypatch.setattr(handler, 'format', err) logger.info('raise')