Exemplo n.º 1
0
def test_create_if_not_exist(setup_groups):
    """Test the `create_if_not_exist` constructor argument."""
    label = 'non-existing-label-01'
    parameter_type = GroupParamType(create_if_not_exist=True)
    result = parameter_type.convert(label, None, None)
    assert isinstance(result, Group)

    label = 'non-existing-label-02'
    parameter_type = GroupParamType(create_if_not_exist=True, sub_classes=('aiida.groups:core.auto',))
    result = parameter_type.convert(label, None, None)
    assert isinstance(result, AutoGroup)

    # Specifying more than one subclass when `create_if_not_exist=True` is not allowed.
    with pytest.raises(ValueError):
        GroupParamType(create_if_not_exist=True, sub_classes=('aiida.groups:core.auto', 'aiida.groups:core.import'))
Exemplo n.º 2
0
def test_sub_classes(setup_groups, sub_classes, expected):
    """Test the `sub_classes` constructor argument."""
    entity_01, entity_02, entity_03 = setup_groups
    parameter_type = GroupParamType(sub_classes=sub_classes)

    results = []

    for group in [entity_01, entity_02, entity_03]:
        try:
            parameter_type.convert(str(group.pk), None, None)
        except click.BadParameter:
            results.append(False)
        else:
            results.append(True)

    assert tuple(results) == expected