Skip to content

Commit

Permalink
Merge pull request #457 from FAIRmat-NFDI/fix-type-hints
Browse files Browse the repository at this point in the history
Fix type hints
  • Loading branch information
lukaspie authored Oct 31, 2024
2 parents 9368155 + 38a5020 commit e002c09
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/pynxtools/testing/nexus_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import os
from glob import glob
from typing import Literal
from typing import Literal, List, Tuple

try:
from nomad.client import parse
Expand Down Expand Up @@ -150,7 +150,7 @@ def check_reproducibility_of_nexus(self):
}
SECTION_SEPARATOR = "DEBUG - ===== "

def should_skip_line(gen_l: str, ref_l: str, ignore_lines: list[str]) -> bool:
def should_skip_line(gen_l: str, ref_l: str, ignore_lines: List[str]) -> bool:
"""Check if both lines start with any ignored prefix."""
return any(
gen_l.startswith(ignore) and ref_l.startswith(ignore)
Expand All @@ -159,17 +159,17 @@ def should_skip_line(gen_l: str, ref_l: str, ignore_lines: list[str]) -> bool:

def load_logs(
gen_log_path: str, ref_log_path: str
) -> tuple[list[str], list[str]]:
) -> Tuple[List[str], List[str]]:
"""Load log files and return their contents as lists of lines."""
with open(gen_log_path, "r", encoding="utf-8") as gen, open(
ref_log_path, "r", encoding="utf-8"
) as ref:
return gen.readlines(), ref.readlines()

def compare_logs(gen_lines: list[str], ref_lines: list[str]) -> None:
def compare_logs(gen_lines: List[str], ref_lines: List[str]) -> None:
"""Compare log lines, ignoring specific differences."""
if len(gen_lines) != len(ref_lines):
assert False, (
raise AssertionError(
f"Log files are different: mismatched line counts. "
f"Generated file has {len(gen_lines)} lines, "
f"while reference file has {len(ref_lines)} lines."
Expand All @@ -188,11 +188,12 @@ def compare_logs(gen_lines: list[str], ref_lines: list[str]) -> None:
if gen_l != ref_l and not should_skip_line(
gen_l, ref_l, IGNORE_LINES + section_ignore_lines
):
assert False, (
raise AssertionError(
f"Log files are different at line {ind}\n"
f"generated: {gen_l}\nreferenced: {ref_l}"
)

# Load log paths
ref_log_path = get_log_file(self.ref_nexus_file, "ref_nexus.log", self.tmp_path)
gen_log_path = get_log_file(self.created_nexus, "gen_nexus.log", self.tmp_path)
gen_lines, ref_lines = load_logs(gen_log_path, ref_log_path)
Expand Down

0 comments on commit e002c09

Please sign in to comment.