"""Test Raspa input generator"""

import pytest

from aiida_raspa.utils import RaspaInput


def test_render_empty_dict():
    with pytest.raises(KeyError) as excinfo:
        RaspaInput({})
    assert "should contain the System subdictionary" in str(excinfo)


def test_render_wrong_system():
    """Test non-dictionary value for System"""
    inp_dict = {
        "System": 1,
    }
    with pytest.raises(AttributeError) as excinfo:
        RaspaInput(inp_dict)
    assert "of type dict" in str(excinfo)


def test_render_empty_system():
    """Test empy System dictionary"""
    inp_dict = {
        "System": {},
    }
    with pytest.raises(ValueError) as excinfo:
        RaspaInput(inp_dict)
    assert "should not be empty" in str(excinfo)


def test_render_base_input():
    """Test normal input dictionary"""
    inp_dict = {
        "GeneralSettings": {
            "SimulationType": "MonteCarlo",
            "NumberOfCycles": 400,
            "NumberOfInitializationCycles": 200,
            "PrintEvery": 200,
            "Forcefield": "GenericMOFs",
            "EwaldPrecision": 1e-6,
            "CutOff": 12.0,
            "WriteBinaryRestartFileEvery": 200,
        },
        "System": {
            "tcc1rs": {
                "type": "Framework",
                "UnitCells": "1 1 1",
                "HeliumVoidFraction": 0.149,
                "ExternalTemperature": 300.0,
                "ExternalPressure": 5e5,
            },
        },
        "Component": {
            "methane": {
                "MoleculeDefinition": "TraPPE",
                "TranslationProbability": 0.5,
                "ReinsertionProbability": 0.5,
                "SwapProbability": 1.0,
                "CreateNumberOfMolecules": 0,
            }
        },
    }
    inp = RaspaInput(inp_dict)
    assert (
        inp.render()
        == """!!! Generated by AiiDA !!!
CutOff 12.0
EwaldPrecision 1e-06
Forcefield GenericMOFs
NumberOfCycles 400
NumberOfInitializationCycles 200
PrintEvery 200
SimulationType MonteCarlo
WriteBinaryRestartFileEvery 200
Framework 0
   FrameworkName tcc1rs
   ExternalPressure 500000.0
   ExternalTemperature 300.0
   HeliumVoidFraction 0.149
   UnitCells 1 1 1
Component 0 MoleculeName methane
   CreateNumberOfMolecules 0
   MoleculeDefinition TraPPE
   ReinsertionProbability 0.5
   SwapProbability 1.0
   TranslationProbability 0.5
"""
    )
