Skip to content

Commit

Permalink
Added controller test
Browse files Browse the repository at this point in the history
  • Loading branch information
kmlefran committed Jan 26, 2024
1 parent 41d1917 commit 55553f4
Show file tree
Hide file tree
Showing 2 changed files with 197 additions and 0 deletions.
147 changes: 147 additions & 0 deletions example/test.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The aiida extension is already loaded. To reload it, use:\n",
" %reload_ext aiida\n"
]
}
],
"source": [
"from aiida_aimall.controllers import G16FragController\n",
"%load_ext aiida\n",
"%aiida\n",
"\n",
"con = G16FragController(\n",
" parent_group_label = \"foo\",\n",
" group_label = \"fa\",\n",
" code_label = \"foo\",\n",
" max_concurrent = 1,\n",
" g16_opt_params={}\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"from aiida.orm import Group"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"g= Group(label = \"fi\")"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"g.is_stored"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Group: 'fi' [type core], of user [email protected]>"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"g.store()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"f = Group(label=\"fi\")"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"g."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "aiida3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
50 changes: 50 additions & 0 deletions tests/controllers/test_g16fragcontroller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""Tests for aiida_aimall.controllers"""
import pytest
from aiida.common.exceptions import NotExistent
from aiida.orm import Group, Str

# pylint:disable=no-name-in-module
from aiida_aimall.controllers import G16FragController

# pylint:disable=no-name-in-module
from aiida_aimall.workchains import G16OptWorkchain # pylint:disable=no-name-in-module


def test_unstored_parentgrouplabel_returns_error():
"""Test that error returns when groups are not defined"""
with pytest.raises(NotExistent) as excinfo:
G16FragController(
parent_group_label="inp_frag",
group_label="opt_workchain",
max_concurrent=1,
code_label="test.aimall.aimqb",
g16_opt_params={},
)
assert str(excinfo.value) == "No result was found"


def test_g16frag_controller():
"""Test that error returns when groups are not defined"""
gr = Group(label="opt_workchain")
gr.store()
gr = Group(label="inp_frag")
gr.store()
# with pytest.raises(NotExistent) as excinfo:
con = G16FragController(
parent_group_label="inp_frag",
group_label="opt_workchain",
max_concurrent=1,
code_label="test.aimall.aimqb",
g16_opt_params={},
)
assert con.get_extra_unique_keys() == ("smiles",)
struct = Str("C 0.0 0.0 0.0\nH -0.5,0.0,0.0\nC 0.5 0.0 0.0\n H 1.0, 0.0,0.0")
struct.base.extras.set("smiles", "CtC")
struct.store()
ins, wfs = con.get_inputs_and_processclass_from_extras(extras_values="CtC")
assert isinstance(ins, dict)
assert "frag_label" in ins
assert "fragment_dict" in ins
assert "g16_code" in ins
assert "g16_opt_params" in ins
assert isinstance(wfs, G16OptWorkchain)

0 comments on commit 55553f4

Please sign in to comment.