コード例 #1
0
def test_raise_for_type_mismatch(story, typ, val):
    command_conf = {
        'type': typ
    }

    line = {'ln': '10'}

    valid = False
    if typ == 'string' and isinstance(val, str):
        valid = True
    elif typ == 'int' and isinstance(val, int):
        valid = True
    elif typ == 'float' and isinstance(val, float):
        valid = True
    elif typ == 'list' and isinstance(val, list):
        valid = True
    elif typ == 'map' and isinstance(val, dict):
        valid = True
    elif typ == 'boolean' and isinstance(val, bool):
        valid = True
    elif typ == 'any':
        valid = True

    if valid:
        Services.raise_for_type_mismatch(story, line, 'arg_name',
                                         val, command_conf)
    else:
        with pytest.raises(ArgumentTypeMismatchError):
            Services.raise_for_type_mismatch(story, line, 'arg_name',
                                             val, command_conf)
コード例 #2
0
def test_raise_for_type_mismatch_enum(story, val):
    command_conf = {'type': 'enum', 'enum': ['a', 'b', 'c']}

    if val in command_conf['enum']:
        Services.raise_for_type_mismatch(story, {}, 'arg_name', val,
                                         command_conf)
    else:
        with pytest.raises(ArgumentTypeMismatchError):
            Services.raise_for_type_mismatch(story, {}, 'arg_name', val,
                                             command_conf)