From 39b5f50003183351dc6f05a980b894e67a041a7f Mon Sep 17 00:00:00 2001 From: Lukas Pielsticker <50139597+lukaspie@users.noreply.github.com> Date: Fri, 29 Nov 2024 11:17:03 +0100 Subject: [PATCH] allow for reader to ignore specific lines in log file comparison --- src/pynxtools/testing/nexus_conversion.py | 30 ++++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/pynxtools/testing/nexus_conversion.py b/src/pynxtools/testing/nexus_conversion.py index 3264d5203..5481cc872 100644 --- a/src/pynxtools/testing/nexus_conversion.py +++ b/src/pynxtools/testing/nexus_conversion.py @@ -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 @@ -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: @@ -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}" )