Exemplo n.º 1
0
def test_wrap_class_constructor():
    class A(object):
        def __init__(self, a, b=None):
            self.a = a
            self.b = b

    cons = kwargify(A)
    a = cons(a=1)
    assert a.a == 1
    assert a.b is None
Exemplo n.º 2
0
def test_wrap_class_constructor():
    class A(object):
        def __init__(self, a, b=None):
            self.a = a
            self.b = b

    cons = kwargify(A)
    a = cons(a=1)
    assert a.a == 1
    assert a.b is None
Exemplo n.º 3
0
def skip_plugin(item, skip, reason="Skipped"):
    if isinstance(skip, bool):
        if skip:
            pytest.skip(reason)
    elif callable(skip):
        skip_kwargified = kwargify(skip)
        if skip_kwargified(**extract_fixtures_values(item)):
            pytest.skip(reason)
    else:
        if bool(skip):
            pytest.skip(reason)
Exemplo n.º 4
0
def skip_plugin(item, skip, reason="Skipped"):
    if isinstance(skip, bool):
        if skip:
            pytest.skip(reason)
    elif callable(skip):
        skip_kwargified = kwargify(skip)
        if skip_kwargified(**extract_fixtures_values(item)):
            pytest.skip(reason)
    else:
        if bool(skip):
            pytest.skip(reason)
Exemplo n.º 5
0
def test_wrapped():
    # double check that the function wrapper does its job
    def f():
        """doctring!"""
        pass
    f.custom_attr = True

    wrapped_f = kwargify(f)
    # __wrapped__ should be set
    assert wrapped_f.__wrapped__ is f
    # dunder attrs should be copied over
    assert wrapped_f.__doc__ == f.__doc__
    # any public attrs on the wrapped func should be available
    assert wrapped_f.custom_attr
Exemplo n.º 6
0
def test_wrap_method():
    """Tst whether wrapping already existing method works."""
    class A(object):
        def a(self):
            return True

        def b(self, a, b):
            return locals()

        def c(self, a, b=None):
            return locals()

    a = A()
    k_a = kwargify(a.a)
    k_b = kwargify(a.b)
    k_c = kwargify(a.c)

    # Plain function
    assert k_a()

    # Without nonrequired parameters
    with pytest.raises(TypeError):
        k_b()

    result = k_b(1, 2)
    assert result["a"] == 1
    assert result["b"] == 2

    # With nonrequired params
    with pytest.raises(TypeError):
        k_c()

    result_1 = k_c(1, 2)
    result_2 = k_c(1)
    assert result_1["a"] == result_2["a"] == 1
    assert result_1["b"] == 2
    assert result_2["b"] is None
Exemplo n.º 7
0
def test_wrap_method():
    """Tst whether wrapping already existing method works."""
    class A(object):
        def a(self):
            return True

        def b(self, a, b):
            return locals()

        def c(self, a, b=None):
            return locals()

    a = A()
    k_a = kwargify(a.a)
    k_b = kwargify(a.b)
    k_c = kwargify(a.c)

    # Plain function
    assert k_a()

    # Without nonrequired parameters
    with pytest.raises(TypeError):
        k_b()

    result = k_b(1, 2)
    assert result["a"] == 1
    assert result["b"] == 2

    # With nonrequired params
    with pytest.raises(TypeError):
        k_c()

    result_1 = k_c(1, 2)
    result_2 = k_c(1)
    assert result_1["a"] == result_2["a"] == 1
    assert result_1["b"] == 2
    assert result_2["b"] is None
Exemplo n.º 8
0
def test_wrapped():
    # double check that the function wrapper does its job
    def f():
        """doctring!"""
        pass

    f.custom_attr = True

    wrapped_f = kwargify(f)
    # __wrapped__ should be set
    assert wrapped_f.__wrapped__ is f
    # dunder attrs should be copied over
    assert wrapped_f.__doc__ == f.__doc__
    # any public attrs on the wrapped func should be available
    assert wrapped_f.custom_attr
Exemplo n.º 9
0
 def test_only_kwargs_passed_not_enough(self, o):
     kwargify(o.onlyargs)(a="bar")
Exemplo n.º 10
0
 def test_only_kwargs_passed_wrong(self, o):
     kwargify(o.onlyargs)(foo="bar")
Exemplo n.º 11
0
 def test_args_given_enough(self, o):
     kwargify(o.onlyargs)(1, 2)
Exemplo n.º 12
0
 def test_no_args_given_fails(self, o):
     kwargify(o.onlyargs)()
Exemplo n.º 13
0
 def test_both_passed(self, o):
     kwargify(o.onlyargs)(1, b=2)
Exemplo n.º 14
0
 def test_pass_only_required(self, o):
     assert kwargify(o.withdefault)(1)["b"] is None
Exemplo n.º 15
0
 def test_args_given_enough(self, o):
     kwargify(o.onlyargs)(1, 2)
Exemplo n.º 16
0
 def test_no_args_given(self, o):
     kwargify(o.noargs)()
Exemplo n.º 17
0
 def test_only_kwargs_passed_wrong(self, o):
     kwargify(o.onlyargs)(foo="bar")
Exemplo n.º 18
0
 def test_only_kwargs_passed_not_enough(self, o):
     kwargify(o.onlyargs)(a="bar")
Exemplo n.º 19
0
 def test_override_default_with_kwarg(self, o):
     assert kwargify(o.withdefault)(1, b=2)["b"] == 2
Exemplo n.º 20
0
 def test_pass_only_required(self, o):
     assert kwargify(o.withdefault)(1)["b"] is None
Exemplo n.º 21
0
 def test_only_kwargs_passed(self, o):
     kwargify(o.onlyargs)(a=1, b=2)
Exemplo n.º 22
0
 def test_no_args_given_fails(self, o):
     kwargify(o.onlyargs)()
Exemplo n.º 23
0
 def test_both_passed(self, o):
     kwargify(o.onlyargs)(1, b=2)
Exemplo n.º 24
0
 def test_kwargs_passed(self, o):
     kwargify(o.noargs)(foo="bar")
Exemplo n.º 25
0
 def test_override_default_with_kwarg(self, o):
     assert kwargify(o.withdefault)(1, b=2)["b"] == 2
Exemplo n.º 26
0
 def test_kwargs_passed(self, o):
     kwargify(o.noargs)(foo="bar")
Exemplo n.º 27
0
 def test_args_given(self, o, n):
     kwargify(o.noargs)(*range(n + 1))
Exemplo n.º 28
0
 def test_only_kwargs_passed(self, o):
     kwargify(o.onlyargs)(a=1, b=2)
Exemplo n.º 29
0
 def test_no_args_given(self, o):
     kwargify(o.noargs)()
Exemplo n.º 30
0
 def f(g):
     self._plugins.append(Plugin(name, keys, kwargify(g), kwargs))
     return g  # So the markers can be chained
Exemplo n.º 31
0
 def f(g):
     self._plugins.append(Plugin(name, keys, kwargify(g), kwargs))
     return g  # So the markers can be chained
Exemplo n.º 32
0
 def test_args_given(self, o, n):
     kwargify(o.noargs)(*range(n + 1))