예제 #1
0
def test_unrecognized_param_throws_exception():
    def f(_a, _b):
        pass

    params = Params().add("a", "", int, 0).add("b", "", int, 0)

    with pytest.raises(ValueError):
        params.call_with_params(f, {"c": 3})
예제 #2
0
def test_params_default_substitution_works():
    def f(a, b):
        assert a == 1
        assert b == 2

    params = Params().add("a", "", int, 1).add("b", "", int, 2)

    params.call_with_params(f, {"a": 1})
예제 #3
0
def test_wrong_type_throws_exception():
    def f(_a):
        pass

    params = Params().add("a", "", int, 0)

    with pytest.raises(ValueError):
        params.call_with_params(f, {"a": "hello"})
예제 #4
0
def test_missing_required_throws_exception():
    def f(_a):
        pass

    params = Params().add("a", "", int, 0, True)

    with pytest.raises(ValueError):
        params.call_with_params(f, {})
예제 #5
0
def test_ensure_conditions_checked():
    def f(_a):
        pass

    params = Params().add("a", "", int,
                          0).ensure(lambda params: params["a"] >= 0, "a >= 0")

    with pytest.raises(ValueError):
        params.call_with_params(f, {"a": -1})