Commit a37ab744 authored by Mohammad Nakhaee's avatar Mohammad Nakhaee
Browse files

Add test for processing empty section

parent 8870a8ec
Pipeline #130491 passed with stages
in 27 minutes and 55 seconds
......@@ -47,16 +47,11 @@ class MetainfoNormalizer(Normalizer):
logger = logger.bind(normalizer=self.__class__.__name__)
self.logger = logger
if self.entry_archive.data:
sections = list(self.entry_archive.data.m_traverse())
if sections:
for sub_section in self.entry_archive.m_contents():
if isinstance(sub_section, EntryData):
sections = list(sub_section.m_traverse())
for section, _, _ in sections:
self.normalize_section(section, logger)
else:
self.normalize_section(self.entry_archive.data, logger)
for sub_section in self.entry_archive.m_contents():
if not isinstance(sub_section, EntryData):
self.normalize_section(sub_section, logger)
self.normalize_section(sub_section, logger)
self.normalize_section(self.entry_archive, logger)
{
"data": {
"m_def": "nomad.datamodel.metainfo.eln.material_library.Chemical"
}
}
\ No newline at end of file
......@@ -16,33 +16,25 @@
# limitations under the License.
#
from nomad.datamodel.context import ServerContext
from nomad.datamodel.datamodel import EntryArchive, EntryMetadata
from nomad.parsing.parser import ArchiveParser
from nomad.processing.data import Upload
from tests.normalizing.conftest import run_normalize
from tests.test_files import create_test_upload_files
from tests.normalizing.conftest import run_processing
def test_processing(raw_files, no_warn):
directory = 'tests/data/datamodel/metainfo/eln/material_library'
mainfile = 'example.archive.json'
# create upload with example files
upload_files = create_test_upload_files('test_upload_id', published=False, raw_files=directory)
upload = Upload(upload_id='test_upload_id')
# parse
parser = ArchiveParser()
context = ServerContext(upload=upload)
test_archive = EntryArchive(m_context=context, metadata=EntryMetadata())
parser.parse(
upload_files.raw_file_object(mainfile).os_path,
test_archive)
run_normalize(test_archive)
test_archive = run_processing(directory, mainfile)
# assert archive
assert test_archive.metadata.entry_type == 'Sample'
assert len(test_archive.data.processes.pvd_evaporation.substrate_temperature) > 0
assert len(test_archive.data.measurements.xray_diffraction[0].two_theta) > 0
assert len(test_archive.data.layers) == 1
def test_processing_empty_chemical(raw_files, no_warn):
directory = 'tests/data/datamodel/metainfo/eln/material_library'
mainfile = 'chemical-empty.archive.json'
test_archive = run_processing(directory, mainfile)
# assert archive
assert test_archive.metadata.entry_type == 'Chemical'
......@@ -47,6 +47,11 @@ from tests.parsing.test_parsing import parsed_vasp_example # pylint: disable=un
from tests.parsing.test_parsing import parsed_template_example # pylint: disable=unused-import
from tests.parsing.test_parsing import parsed_example # pylint: disable=unused-import
from tests.parsing.test_parsing import parse_file
from nomad.datamodel.context import ServerContext
from nomad.datamodel.datamodel import EntryArchive, EntryMetadata
from nomad.parsing.parser import ArchiveParser
from nomad.processing.data import Upload
from tests.test_files import create_test_upload_files
def run_normalize(entry_archive: EntryArchive) -> EntryArchive:
......@@ -56,6 +61,22 @@ def run_normalize(entry_archive: EntryArchive) -> EntryArchive:
return entry_archive
def run_processing(directory, mainfile):
# create upload with example files
upload_files = create_test_upload_files('test_upload_id', published=False, raw_files=directory)
upload = Upload(upload_id='test_upload_id')
# parse
parser = ArchiveParser()
context = ServerContext(upload=upload)
test_archive = EntryArchive(m_context=context, metadata=EntryMetadata())
parser.parse(
upload_files.raw_file_object(mainfile).os_path,
test_archive)
run_normalize(test_archive)
return test_archive
@pytest.fixture
def normalized_vasp_example(parsed_vasp_example: EntryArchive) -> EntryArchive:
return run_normalize(parsed_vasp_example)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment