コード例 #1
0
ファイル: test_reflection.py プロジェクト: jjpal/hypothesis
def test_arg_string_is_in_order():
    def foo(c, a, b, f, a1):
        pass

    assert repr_call(foo, (1, 2, 3, 4, 5),
                     {}) == "foo(c=1, a=2, b=3, f=4, a1=5)"
    assert (repr_call(foo, (1, 2), {
        "b": 3,
        "f": 4,
        "a1": 5
    }) == "foo(c=1, a=2, b=3, f=4, a1=5)")
コード例 #2
0
ファイル: functions.py プロジェクト: jjpal/hypothesis
 def inner(*args, **kwargs):
     if data.frozen:
         raise InvalidState(
             f"This generated {nicerepr(self.like)} function can only "
             "be called within the scope of the @given that created it."
         )
     if self.pure:
         args, kwargs = convert_positional_arguments(
             self.like, args, kwargs)
         key = (args, frozenset(kwargs.items()))
         cache = self._cache.setdefault(inner, {})
         if key not in cache:
             cache[key] = data.draw(self.returns)
             rep = repr_call(self.like, args, kwargs, reorder=False)
             note(f"Called function: {rep} -> {cache[key]!r}")
         return cache[key]
     else:
         val = data.draw(self.returns)
         rep = repr_call(self.like, args, kwargs, reorder=False)
         note(f"Called function: {rep} -> {val!r}")
         return val
コード例 #3
0
ファイル: test_reflection.py プロジェクト: jjpal/hypothesis
def test_varkwargs_are_sorted_and_after_real_kwargs():
    def foo(d, e, f, **kwargs):
        pass

    assert (repr_call(foo, (), {
        "a": 1,
        "b": 2,
        "c": 3,
        "d": 4,
        "e": 5,
        "f": 6
    }) == "foo(d=4, e=5, f=6, a=1, b=2, c=3)")
コード例 #4
0
ファイル: lazy.py プロジェクト: jjpal/hypothesis
 def __repr__(self):
     if self.__representation is None:
         sig = signature(self.function)
         pos = [p for p in sig.parameters.values() if "POSITIONAL" in p.kind.name]
         if len(pos) > 1 or any(p.default is not sig.empty for p in pos):
             _args, _kwargs = convert_positional_arguments(
                 self.function, self.__args, self.__kwargs
             )
         else:
             _args, _kwargs = convert_keyword_arguments(
                 self.function, self.__args, self.__kwargs
             )
         kwargs_for_repr = {
             k: v
             for k, v in _kwargs.items()
             if k not in sig.parameters or v is not sig.parameters[k].default
         }
         self.__representation = repr_call(
             self.function, _args, kwargs_for_repr, reorder=False
         ) + "".join(map(_repr_filter, self.__filters))
     return self.__representation
コード例 #5
0
ファイル: test_reflection.py プロジェクト: jjpal/hypothesis
def test_kwargs_appear_in_arg_string():
    def varargs(*args, **kwargs):
        pass

    assert "x=1" in repr_call(varargs, (), {"x": 1})
コード例 #6
0
ファイル: test_reflection.py プロジェクト: jjpal/hypothesis
def test_can_handle_repr_of_none():
    def foo(x):
        pass

    assert repr_call(foo, [None], {}) == "foo(x=None)"
    assert repr_call(foo, [], {"x": None}) == "foo(x=None)"
コード例 #7
0
ファイル: test_reflection.py プロジェクト: jjpal/hypothesis
def test_can_handle_repr_on_type():
    def foo(x):
        pass

    assert repr_call(foo, [Snowman], {}) == "foo(x=Snowman)"
    assert repr_call(foo, [NoRepr], {}) == "foo(x=NoRepr)"
コード例 #8
0
ファイル: test_reflection.py プロジェクト: jjpal/hypothesis
def test_can_handle_unicode_repr():
    def foo(x):
        pass

    assert repr_call(foo, [Snowman()], {}) == "foo(x=☃)"
    assert repr_call(foo, [], {"x": Snowman()}) == "foo(x=☃)"
コード例 #9
0
ファイル: test_reflection.py プロジェクト: jjpal/hypothesis
def test_arg_string_does_not_include_unprovided_defaults():
    def foo(a, b, c=9, d=10):
        pass

    assert repr_call(foo, (1, ), {"b": 1, "d": 11}) == "foo(a=1, b=1, d=11)"
コード例 #10
0
ファイル: test_reflection.py プロジェクト: jjpal/hypothesis
def test_can_mix_varargs_and_varkwargs():
    def foo(*args, **kwargs):
        pass

    assert repr_call(foo, (1, 2, 3), {"c": 7}) == "foo(1, 2, 3, c=7)"
コード例 #11
0
ファイル: test_reflection.py プロジェクト: jjpal/hypothesis
def test_varargs_come_without_equals():
    def foo(a, *args):
        pass

    assert repr_call(foo, (1, 2, 3, 4), {}) == "foo(2, 3, 4, a=1)"