Example #1
0
 def test_local_functions(self):
     @expects(basestring)
     def __str_func(arg):
         return str
     @expects(int)
     def __int_func(arg):
         return int
     @expects(SimpleInterface)
     def __iface_func(arg):
         return SimpleClass
     func = overload(__str_func, __int_func, __iface_func)
     
     assert func("str") == str
     assert func(1) == int
     assert func(SimpleClass()) == SimpleClass
Example #2
0
import unittest


@expects(basestring)
def __str_func(arg):
    return str

@expects(int)
def __int_func(arg):
    return int

@expects(SimpleInterface)
def __iface_func(arg):
    return SimpleClass

func = overload(__str_func, __int_func, __iface_func)


class OverloadTests(unittest.TestCase):
    
    def test_global_functions(self):
        assert func("str") == str
        assert func(1) == int
        assert func(SimpleClass()) == SimpleClass

    def test_local_functions(self):
        @expects(basestring)
        def __str_func(arg):
            return str
        @expects(int)
        def __int_func(arg):