Exemple #1
0
def test_setup_custodian_handlers_with_params(handler_name, handler_params):
    from aiida_cusp.utils.custodian import CustodianSettings
    from aiida_cusp.utils.defaults import CustodianDefaults
    val = 'updated_val'
    custodian_settings = CustodianSettings(val, val, val)
    hdlr_param_updated = {p: val for p in dict(handler_params).keys()}
    hdlr_input = {handler_name: hdlr_param_updated}
    hdlr_output = custodian_settings.setup_custodian_handlers(hdlr_input)
    path = CustodianDefaults.HANDLER_IMPORT_PATH
    expected_output = {".".join([path, handler_name]): hdlr_param_updated}
    assert hdlr_output == expected_output
Exemple #2
0
def test_setup_custodian_handlers_raises_for_invalid_param(handler_name):
    from aiida_cusp.utils.custodian import CustodianSettings
    from aiida_cusp.utils.defaults import CustodianDefaults, PluginDefaults
    from aiida_cusp.utils.exceptions import CustodianSettingsError
    vasp_cmd = None
    stdout = PluginDefaults.STDOUT_FNAME
    stderr = PluginDefaults.STDERR_FNAME
    custodian_settings = CustodianSettings(vasp_cmd, stdout, stderr)
    hdlr_input = {handler_name: {'this_is_an_invalid_handler_parameter': None}}
    with pytest.raises(CustodianSettingsError) as exception:
        hdlr_output = custodian_settings.setup_custodian_handlers(hdlr_input)
    assert "Invalid parameter" in str(exception.value)
Exemple #3
0
def test_setup_custodian_handlers_raises_on_invalid_type(handler):
    from aiida_cusp.utils.custodian import CustodianSettings
    from aiida_cusp.utils.defaults import CustodianDefaults, PluginDefaults
    from aiida_cusp.utils.exceptions import CustodianSettingsError
    # instantiate custodian settings and test setup_vaspjob_settings method
    # with defined settings
    vasp_cmd = None
    stdout = PluginDefaults.STDOUT_FNAME
    stderr = PluginDefaults.STDERR_FNAME
    custodian_settings = CustodianSettings(vasp_cmd, stderr, stdout)
    # test invalid handler type
    with pytest.raises(CustodianSettingsError) as exception:
        _ = custodian_settings.setup_custodian_handlers(handler)
    assert "Invalid input type for 'handler'" in str(exception.value)
Exemple #4
0
def test_setup_custodian_handlers_from_valid_types(handler_type):
    from aiida_cusp.utils.custodian import CustodianSettings
    from aiida_cusp.utils.defaults import CustodianDefaults, PluginDefaults
    handlers_avail = dict(CustodianDefaults.ERROR_HANDLER_SETTINGS)
    if handler_type == 'list':
        handlers = list(handlers_avail.keys())
    elif handler_type == 'tuple':
        handlers = tuple(handlers_avail.keys())
    elif handler_type == 'dict':
        handlers = {h: {} for h in handlers_avail.keys()}
    else:
        raise
    # instantiate custodian settings and test setup_vaspjob_settings method
    # with defined settings
    vasp_cmd = None
    stdout = PluginDefaults.STDOUT_FNAME
    stderr = PluginDefaults.STDERR_FNAME
    custodian_settings = CustodianSettings(stdout, stderr, stdout)
    output_handlers = custodian_settings.setup_custodian_handlers(handlers)
    import_path = CustodianDefaults.HANDLER_IMPORT_PATH
    expected_output = {".".join([import_path, name]): params for name, params
                       in handlers_avail.items()}
    assert output_handlers == expected_output