Beispiel #1
0
def test_gui_handler(exopy_qtbot, logger, monkeypatch):
    """Test the gui handler.

    """
    model = LogModel()
    handler = GuiHandler(model)
    logger.addHandler(handler)

    logger.info('test')

    def assert_text():
        assert model.text == 'test\n'

    exopy_qtbot.wait_until(assert_text)
    model.clean_text()

    logger.debug('test')

    def assert_text():
        assert model.text == 'DEBUG: test\n'

    exopy_qtbot.wait_until(assert_text)
    model.clean_text()

    logger.warning('test')

    def assert_text():
        assert model.text == 'WARNING: test\n'

    exopy_qtbot.wait_until(assert_text)
    model.clean_text()

    logger.error('test')

    def assert_text():
        assert model.text == 'ERROR: test\n'

    exopy_qtbot.wait_until(assert_text)
    model.clean_text()

    logger.critical('test')
    answer = 'An error occured please check the log file for more details.\n'

    def assert_text():
        assert model.text == answer

    exopy_qtbot.wait_until(assert_text)
    model.clean_text()

    def err(record):
        raise Exception

    monkeypatch.setattr(handler, 'format', err)
    logger.info('raise')
Beispiel #2
0
def test_gui_handler(exopy_qtbot, logger, monkeypatch):
    """Test the gui handler.

    """
    model = LogModel()
    handler = GuiHandler(model)
    logger.addHandler(handler)

    logger.info('test')

    def assert_text():
        assert model.text == 'test\n'
    exopy_qtbot.wait_until(assert_text)
    model.clean_text()

    logger.debug('test')

    def assert_text():
        assert model.text == 'DEBUG: test\n'
    exopy_qtbot.wait_until(assert_text)
    model.clean_text()

    logger.warning('test')

    def assert_text():
        assert model.text == 'WARNING: test\n'
    exopy_qtbot.wait_until(assert_text)
    model.clean_text()

    logger.error('test')

    def assert_text():
        assert model.text == 'ERROR: test\n'
    exopy_qtbot.wait_until(assert_text)
    model.clean_text()

    logger.critical('test')
    answer = 'An error occured please check the log file for more details.\n'

    def assert_text():
        assert model.text == answer
    exopy_qtbot.wait_until(assert_text)
    model.clean_text()

    def err(record):
        raise Exception

    monkeypatch.setattr(handler, 'format', err)
    logger.info('raise')
Beispiel #3
0
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)])
Beispiel #4
0
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)])