예제 #1
0
 def test_mismatching_typevariables_raises(self):
     with raises(StrictTypeError, 'Expected argument'):
         asum = arrow(self.add, A, A, A)
         asum(3, 4.0)  # <- both should be of the same type
     with raises(StrictTypeError, 'Expected argument'):
         afloat = arrow(float, A, A)  # <- should return float
         afloat(1)
예제 #2
0
    def test_compose_left(self):
        sum_of_squares = lambda x, y: x**2 + y**2

        f = arrow(sum_of_squares, Int, Int, Int)
        g = arrow(math.sqrt, Int, Real)

        assert (g << f)(3, 4) == 5.0
예제 #3
0
    def test_wrong_arg_types_raises(self, length):
        arglist = [Bool, Int, Real]
        misfits = [4, 0.7, 1 + 1j]

        with raises(StrictTypeError, 'is of wrong type for signature'):
            t = arrow(*[self.argcount] + arglist[:length] + [Int])
            t(*misfits[:length])
예제 #4
0
 def test_wrong_return_type_raises(self):
     with raises(StrictTypeError, 'is of wrong type for signature'):
         t = arrow(self.argcount, A, Bool)  # <- bool should be Int
         t(1)
예제 #5
0
 def test_wrong_arg_count_raises(self):
     with raises(StrictTypeError, 'Wrong number of arguments in'):
         t = arrow(self.no, A, Bool)
         t('one', 'extra')  # <-- Expects only one argument
예제 #6
0
    def test_two_args_fun(self):
        asum = arrow(self.add, A, A, Int)

        args = (1, 2)
        assert asum(*args) == self.add(*args)
        assert type(asum(*args)) is int
예제 #7
0
    def test_one_arg_fun(self):
        ano = arrow(self.no, A, Bool)

        val = True
        assert ano(val) is not(val)
        assert type(ano(val)) is bool
예제 #8
0
 def test_uncallable_fun_raises(self):
     uncallable = 5
     with raises(StrictTypeError, 'is not callable'):
         arrow(uncallable, A, A)
예제 #9
0
 def test_less_than_two_types_raises(self, types):
     with raises(TypeError, 'Needs at least two types:'):
         args = [int] + types
         arrow(*args)
예제 #10
0
 def test_init(self):
     t = arrow(Bool, A, Bool, A=Num)
     assert t._fun is Bool
     assert t.signature == signature(A, Bool, A=Num)