Skip to content

Commit

Permalink
fixing test.
Browse files Browse the repository at this point in the history
  • Loading branch information
RubelMozumder committed Dec 20, 2023
1 parent 1c4d0c3 commit 9ba3d9b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
13 changes: 6 additions & 7 deletions pynxtools/dataconverter/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,20 @@
#
"""Helper functions commonly used by the convert routine."""

from typing import List, Optional, Any
from typing import Tuple, Callable, Union
import json
import re
import xml.etree.ElementTree as ET
from datetime import datetime, timezone
import json
from typing import Any, Callable, List, Optional, Tuple, Union

import h5py
import numpy as np
from ase.data import chemical_symbols
import h5py

from pynxtools import get_nexus_version, get_nexus_version_hash
from pynxtools.dataconverter.logger import logger as pynx_logger
from pynxtools.nexus import nexus
from pynxtools.nexus.nexus import NxdlAttributeError
from pynxtools.dataconverter.logger import logger as pynx_logger


def is_a_lone_group(xml_element) -> bool:
Expand Down Expand Up @@ -510,8 +509,8 @@ def ensure_all_required_fields_exist(template, data, nxdl_root, logger=pynx_logg
)
continue
if not does_group_exist(renamed_path, data):
raise ValueError(f"The required group, {path}, hasn't been supplied.")
continue
logger.warning(f"The required group, {path}, hasn't been supplied.")
continue
if not is_path_in_data_dict or data[renamed_path] is None:
logger.warning(
f"The data entry corresponding to {path} is required "
Expand Down
36 changes: 14 additions & 22 deletions tests/dataconverter/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
#
"""Test cases for the helper functions used by the DataConverter."""

import xml.etree.ElementTree as ET
import os
import logging
from setuptools import distutils
import pytest
import os
import xml.etree.ElementTree as ET

import numpy as np
import pytest
from setuptools import distutils

from pynxtools.dataconverter import helpers
from pynxtools.dataconverter.logger import logger as pynx_logger
Expand Down Expand Up @@ -351,21 +352,8 @@ def fixture_filled_test_data(template, tmp_path):
id="missing-empty-yet-required-group2",
),
pytest.param(
alter_dict(
remove_from_dict(
TEMPLATE, "/ENTRY[my_entry]/required_group/description"
),
"The required group, /ENTRY[entry]/required_group, hasn't been supplied.",
id="missing-empty-yet-required-group",
),
pytest.param(
remove_from_dict(
TEMPLATE, "/ENTRY[my_entry]/required_group2/description"
),
"The required group, /ENTRY[entry]/required_group2, hasn't been supplied.",
id="missing-empty-yet-required-group2",
),
(""),
remove_from_dict(TEMPLATE, "/ENTRY[my_entry]/required_group/description"),
"The required group, /ENTRY[entry]/required_group, hasn't been supplied.",
id="allow-required-and-empty-group",
),
pytest.param(
Expand All @@ -388,7 +376,7 @@ def fixture_filled_test_data(template, tmp_path):
def test_validate_data_dict(
caplog, data_dict, error_message, template, nxdl_root, request
):
"""Unit test for the data validation routine"""
"""Unit test for the data validation routine."""
if request.node.callspec.id in (
"valid-data-dict",
"lists",
Expand All @@ -398,15 +386,19 @@ def test_validate_data_dict(
"no-child-provided-optional-parent",
"int-instead-of-chars",
"link-dict-instead-of-bool",
"allow-required-and-empty-group",
"opt-group-completely-removed",
):
helpers.validate_data_dict(template, data_dict, nxdl_root, logger=pynx_logger)
# Missing required fields
# Missing required fields caught by logger with warning
elif request.node.callspec.id in (
"empty-required-field",
"allow-required-and-empty-group",
"req-group-in-opt-parent-removed",
"missing-empty-yet-required-group",
"missing-empty-yet-required-group2",
):
assert "" == caplog.text
# logger records
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)
Expand Down

0 comments on commit 9ba3d9b

Please sign in to comment.