From 6c0042297d4c5f6c53cddc63fc52beb4c167cb3c Mon Sep 17 00:00:00 2001 From: Rubel Date: Thu, 30 Nov 2023 22:03:25 +0100 Subject: [PATCH] CI --- pynxtools/dataconverter/convert.py | 9 +++++---- pynxtools/dataconverter/logger.py | 1 + pynxtools/definitions | 2 +- tests/dataconverter/test_helpers.py | 16 +++++++++++----- tests/dataconverter/test_readers.py | 5 +++-- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/pynxtools/dataconverter/convert.py b/pynxtools/dataconverter/convert.py index 7993c1ec6..854ce3302 100644 --- a/pynxtools/dataconverter/convert.py +++ b/pynxtools/dataconverter/convert.py @@ -34,7 +34,7 @@ from pynxtools.dataconverter.template import Template from pynxtools.nexus import nexus -from .logger import logger +from pynxtools.dataconverter.logger import logger as pynx_logger def get_reader(reader_name) -> BaseReader: @@ -60,7 +60,7 @@ def get_names_of_all_readers() -> List[str]: return all_readers -# pylint: disable=too-many-arguments,too-many-locals +# pylint: disable=too-many-arguments,too-many-locals,W1203 def convert(input_file: Tuple[str], reader: str, nxdl: str, @@ -72,8 +72,9 @@ def convert(input_file: Tuple[str], **kwargs): """The conversion routine that takes the input parameters and calls the necessary functions.""" if logger_: - global logger logger = logger_ + else: + logger = pynx_logger # Reading in the NXDL and generating a template definitions_path = nexus.get_nexus_definitions_path() if nxdl == "NXtest": @@ -123,7 +124,7 @@ def convert(input_file: Tuple[str], if "/@default" in path: continue logger.info( - f"NO DOCUMENTATION: The path, {path} is being written but has no documentation." + f"NO DOCUMENTATION: The path, {path} is being written but has no documentation." ) helpers.add_default_root_attributes(data=data, filename=os.path.basename(output)) diff --git a/pynxtools/dataconverter/logger.py b/pynxtools/dataconverter/logger.py index 69cdb4990..c28ee0b84 100644 --- a/pynxtools/dataconverter/logger.py +++ b/pynxtools/dataconverter/logger.py @@ -1,3 +1,4 @@ +"""Logger for pynxtools""" # # Copyright The NOMAD Authors. # diff --git a/pynxtools/definitions b/pynxtools/definitions index f0d7e0624..f82576cdf 160000 --- a/pynxtools/definitions +++ b/pynxtools/definitions @@ -1 +1 @@ -Subproject commit f0d7e06241585543bd49699face4ac0ff76cc662 +Subproject commit f82576cdf6a9b313b5eeb569dd4f168a7b8cd0fa diff --git a/tests/dataconverter/test_helpers.py b/tests/dataconverter/test_helpers.py index 9cfdf60c6..c7510bc61 100644 --- a/tests/dataconverter/test_helpers.py +++ b/tests/dataconverter/test_helpers.py @@ -24,6 +24,7 @@ import numpy as np from pynxtools.dataconverter import helpers +from pynxtools.dataconverter.logger import logger as pynx_logger from pynxtools.dataconverter.template import Template @@ -286,7 +287,7 @@ def fixture_filled_test_data(template, tmp_path): id="opt-group-completely-removed" ), ]) -def test_validate_data_dict(data_dict, error_message, template, nxdl_root, request): +def test_validate_data_dict(caplog, data_dict, error_message, template, nxdl_root, request): """Unit test for the data validation routine""" if request.node.callspec.id in ("valid-data-dict", "lists", @@ -298,11 +299,16 @@ def test_validate_data_dict(data_dict, error_message, template, nxdl_root, reque "link-dict-instead-of-bool", "allow-required-and-empty-group", "opt-group-completely-removed"): - helpers.validate_data_dict(template, data_dict, nxdl_root) + helpers.validate_data_dict(template, data_dict, nxdl_root, logger=pynx_logger) else: - with pytest.raises(Exception) as execinfo: - helpers.validate_data_dict(template, data_dict, nxdl_root) - assert (error_message) == str(execinfo.value) + try: + captured_logs = caplog.records + helpers.validate_data_dict(template, data_dict, nxdl_root, pynx_logger) + assert any(error_message in rec.message for rec in captured_logs) + except Exception: + with pytest.raises(Exception) as execinfo: + helpers.validate_data_dict(template, data_dict, nxdl_root, pynx_logger) + assert (error_message) == str(execinfo.value) @pytest.mark.parametrize("nxdl_path,expected", [ diff --git a/tests/dataconverter/test_readers.py b/tests/dataconverter/test_readers.py index d75344541..6324b04e3 100644 --- a/tests/dataconverter/test_readers.py +++ b/tests/dataconverter/test_readers.py @@ -25,6 +25,7 @@ import pytest from _pytest.mark.structures import ParameterSet +from pynxtools.dataconverter.logger import logger as pynx_logger from pynxtools.dataconverter.readers.base.reader import BaseReader from pynxtools.dataconverter.convert import \ get_names_of_all_readers, get_reader @@ -101,7 +102,7 @@ def test_has_correct_read_func(reader): read_data = reader().read(template=Template(template), file_paths=tuple(input_files)) assert isinstance(read_data, Template) - assert validate_data_dict(template, read_data, root) + assert validate_data_dict(template, read_data, root, logger=pynx_logger) @pytest.mark.parametrize("reader_name,nxdl,undocumented_keys", [ @@ -129,5 +130,5 @@ def test_shows_correct_warnings(reader_name, nxdl, undocumented_keys): template=Template(template), file_paths=tuple(input_files) ) - assert validate_data_dict(template, read_data, root) + assert validate_data_dict(template, read_data, root, logger=pynx_logger) assert list(read_data.undocumented.keys()) == undocumented_keys