Skip to content

Commit

Permalink
allow for reader to ignore specific lines in log file comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaspie committed Nov 29, 2024
1 parent 210230d commit 39b5f50
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/pynxtools/testing/nexus_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import logging
import os
from glob import glob
from typing import List, Literal, Tuple
from typing import List, Literal, Tuple, Dict

try:
from nomad.client import parse
Expand Down Expand Up @@ -159,20 +159,26 @@ def convert_to_nexus(

parse(self.created_nexus, **kwargs)

def check_reproducibility_of_nexus(self):
def check_reproducibility_of_nexus(self, **kwargs):
"""Reproducibility test for the generated nexus file."""
IGNORE_LINES = [
reader_ignore_lines: List[str] = kwargs.get("ignore_lines", [])
reader_ignore_sections: Dict[str, List[str]] = kwargs.get("ignore_sections", {})

IGNORE_LINES: List[str] = reader_ignore_lines + [
"DEBUG - value: v",
"DEBUG - value: https://github.com/FAIRmat-NFDI/nexus_definitions/blob/",
"DEBUG - ===== GROUP (// [NXroot::]):",
]
SECTION_IGNORE = {
"ATTRS (//@HDF5_version)": ["DEBUG - value:"],
"ATTRS (//@file_name)": ["DEBUG - value:"],
"ATTRS (//@file_time)": ["DEBUG - value:"],
"ATTRS (//@file_update_time)": ["DEBUG - value:"],
"ATTRS (//@h5py_version)": ["DEBUG - value:"],
}
IGNORE_SECTIONS: Dict[str, List[str]] = reader_ignore_sections.update(
{
"ATTRS (//@HDF5_version)": ["DEBUG - value:"],
"ATTRS (//@file_name)": ["DEBUG - value:"],
"ATTRS (//@file_time)": ["DEBUG - value:"],
"ATTRS (//@file_update_time)": ["DEBUG - value:"],
"ATTRS (//@h5py_version)": ["DEBUG - value:"],
}
)

SECTION_SEPARATOR = "DEBUG - ===== "

def should_skip_line(gen_l: str, ref_l: str, ignore_lines: List[str]) -> bool:
Expand Down Expand Up @@ -207,14 +213,14 @@ def compare_logs(gen_lines: List[str], ref_lines: List[str]) -> None:
SECTION_SEPARATOR
):
section = gen_l.rsplit(SECTION_SEPARATOR)[-1].strip()
section_ignore_lines = SECTION_IGNORE.get(section, [])
section_ignore_lines = IGNORE_SECTIONS.get(section, [])

# Compare lines if not in ignore list
if gen_l != ref_l and not should_skip_line(
gen_l, ref_l, IGNORE_LINES + section_ignore_lines
):
raise AssertionError(
f"Log files are different at line {ind}\n"
f"Log files are diqfferent at line {ind}\n"
f"generated: {gen_l}\nreferenced: {ref_l}"
)

Expand Down

0 comments on commit 39b5f50

Please sign in to comment.