From 55553f4394116e2b3b20e59d1b839adb2fcccd81 Mon Sep 17 00:00:00 2001 From: kmlefran Date: Fri, 26 Jan 2024 09:38:43 -0500 Subject: [PATCH] Added controller test --- example/test.ipynb | 147 ++++++++++++++++++++ tests/controllers/test_g16fragcontroller.py | 50 +++++++ 2 files changed, 197 insertions(+) create mode 100644 example/test.ipynb create mode 100644 tests/controllers/test_g16fragcontroller.py diff --git a/example/test.ipynb b/example/test.ipynb new file mode 100644 index 0000000..03f6747 --- /dev/null +++ b/example/test.ipynb @@ -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": [ + "" + ] + }, + "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 +} diff --git a/tests/controllers/test_g16fragcontroller.py b/tests/controllers/test_g16fragcontroller.py new file mode 100644 index 0000000..a56da9f --- /dev/null +++ b/tests/controllers/test_g16fragcontroller.py @@ -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)