Commit 40ecb483 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Looking for test log in parser tests.

parent f04a5f71
Pipeline #41116 passed with stages
in 14 minutes and 16 seconds
......@@ -44,7 +44,7 @@
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/.pyenv/bin/pytest",
"args": [
"-sv", "tests/test_api.py::test_raw_file"
"-sv", "tests/test_parsing.py::test_parser[parsers/random-test/data/parsers/random_0]"
]
},
{
......
......@@ -94,6 +94,10 @@ class TemplateParser(ArtificalParser):
self.backend.closeSection(name, index)
def run(self, mainfile: str, logger=None) -> LocalBackend:
# tell tests about received logger
if logger is not None:
logger.debug('received logger')
self.init_backend()
if 'warning' in mainfile:
......@@ -168,6 +172,10 @@ class GenerateRandomParser(TemplateParser):
return value
def run(self, mainfile: str, logger=None) -> LocalBackend:
# tell tests about received logger
if logger is not None:
logger.debug('received logger')
self.init_backend()
seed = int(os.path.basename(mainfile).split('_')[1])
random.seed(seed)
......
......@@ -110,11 +110,13 @@ class LegacyParser(Parser):
init_signature = inspect.getargspec(Parser.__init__)
kwargs = dict(
backend=lambda meta_info: create_backend(meta_info, logger=logger),
log_level=logging.DEBUG, debug=True)
log_level=logging.DEBUG, logger=logger, debug=True)
kwargs = {key: value for key, value in kwargs.items() if key in init_signature.args}
self.parser = Parser(**kwargs)
if logger is not None:
# TODO the following should be deprecated and loggers should be handed via the parser
# constructor only
if logger is not None and 'logger' not in init_signature.args:
if hasattr(self.parser, 'setup_logger'):
self.parser.setup_logger(logger.bind(parser=self.name))
else:
......
......@@ -234,15 +234,22 @@ def parsed_template_example() -> LocalBackend:
@pytest.fixture(params=parser_examples, ids=lambda spec: '%s-%s' % spec)
def parsed_example(request) -> LocalBackend:
def parsed_example(caplog, request) -> LocalBackend:
parser_name, mainfile = request.param
run_parser(parser_name, mainfile)
return run_parser(parser_name, mainfile)
def test_parser(parsed_example, no_warn):
@pytest.mark.parametrize('parser_name, mainfile', parser_examples)
def test_parser(parser_name, mainfile, caplog):
parsed_example = run_parser(parser_name, mainfile)
assert_parser_result(parsed_example)
logger_received = False
for record in caplog.get_records(when='call'):
if record.levelname == 'DEBUG':
logger_received |= json.loads(record.msg)['event'] == 'received logger'
assert logger_received
def test_match(no_warn):
directory = 'tests/data/proc/match'
......
......@@ -31,5 +31,14 @@ def test_sanitize_logevent():
assert utils.sanitize_logevent('mat [2, [3.3, 2], 10]') == 'mat M'
def test_logging():
utils.get_logger(__name__).debug('test')
def test_logging(no_warn):
utils.get_logger(__name__).info('test msg')
received_test_event = False
for record in no_warn.get_records(when='call'):
assert record.levelname == 'INFO'
data = json.loads(record.msg)
assert 'event' in data
assert data['event'] == 'test msg'
received_test_event = True
assert received_test_event
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