示例#1
0
    def test_hint_with_none_default_raises(self):
        def _test_func(a, b, c: str = None, **kwargs):
            pass

        params = {"a": 1, "b": 2, "c": 3}
        with pytest.raises(TypeError):
            validate_signature([_test_func], params)
示例#2
0
    def test_mixed_hints_raises(self):
        def _test_func(a: str, b, c, **kwargs):
            pass

        params = {"a": 1, "b": 2, "c": 3}
        with pytest.raises(TypeError):
            validate_signature([_test_func], params)
示例#3
0
    def test_hint_with_none_default_but_set(self):
        def _test_func(a, b, c: str = None, **kwargs):
            pass

        params = {"a": 1, "b": 2, "c": "foobar"}
        validated_params = validate_signature([_test_func], params)
        assert validated_params == {"a": 1, "b": 2, "c": "foobar"}
示例#4
0
    def test_hints_defaults_override(self):
        def _test_func(a, b, c: str = "asdf", **kwargs):
            pass

        params = {"a": 1, "b": 2, "c": "foobar"}
        validated_params = validate_signature([_test_func], params)
        assert validated_params == {"a": 1, "b": 2, "c": "foobar"}
示例#5
0
    def test_mixed_hints(self):
        def _test_func(a: str, b, c, **kwargs):
            pass

        params = {"a": "foo", "b": 2, "c": 3}
        validated_params = validate_signature([_test_func], params)
        assert validated_params == {"a": "foo", "b": 2, "c": 3}
示例#6
0
    def test_no_hints(self):
        def _test_func(a, b, c, **kwargs):
            pass

        params = {"a": 1, "b": 2, "c": 3}
        validated_params = validate_signature([_test_func], params)
        assert validated_params == {"a": 1, "b": 2, "c": 3}