Commit c2177195 authored by Samuel GAIST's avatar Samuel GAIST Committed by Samuel Gaist
Browse files

[test][utils] Add mock logging handler

This will allow to analyse the content of logs generated during
a test.
parent 66f2507b
...@@ -29,6 +29,7 @@ Helper functions to run tests ...@@ -29,6 +29,7 @@ Helper functions to run tests
""" """
import os import os
import logging
from beat.core.experiment import Experiment from beat.core.experiment import Experiment
from beat.core.hash import toPath from beat.core.hash import toPath
...@@ -53,3 +54,35 @@ def index_experiment_dbs(experiment_name): ...@@ -53,3 +54,35 @@ def index_experiment_dbs(experiment_name):
infos['set']), infos['set']),
suffix='.db') suffix='.db')
view.index(os.path.join(tmp_prefix, filename)) view.index(os.path.join(tmp_prefix, filename))
# Based on
class MockLoggingHandler(logging.Handler):
"""Mock logging handler to check for expected logs.
Messages are available from an instance's ``messages`` dict, in order,
indexed by a lowercase log level string (e.g., 'debug', 'info', etc.).
def __init__(self, *args, **kwargs):
self.messages = {
'debug': [], 'info': [],
'warning': [], 'error': [],
'critical': [], 'extra': []
super(MockLoggingHandler, self).__init__(*args, **kwargs)
def emit(self, record):
"Store a message from ``record`` in the instance's ``messages`` dict."
except Exception:
def reset(self):
for message_list in self.messages.values():
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment