Skip to content
Snippets Groups Projects
Commit 5c441ea5 authored by Hans Fangohr's avatar Hans Fangohr
Browse files

additional tests

parent 464b60e1
No related branches found
No related tags found
1 merge request!28improve machine readable logging
"""Tests for mpsd-software-environment.py."""
import importlib
import logging
import os
import shutil
import subprocess
......@@ -317,18 +318,41 @@ def test_install_environment_zlib():
def test_metadata_logging(tmp_path):
"""Test that metadata is logged and read correctly."""
# Test that the metadata is logged correctly
mod.set_up_logging(loglevel="debug", filename=tmp_path / "test-metadata.log")
key = "important_key"
value = "important_value"
mod.log_metadata(key, value)
open_tag = mod.config_vars["metadata_tag_open"]
close_tag = mod.config_vars["metadata_tag_close"]
expected_log = f"{open_tag}{key}:{value}{close_tag}"
filename = tmp_path / "test-metadata.log"
print(f"Writing to {filename}")
mod.set_up_logging(loglevel="debug", filename=filename)
# our test data
keys = ["important_key", "important_value2"]
values = ["important_value", "important_value2"]
expected_log_entries = []
for key, value in zip(keys, values):
mod.log_metadata(key, value)
mod.log_metadata(key, value)
open_tag = mod.config_vars["metadata_tag_open"]
close_tag = mod.config_vars["metadata_tag_close"]
expected_log = f"{open_tag}{key}:{value}{close_tag}"
expected_log_entries.append(expected_log)
logging.info(f"Add some other info (after adding {key=})")
logging.debug("Add some other info")
logging.warning("Add some other info")
# Check that relevant lines show up in the log file somewhere
with open(tmp_path / "test-metadata.log", "r") as f:
assert expected_log in f.read()
# Test that the metadata is read correctly
logfile_content = f.read()
for expected_log in expected_log_entries:
assert expected_log in logfile_content
# Test that the metadata is read correctly using our parser
read_dict = mod.read_metadata_from_logfile(tmp_path / "test-metadata.log")
assert read_dict[key] == value
# check all entries are in the file
for key, value in zip(keys, values):
read_dict[key] == value
# check no additional entries are there
assert len(read_dict) == len(keys)
def test_interface(tmp_path):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment