-
Notifications
You must be signed in to change notification settings - Fork 10
Avoid name conflict with BaseSection classes #453
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a41d6df
rename group names if they are used in the BaseSection class
lukaspie 1e45e65
restructure nomad tests
lukaspie e24b729
temporarily install nomad feature branch in tests
lukaspie 3cc3fcc
add test for schema
lukaspie c69c564
ignore myp error on nexus_schema.NeXus
lukaspie 6e34ffd
use renaming function in tests
lukaspie 9249732
bring XML_NAMESPACES back to schema
lukaspie 3561117
rename to __XML_NAMESPACES
lukaspie d33981a
include field and attribute renaming, capitalization
lukaspie 46caf4e
small docs change
lukaspie ab40557
remove capitalization
lukaspie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10000
span>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
"""This is a code that performs several tests on nexus tool""" | ||
|
||
# | ||
# Copyright The NOMAD Authors. | ||
# | ||
# This file is part of NOMAD. See https://nomad-lab.eu for further info. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
import pytest | ||
|
||
try: | ||
from nomad.metainfo import Section | ||
except ImportError: | ||
pytest.skip("nomad not installed", allow_module_level=True) | ||
|
||
from typing import Any | ||
|
||
from pynxtools.nomad.schema import nexus_metainfo_package | ||
from pynxtools.nomad.utils import __rename_nx_for_nomad as rename_nx_for_nomad | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"path,value", | ||
[ | ||
pytest.param("name", "nexus"), | ||
pytest.param("NXobject.name", "NXobject"), | ||
pytest.param(rename_nx_for_nomad("NXentry") + ".nx_kind", "group"), | ||
pytest.param(rename_nx_for_nomad("NXdetector") + ".real_time__field", "*"), | ||
pytest.param(rename_nx_for_nomad("NXentry") + ".DATA.nx_optional", True), | ||
pytest.param(rename_nx_for_nomad("NXentry") + ".DATA.nx_kind", "group"), | ||
pytest.param(rename_nx_for_nomad("NXentry") + ".DATA.nx_optional", True), | ||
pytest.param( | ||
rename_nx_for_nomad("NXdetector") + ".real_time__field.name", | ||
"real_time__field", | ||
), | ||
pytest.param( | ||
rename_nx_for_nomad("NXdetector") + ".real_time__field.nx_type", "NX_NUMBER" | ||
), | ||
pytest.param( | ||
rename_nx_for_nomad("NXdetector") + ".real_time__field.nx_units", "NX_TIME" | ||
), | ||
pytest.param(rename_nx_for_nomad("NXarpes") + ".ENTRY.DATA.nx_optional", False), | ||
pytest.param(rename_nx_for_nomad("NXentry") + ".nx_category", "base"), | ||
pytest.param( | ||
rename_nx_for_nomad("NXdispersion_table") | ||
+ ".refractive_index__field.nx_type", | ||
"NX_COMPLEX", | ||
), | ||
pytest.param( | ||
rename_nx_for_nomad("NXdispersive_material") | ||
+ ".ENTRY.dispersion_x." | ||
+ "DISPERSION_TABLE.refractive_index__field.nx_type", | ||
"NX_COMPLEX", | ||
), | ||
pytest.param(rename_nx_for_nomad("NXapm") + ".nx_category", "application"), | ||
], | ||
) | ||
def test_assert_nexus_metainfo(path: str, value: Any): | ||
""" | ||
Test the existence of nexus metainfo | ||
|
||
pytest.param('NXdispersive_material.inner_section_definitions[0].sub_sections[1].sub_section.inner_section_definitions[0].quantities[4].more["nx_type"] | ||
""" | ||
current = nexus_metainfo_package | ||
for name in path.split("."): | ||
elements: list = [] | ||
if name.endswith("__field"): | ||
subelement_list = getattr(current, "quantities", None) | ||
if subelement_list: | ||
elements += subelement_list | ||
else: | ||
subelement_list = getattr(current, "section_definitions", None) | ||
if subelement_list: | ||
elements += subelement_list | ||
subelement_list = getattr(current, "sub_sections", None) | ||
if subelement_list: | ||
elements += subelement_list | ||
subelement_list = getattr(current, "attributes", None) | ||
if subelement_list: | ||
elements += subelement_list | ||
subelement_list = current.m_contents() | ||
if subelement_list: | ||
elements += subelement_list | ||
for content in elements: | ||
if getattr(content, "name", None) == name: | ||
current = content # type: ignore | ||
if getattr(current, "sub_section", None): | ||
current = current.section_definition | ||
break | ||
else: | ||
current = getattr(current, name, None) | ||
if current is None: | ||
assert False, f"{path} does not exist" | ||
|
||
if value == "*": | ||
assert current is not None, f"{path} does not exist" | ||
elif value is None: | ||
assert current is None, f"{path} does exist" | ||
else: | ||
assert current == value, f"{path} has wrong value" | ||
|
||
if isinstance(current, Section): | ||
assert current.nx_kind is not None | ||
for base_section in current.all_base_sections: | ||
assert base_section.nx_kind == current.nx_kind |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 must be changed back later.