Пример #1
0
        class Offset(object):
            def __init__(self, value):
                self.value = value

            def add(self, a, b):
                return self.value + a + b

            add = inject.bind(add, a=2)
Пример #2
0
    def test_bind_unbound_method(self):
        class Offset(object):
            def __init__(self, value):
                self.value = value

            def add(self, a, b):
                return self.value + a + b

        func = inject.bind(Offset.add, a=2)
        self.assertEquals(10, func(Offset(5), 3))
Пример #3
0
    def test_bind_unbound_method(self):
        class Offset(object):
            def __init__(self, value):
                self.value = value

            def add(self, a, b):
                return self.value + a + b

        func = inject.bind(Offset.add, a=2)
        self.assertEquals(10, func(Offset(5), 3))
Пример #4
0
 def test_bind_first_arg_with_keyword_second_arg(self):
     def func(a, b):
         return a + 2 * b
     func = inject.bind(func, a=1)
     self.assertEqual(7, func(b=3))
Пример #5
0
 def test_bind_first_arg_with_default_second_arg(self):
     def func(a, b=5):
         return a + 2 * b
     func = inject.bind(func, a=1)
     self.assertEqual(11, func())
Пример #6
0
    def test_we_cant_override_a_bound_argument(self):
        def func(a, b):
            return a + 2 * b

        func = inject.bind(func, a=1)
        self.assertRaises(TypeError, func, a=2, b=3)
Пример #7
0
 def test_bind_with_keyword_args(self):
     def func(a, **kwargs):
         return a, kwargs
     func = inject.bind(func, a=1)
     self.assertEquals((1, dict(b=1, c=1)), func(b=1, c=1))
Пример #8
0
 def test_bind_callable(self):
     def func(a, b):
         return a + 2 * b
     func = inject.bind(func, b=lambda: 1)
     self.assertEqual(4, func(2))
Пример #9
0
 def test_bind_middle_arg(self):
     def func(a, b, c):
         return a + 2 * b + 3 * c
     func = inject.bind(func, b=1)
     self.assertEqual(13, func(2, 3))
Пример #10
0
 def test_fail_when_passing_a_normal_argument_twice(self):
     def func(a, b):
         return a + 2 * b
     func = inject.bind(func, a=1)
     self.assertRaises(TypeError,
                       func, 3, b=3)
Пример #11
0
    def test_bind_callable(self):
        def func(a, b):
            return a + 2 * b

        func = inject.bind(func, b=lambda: 1)
        self.assertEqual(4, func(2))
Пример #12
0
    def test_bind_out_of_order_args(self):
        def func(e, d, c, b, a):
            return (e, d, c, b, a)

        func = inject.bind(func, a=5, b=4, c=3, d=2)
        self.assertEqual((1, 2, 3, 4, 5), func(1))
Пример #13
0
    def test_bind_middle_arg(self):
        def func(a, b, c):
            return a + 2 * b + 3 * c

        func = inject.bind(func, b=1)
        self.assertEqual(13, func(2, 3))
Пример #14
0
    def test_bind_last_arg(self):
        def func(a, b):
            return a + 2 * b

        func = inject.bind(func, b=1)
        self.assertEqual(4, func(2))
Пример #15
0
    def test_fail_when_passing_a_normal_argument_twice(self):
        def func(a, b):
            return a + 2 * b

        func = inject.bind(func, a=1)
        self.assertRaises(TypeError, func, 3, b=3)
Пример #16
0
    def test_fail_if_we_miss_an_argument(self):
        def func(a, b):
            return a + 2 * b

        func = inject.bind(func, a=1)
        self.assertRaises(TypeError, func)
Пример #17
0
 def test_we_cant_override_a_bound_argument(self):
     def func(a, b):
         return a + 2 * b
     func = inject.bind(func, a=1)
     self.assertRaises(TypeError,
                       func, a=2, b=3)
Пример #18
0
 def test_fail_if_we_miss_an_argument(self):
     def func(a, b):
         return a + 2 * b
     func = inject.bind(func, a=1)
     self.assertRaises(TypeError,
                       func)
Пример #19
0
    def test_bind_with_varargs(self):
        def func(a, *args):
            return (a, args)

        func = inject.bind(func, a=0)
        self.assertEquals((0, (1, 2)), func(1, 2))
Пример #20
0
 def test_bind_last_arg(self):
     def func(a, b):
         return a + 2 * b
     func = inject.bind(func, b=1)
     self.assertEqual(4, func(2))
Пример #21
0
    def test_bind_with_keyword_args(self):
        def func(a, **kwargs):
            return a, kwargs

        func = inject.bind(func, a=1)
        self.assertEquals((1, dict(b=1, c=1)), func(b=1, c=1))
Пример #22
0
 def test_bind_out_of_order_args(self):
     def func(e, d, c, b, a):
         return (e, d, c, b, a)
     func = inject.bind(func, a=5, b=4, c=3, d=2)
     self.assertEqual((1, 2, 3, 4, 5), func(1))
Пример #23
0
    def test_bind_first_arg_with_default_second_arg(self):
        def func(a, b=5):
            return a + 2 * b

        func = inject.bind(func, a=1)
        self.assertEqual(11, func())
Пример #24
0
    def test_bind_with_varargs(self):
        def func(a, *args):
            return (a, args)

        func = inject.bind(func, a=0)
        self.assertEquals((0, (1, 2)), func(1, 2))
Пример #25
0
 def test_bind_first_arg_with_positional_second_arg(self):
     def func(a, b):
         return a + 2 * b
     func = inject.bind(func, a=1)
     self.assertEqual(5, func(2))
Пример #26
0
    def test_bind_first_arg_with_positional_second_arg(self):
        def func(a, b):
            return a + 2 * b

        func = inject.bind(func, a=1)
        self.assertEqual(5, func(2))
Пример #27
0
    def test_bind_first_arg_with_keyword_second_arg(self):
        def func(a, b):
            return a + 2 * b

        func = inject.bind(func, a=1)
        self.assertEqual(7, func(b=3))