Ejemplo n.º 1
0
def validate_vars(ctx: click.Context, param: click.Option,
                  value: List[str]) -> Dict[str, Any]:
    """
    Process all `--var key=value` and return a dictionnary of them with the
    value converted to the appropriate type.
    """
    try:
        convert_vars(value)
    except ValueError as x:
        raise click.BadParameter(str(x))
def test_convert_invalid_type():
    with pytest.raises(ValueError):
        convert_vars(["todo:object=stuff"])
def test_convert_invalid_format():
    with pytest.raises(ValueError):
        convert_vars(["todo/stuff"])
def test_convert_default_to_str_var():
    assert convert_vars(["todo=stuff"]) == {"todo": "stuff"}
def test_convert_str_var():
    assert convert_vars(["todo:str=stuff"]) == {"todo": "stuff"}
def test_convert_bytes_var():
    assert convert_vars(["todo:bytes=stuff"]) == {"todo": b"stuff"}
def test_convert_float_var():
    assert convert_vars(["age:float=45"]) == {"age": 45.0}
def test_convert_int_var():
    assert convert_vars(["age:int=45"]) == {"age": 45}