diff --git a/tests/data/processed_reactions/paper_0_reaction_1.archive.yaml b/tests/data/processed_reactions/paper_0_reaction_1.archive.yaml new file mode 100644 index 0000000..22cd521 --- /dev/null +++ b/tests/data/processed_reactions/paper_0_reaction_1.archive.yaml @@ -0,0 +1,13 @@ +data: + extracted_json_data: paper_0.json + m_def: nomad_polymerization_reactions.schema_packages.mypackage.PolymerizationReaction + monomers: + - smiles: C=C + substance_name: ethylene + - smiles: C=O + substance_name: carbon monoxide + publication_reference: + DOI_number: https://doi.org/10.1002/pol.1963.110010415 + reaction_conditions: + method: bulk + temperature: 293.15 diff --git a/tests/data/processed_reactions/paper_5_reaction_1.archive.yaml b/tests/data/processed_reactions/paper_5_reaction_1.archive.yaml new file mode 100644 index 0000000..86afefd --- /dev/null +++ b/tests/data/processed_reactions/paper_5_reaction_1.archive.yaml @@ -0,0 +1,16 @@ +data: + extracted_json_data: paper_5.json + logP: 0.38710000000000006 + m_def: nomad_polymerization_reactions.schema_packages.mypackage.PolymerizationReaction + monomers: + - smiles: C=C(C)C(=O)OC + substance_name: Methyl Methacrylate + - smiles: C=C(C)C(=O)O + substance_name: Methacrylic Acid + publication_reference: + DOI_number: https://doi.org/10.1016/0014-3057(94)00111-1 + reaction_conditions: + method: solvent + solvent: + name: CC(C)O + temperature: 343.15 diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..b34d0d4 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,29 @@ +import os + +import pytest +import yaml +from nomad_polymerization_reactions.utils import generate_archive_from_llm_output + + +@pytest.mark.parametrize( + 'params', + [ + { + 'filepath': 'tests/data/processed_reactions/paper_0_reaction_1.json', + 'reference': 'tests/data/processed_reactions/paper_0_reaction_1.archive.yaml', + }, + { + 'filepath': 'tests/data/processed_reactions/paper_5_reaction_1.json', + 'reference': 'tests/data/processed_reactions/paper_5_reaction_1.archive.yaml', + }, + ], +) +def test_generate_archive_from_llm_output(params): + output = generate_archive_from_llm_output(params['filepath']) + with open(params['reference']) as f: + reference = yaml.load(f, Loader=yaml.FullLoader) + assert output == reference + + # remove the generated file + generated_file = f'{params["filepath"].split("/")[-1].split(".")[0]}.archive.yaml' + os.remove(generated_file)