-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test nxdl hdf5 validator #280
base: fairmat
Are you sure you want to change the base?
Changes from all commits
cbff1e1
df93d00
40a2e8a
6c98493
3edba61
5ff1937
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?xml-stylesheet type="text/xsl" href="nxdlformat.xsl" ?> | ||
<definition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://definition.nexusformat.org/nxdl/3.1 ../nxdl.xsd" | ||
xmlns="http://definition.nexusformat.org/nxdl/3.1" | ||
name="NXhdf5_validator_1" | ||
extends="NXobject" | ||
type="group" | ||
category="application" | ||
> | ||
<doc>This is a dummy NXDL to test out the dataconverter.</doc> | ||
<group type="NXentry"> | ||
<field name="hdf5_validator_1_program_name"/> | ||
<field name="definition"> | ||
<doc>This is a dummy NXDL to test out the dataconverter.</doc> | ||
<attribute name="version"/> | ||
<enumeration> | ||
<item value="hdf5_validator_1"/> | ||
<item value="hdf5_VALIDATOR_1"/> | ||
<item value="HDF5_VALIDATOR_1"/> | ||
</enumeration> | ||
</field> | ||
<group type="NXdata" name="hdf5_validator_1_data" optional="true"> | ||
<attribute name="signal"/> | ||
<attribute name="auxiliary_signals"/> | ||
<attribute name="AXISNAME_indices" type="NX_NUMBER"/> | ||
<attribute name="axes"/> | ||
<field name="AXISNAME" units="NX_ANY"/> | ||
<attribute name="long_name"/> | ||
<field name="DATA" type="NX_NUMBER" units="NX_ANY"/> | ||
</group> | ||
<group type="NXnote" name="hdf5_validator_1_required" optional="true"> | ||
<doc>This is a required yet empty group.</doc> | ||
<field name="required_field" type="NX_CHAR"/> | ||
</group> | ||
</group> | ||
</definition> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?xml-stylesheet type="text/xsl" href="nxdlformat.xsl" ?> | ||
<definition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://definition.nexusformat.org/nxdl/3.1 ../nxdl.xsd" | ||
xmlns="http://definition.nexusformat.org/nxdl/3.1" | ||
name="NXhdf5_validator_2" | ||
extends="NXhdf5_validator_1" | ||
type="group" | ||
category="application" | ||
> | ||
<doc>This is a dummy NXDL to test out the dataconverter.</doc> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above |
||
<group type="NXentry"> | ||
<field name="hdf5_validator_2_program_name"/> | ||
|
||
<group type="NXnote" name="hdf5_validator_2_required"> | ||
<doc>This is a required yet empty group.</doc> | ||
<field name="required_field" type="NX_CHAR"/> | ||
</group> | ||
<group type="NXuser" name="hdf5_validator_2_users_req"> | ||
<doc>This is a required yet empty group.</doc> | ||
<field name="required_field" type="NX_CHAR"/> | ||
</group> | ||
<group name="experiment_result" type="NXdata"> | ||
<doc> | ||
All experiment results data such as scattering angle (2theta), | ||
intensity, incident angle, scattering vector, etc will be stored here. | ||
</doc> | ||
<field name="hdf5_validator_2_intensity" type="NX_FLOAT"> | ||
<doc> | ||
Number of scattered electrons per unit time. | ||
</doc> | ||
<dimensions rank="2"> | ||
<dim index="1" value="nX"/> | ||
<dim index="1" value="nY"/> | ||
</dimensions> | ||
</field> | ||
</group> | ||
</group> | ||
</definition> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,11 @@ | |
from ..globals.directories import get_xsd_file | ||
from ..nxdl import iter_definitions | ||
|
||
SKIP_FILES_FROM_TESTS = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get why you skipped these files here, but should the doc generation not just work on them if they are valid files? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, my mistake, I just skip the doc generation not all the tests, where some tests validate the nexus data structure. The files are not presentable to the outer users. I think Doc generation would make this NXDL accessible to the public. As the files are reference app defs for nexus file validator, later I will add further nxdl to make the validator fail. And the doc generating does not give validity to the files. NXDL validation performed test in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "The files are not presentable to the outer users. I think Doc generation would make this NXDL accessible to the public." I don't understand this, but this is probably related to my comment above. The user should never be able to use an NXDL in |
||
"NXhdf5_validator_2.nxdl.xml", | ||
"NXhdf5_validator_1.nxdl.xml", | ||
] | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def doc_generator(): | ||
|
@@ -28,16 +33,22 @@ def anchor_registry_write(tmpdir_factory): | |
|
||
@pytest.mark.parametrize("nxdl_file", list(iter_definitions())) | ||
def test_nxdl_generate_doc(nxdl_file, doc_generator): | ||
if nxdl_file.name in SKIP_FILES_FROM_TESTS: | ||
pytest.skip(f"Skip {nxdl_file.name}") | ||
assert doc_generator(nxdl_file) | ||
|
||
|
||
@pytest.mark.parametrize("nxdl_file", list(iter_definitions())) | ||
def test_nxdl_anchor_list(nxdl_file, doc_generator, anchor_registry): | ||
if nxdl_file.name in SKIP_FILES_FROM_TESTS: | ||
pytest.skip(f"Skip {nxdl_file.name}") | ||
assert doc_generator(nxdl_file, anchor_registry=anchor_registry) | ||
|
||
|
||
@pytest.mark.parametrize("nxdl_file", list(iter_definitions())) | ||
def test_nxdl_anchor_write_list(nxdl_file, doc_generator, anchor_registry_write): | ||
if nxdl_file.name in SKIP_FILES_FROM_TESTS: | ||
pytest.skip(f"Skip {nxdl_file.name}") | ||
assert doc_generator(nxdl_file, anchor_registry=anchor_registry_write) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,9 +44,15 @@ def get_app_defs_names(): | |
app_def_path_glob = nexus_def_path / "applications" / "*.nxdl*" | ||
|
||
contrib_def_path_glob = Path(nexus_def_path) / "contributed_definitions" / "*.nxdl*" | ||
test_def_path_glob = Path(nexus_def_path) / "dev_tools/tests/data" / "*.nxdl*" | ||
|
||
files = sorted(glob(str(app_def_path_glob))) | ||
for nexus_file in sorted(glob(str(contrib_def_path_glob))): | ||
delte_files = sorted(glob(str(contrib_def_path_glob))) + sorted( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not used at all |
||
glob(str(test_def_path_glob)) | ||
) | ||
for nexus_file in sorted(glob(str(contrib_def_path_glob))) + sorted( | ||
glob(str(test_def_path_glob)) | ||
): | ||
root = get_xml_root(nexus_file) | ||
if root.attrib["category"] == "application": | ||
files.append(nexus_file) | ||
|
@@ -363,7 +369,12 @@ def find_definition_file(bc_name): | |
Note that it first checks in contributed and goes beyond only if no contributed found | ||
""" | ||
bc_filename = None | ||
for nxdl_folder in ["contributed_definitions", "base_classes", "applications"]: | ||
for nxdl_folder in [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems a bit awkward to also search the |
||
"contributed_definitions", | ||
"base_classes", | ||
"applications", | ||
"dev_tools/tests/data", | ||
]: | ||
nxdl_file = nexus_def_path / nxdl_folder / f"{bc_name}.nxdl.xml" | ||
if nxdl_file.exists(): | ||
bc_filename = nexus_def_path / nxdl_folder / f"{bc_name}.nxdl.xml" | ||
|
@@ -517,9 +528,7 @@ def check_attr_name_nxdl(param): | |
return logger, elem, nxdl_path, doc, attr, req_str | ||
|
||
|
||
def try_find_default( | ||
logger, orig_elem, elem, nxdl_path, doc, attr | ||
): # pylint: disable=too-many-arguments | ||
def try_find_default(logger, orig_elem, elem, nxdl_path, doc, attr): # pylint: disable=too-many-arguments | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what changed here? |
||
"""Try to find if default is defined as a child of the NXDL element""" | ||
if elem is not None: | ||
if doc: | ||
|
@@ -539,9 +548,7 @@ def try_find_default( | |
return logger, elem, nxdl_path, doc, attr | ||
|
||
|
||
def other_attrs( | ||
logger, orig_elem, elem, nxdl_path, doc, attr | ||
): # pylint: disable=too-many-arguments | ||
def other_attrs(logger, orig_elem, elem, nxdl_path, doc, attr): # pylint: disable=too-many-arguments | ||
"""Handle remaining attributes""" | ||
if elem is not None: | ||
if doc: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not mention the dataconverter, which is a pynxtools concept. Just say it is a dummy for testing validation.