Skip to content

Commit

Permalink
Add util tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ka-sarthak committed Aug 13, 2024
1 parent ca0f78d commit 41d5331
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/data/processed_reactions/paper_0_reaction_1.archive.yaml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions tests/data/processed_reactions/paper_5_reaction_1.archive.yaml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 41d5331

Please sign in to comment.