Ejemplo n.º 1
0
    def test_calls_function_with_extra_context_argument_if_function_accepts_more_arguments_than_given(
            self):
        class NonLocal:
            args = None

        def func(a, b, c):
            NonLocal.args = (a, b, c)
            return 42

        context = object()
        call_with_context(func, context, 1, 'foo')
        assert NonLocal.args == (1, 'foo', context)
Ejemplo n.º 2
0
    def test_calls_function_with_given_arguments(self):
        class NonLocal:
            args = None

        def func(a, b, c):
            NonLocal.args = (a, b, c)
            return 42

        context = object()
        assert call_with_context(func, context, 1, 'foo', True) == 42
        assert NonLocal.args == (1, 'foo', True)
Ejemplo n.º 3
0
 def test_calls_builtin_with_given_arguments(self):
     context = object()
     assert call_with_context(str, context, 123) == '123'
Ejemplo n.º 4
0
 def test_calls_class_with_extra_context_argument_if_function_accepts_more_arguments_than_given(
         self):
     context = object()
     result = call_with_context(ObjClassDummy, context, 1, 'foo')
     assert result.args == (1, 'foo', context)
Ejemplo n.º 5
0
 def test_calls_class_with_given_arguments(self):
     context = object()
     result = call_with_context(ObjClassDummy, context, 1, 'foo', True)
     assert result.args == (1, 'foo', True)
Ejemplo n.º 6
0
 def test_calls_callable_object_with_extra_context_argument_if_function_accepts_more_arguments_than_given(
         self):
     context = object()
     obj = ObjCallableDummy()
     call_with_context(obj, context, 1, 'foo')
     assert obj.args == (1, 'foo', context)
Ejemplo n.º 7
0
 def test_calls_callable_object_with_given_arguments(self):
     context = object()
     obj = ObjCallableDummy()
     assert call_with_context(obj, context, 1, 'foo', True) == 42
     assert obj.args == (1, 'foo', True)
Ejemplo n.º 8
0
 def test_calls_method_with_given_arguments(self):
     context = object()
     obj = ObjMethodDummy()
     assert call_with_context(obj.foo, context, 1, 'foo', True) == 42
     assert obj.args == (1, 'foo', True)