Skip to content

Commit

Permalink
CI
Browse files Browse the repository at this point in the history
  • Loading branch information
RubelMozumder committed Nov 30, 2023
1 parent 4bc1af3 commit 6c00422
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
9 changes: 5 additions & 4 deletions pynxtools/dataconverter/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand All @@ -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":
Expand Down Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions pynxtools/dataconverter/logger.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Logger for pynxtools"""
#
# Copyright The NOMAD Authors.
#
Expand Down
2 changes: 1 addition & 1 deletion pynxtools/definitions
Submodule definitions updated 297 files
16 changes: 11 additions & 5 deletions tests/dataconverter/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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",
Expand All @@ -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", [
Expand Down
5 changes: 3 additions & 2 deletions tests/dataconverter/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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", [
Expand Down Expand Up @@ -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

0 comments on commit 6c00422

Please sign in to comment.