diff --git a/tests/parsers/test_myparser.py b/tests/parsers/test_myparser.py new file mode 100644 index 0000000..c356283 --- /dev/null +++ b/tests/parsers/test_myparser.py @@ -0,0 +1,12 @@ +import logging + +from nomad.datamodel import EntryArchive +from nomad_uibk_plugin.parsers.myparser import MyParser + + +def test_parse_file(): + parser = MyParser() + archive = EntryArchive() + parser.parse('tests/data/example.out', archive, logging.getLogger()) + + assert archive.results.material.elements == ['H', 'O'] diff --git a/tests/parsers/test_parser.py b/tests/parsers/test_parser.py index c356283..db4b52a 100644 --- a/tests/parsers/test_parser.py +++ b/tests/parsers/test_parser.py @@ -1,12 +1,37 @@ -import logging +import os -from nomad.datamodel import EntryArchive -from nomad_uibk_plugin.parsers.myparser import MyParser +import pytest +from nomad.client import normalize_all, parse -def test_parse_file(): - parser = MyParser() - archive = EntryArchive() - parser.parse('tests/data/example.out', archive, logging.getLogger()) +@pytest.fixture(params=['QNT20220823_A1_2m.txt']) +def parsed_archive(request): + """ + Sets up a parsed archive and cleans up afterwards. + """ + file_path = os.path.join('tests', 'data', request.param) + archive_from_file = parse(file_path)[0] + measurement = os.path.join( + 'tests', 'data', '.'.join(request.param.split('.')[:-1]) + '.archive.json' + ) + assert archive_from_file.data.measurement.m_proxy_value == os.path.abspath( + measurement + ) + measurement_archive = parse(measurement)[0] - assert archive.results.material.elements == ['H', 'O'] + yield measurement_archive + + if os.path.exists(measurement): + os.remove(measurement) + + +def test_normalize_all(parsed_archive): + """ + Tests the normalization of data in the archive. + """ + normalize_all(parsed_archive) + + # checks for different parsers + if parsed_archive.data.method == 'X-Ray Fluorescence (XRF)': + # TODO: Add tests specific for XRF method + pass