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
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):