Esempio 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
Esempio 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
Esempio 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)
Esempio 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)
Esempio 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
Esempio 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
Esempio 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
Esempio 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
Esempio n. 9
0
 def test_only_kwargs_passed_not_enough(self, o):
     kwargify(o.onlyargs)(a="bar")
Esempio n. 10
0
 def test_only_kwargs_passed_wrong(self, o):
     kwargify(o.onlyargs)(foo="bar")
Esempio n. 11
0
 def test_args_given_enough(self, o):
     kwargify(o.onlyargs)(1, 2)
Esempio n. 12
0
 def test_no_args_given_fails(self, o):
     kwargify(o.onlyargs)()
Esempio n. 13
0
 def test_both_passed(self, o):
     kwargify(o.onlyargs)(1, b=2)
Esempio n. 14
0
 def test_pass_only_required(self, o):
     assert kwargify(o.withdefault)(1)["b"] is None
Esempio n. 15
0
 def test_args_given_enough(self, o):
     kwargify(o.onlyargs)(1, 2)
Esempio n. 16
0
 def test_no_args_given(self, o):
     kwargify(o.noargs)()
Esempio n. 17
0
 def test_only_kwargs_passed_wrong(self, o):
     kwargify(o.onlyargs)(foo="bar")
Esempio n. 18
0
 def test_only_kwargs_passed_not_enough(self, o):
     kwargify(o.onlyargs)(a="bar")
Esempio n. 19
0
 def test_override_default_with_kwarg(self, o):
     assert kwargify(o.withdefault)(1, b=2)["b"] == 2
Esempio n. 20
0
 def test_pass_only_required(self, o):
     assert kwargify(o.withdefault)(1)["b"] is None
Esempio n. 21
0
 def test_only_kwargs_passed(self, o):
     kwargify(o.onlyargs)(a=1, b=2)
Esempio n. 22
0
 def test_no_args_given_fails(self, o):
     kwargify(o.onlyargs)()
Esempio n. 23
0
 def test_both_passed(self, o):
     kwargify(o.onlyargs)(1, b=2)
Esempio n. 24
0
 def test_kwargs_passed(self, o):
     kwargify(o.noargs)(foo="bar")
Esempio n. 25
0
 def test_override_default_with_kwarg(self, o):
     assert kwargify(o.withdefault)(1, b=2)["b"] == 2
Esempio n. 26
0
 def test_kwargs_passed(self, o):
     kwargify(o.noargs)(foo="bar")
Esempio n. 27
0
 def test_args_given(self, o, n):
     kwargify(o.noargs)(*range(n + 1))
Esempio n. 28
0
 def test_only_kwargs_passed(self, o):
     kwargify(o.onlyargs)(a=1, b=2)
Esempio n. 29
0
 def test_no_args_given(self, o):
     kwargify(o.noargs)()
Esempio n. 30
0
 def f(g):
     self._plugins.append(Plugin(name, keys, kwargify(g), kwargs))
     return g  # So the markers can be chained
Esempio n. 31
0
 def f(g):
     self._plugins.append(Plugin(name, keys, kwargify(g), kwargs))
     return g  # So the markers can be chained
Esempio n. 32
0
 def test_args_given(self, o, n):
     kwargify(o.noargs)(*range(n + 1))