예제 #1
0
 def mixed_arbitary_arguments(self):
     func = curried(lambda a, b, c, *args, **kwargs:
                    (a, b, c, args, kwargs))
     Assert(func(1, 2, 3)) == (1, 2, 3, (), {})
     Assert(func(1, 2, 3, 4, 5)) == (1, 2, 3, (4, 5), {})
     Assert(func(1, 2, 3, foo=4)) == (1, 2, 3, (), dict(foo=4))
     Assert(func(1, 2, 3, 4, foo=5)) == (1, 2, 3, (4, ), dict(foo=5))
예제 #2
0
 def arbitary_keyword_arguments(self):
     func = curried(lambda a, b, c, **kwargs: (a, b, c, kwargs))
     Assert(func(1, 2, 3)) == (1, 2, 3, {})
     with Assert.raises(TypeError):
         func(1, 2)(3, c=4)
     Assert(func(1, 2, 3, foo=4)) == (1, 2, 3, dict(foo=4))
     Assert(func(1)(2, 3, foo=4)) == (1, 2, 3, dict(foo=4))
     Assert(func(1, 2)(3, foo=4)) == (1, 2, 3, dict(foo=4))
예제 #3
0
 def arbitary_keyword_arguments(self):
     func = curried(lambda a, b, c, **kwargs: (a, b, c, kwargs))
     Assert(func(1, 2, 3)) == (1, 2, 3, {})
     with Assert.raises(TypeError):
         func(1, 2)(3, c=4)
     Assert(func(1, 2, 3, foo=4)) == (1, 2, 3, dict(foo=4))
     Assert(func(1)(2, 3, foo=4)) == (1, 2, 3, dict(foo=4))
     Assert(func(1, 2)(3, foo=4)) == (1, 2, 3, dict(foo=4))
예제 #4
0
    def keyword_arguments(self):
        func = curried(lambda a=1, b=2, c=3: (a, b, c))
        Assert(func()) == (1, 2, 3)
        Assert(func(c=4)) == (1, 2, 4)
        Assert(func(4)) == (4, 2, 3)

        with Assert.raises(TypeError) as exc:
            func(d=4)
        Assert(exc.args[0]) == 'd is an unexpected keyword argument: 4'
예제 #5
0
    def keyword_arguments(self):
        func = curried(lambda a=1, b=2, c=3: (a, b, c))
        Assert(func()) == (1, 2, 3)
        Assert(func(c=4)) == (1, 2, 4)
        Assert(func(4)) == (4, 2, 3)

        with Assert.raises(TypeError) as exc:
            func(d=4)
        Assert(exc.args[0]) == 'd is an unexpected keyword argument: 4'
예제 #6
0
    def arbitary_positionals(self):
        func = curried(lambda a, b, c, *args: (a, b, c, args))
        Assert(func(1, 2, 3)) == (1, 2, 3, ())
        Assert(func(1, 2, 3, 4, 5)) == (1, 2, 3, (4, 5))
        Assert(func(1)(2, 3, 4, 5)) == (1, 2, 3, (4, 5))
        Assert(func(1, 2)(3, 4, 5)) == (1, 2, 3, (4, 5))
        Assert(func(1)(2, 3, 4, 5)) == (1, 2, 3, (4, 5))

        Assert(func(1)(b=2)(3, 4, 5)) == (1, 2, 3, (4, 5))
        Assert(func(a=1)(b=2)(3, 4, 5)) == (1, 2, 3, (4, 5))
        Assert(func(a=1, b=2)(3, 4, 5)) == (1, 2, 3, (4, 5))
예제 #7
0
    def arbitary_positionals(self):
        func = curried(lambda a, b, c, *args: (a, b, c, args))
        Assert(func(1, 2, 3)) == (1, 2, 3, ())
        Assert(func(1, 2, 3, 4, 5)) == (1, 2, 3, (4, 5))
        Assert(func(1)(2, 3, 4, 5)) == (1, 2, 3, (4, 5))
        Assert(func(1, 2)(3, 4, 5)) == (1, 2, 3, (4, 5))
        Assert(func(1)(2, 3, 4, 5)) == (1, 2, 3, (4, 5))

        Assert(func(1)(b=2)(3, 4, 5)) == (1, 2, 3, (4, 5))
        Assert(func(a=1)(b=2)(3, 4, 5)) == (1, 2, 3, (4, 5))
        Assert(func(a=1, b=2)(3, 4, 5)) == (1, 2, 3, (4, 5))
예제 #8
0
    def positional(self):
        func = curried(lambda a, b, c: (a, b, c))
        Assert(func(1, 2, 3)) == (1, 2, 3)
        Assert(func(1, 2)(3)) == (1, 2, 3)
        Assert(func(1)(2, 3)) == (1, 2, 3)
        Assert(func(1)(2)(3)) == (1, 2, 3)

        Assert(func(c=3, b=2, a=1)) == (1, 2, 3)
        Assert(func(c=3)(a=1)(2)) == (1, 2, 3)

        with Assert.raises(TypeError) as exc:
            func(1, 2, 3, 4)
        Assert(exc.args[0]) == 'unexpected positional argument: 4'
예제 #9
0
    def positional(self):
        func = curried(lambda a, b, c: (a, b, c))
        Assert(func(1, 2, 3)) == (1, 2, 3)
        Assert(func(1, 2)(3)) == (1, 2, 3)
        Assert(func(1)(2, 3)) == (1, 2, 3)
        Assert(func(1)(2)(3)) == (1, 2, 3)

        Assert(func(c=3, b=2, a=1)) == (1, 2, 3)
        Assert(func(c=3)(a=1)(2)) == (1, 2, 3)

        with Assert.raises(TypeError) as exc:
            func(1, 2, 3, 4)
        Assert(exc.args[0]) == 'unexpected positional argument: 4'
예제 #10
0
 def mixed_arbitary_arguments(self):
     func = curried(lambda a, b, c, *args, **kwargs: (a, b, c, args, kwargs))
     Assert(func(1, 2, 3)) == (1, 2, 3, (), {})
     Assert(func(1, 2, 3, 4, 5)) == (1, 2, 3, (4, 5), {})
     Assert(func(1, 2, 3, foo=4)) == (1, 2, 3, (), dict(foo=4))
     Assert(func(1, 2, 3, 4, foo=5)) == (1, 2, 3, (4, ), dict(foo=5))
예제 #11
0
 def mixed_positional_keyword_arguments(self):
     func = curried(lambda a, b, c=3: (a, b, c))
     Assert(func(1, 2)) == (1, 2, 3)
     Assert(func(1, 2, 4)) == (1, 2, 4)
예제 #12
0
 def mixed_positional_keyword_arguments(self):
     func = curried(lambda a, b, c=3: (a, b, c))
     Assert(func(1, 2)) == (1, 2, 3)
     Assert(func(1, 2, 4)) == (1, 2, 4)