示例#1
0
 def test_function_with_keyword_args(self):
     decorator = expects(Any, Any, foo = SimpleInterface)
     decorated = decorator(keyword_function)
     decorated(0, 1, foo = SimpleClass())
     self.assertRaises(TypeError, decorated, 0, 1, foo = 2)
示例#2
0
 def test_keyword_spec_but_normal_call(self):
     decorator = expects(Any, second = SimpleInterface)
     decorated = decorator(normal_function)
     decorated(1, SimpleClass())
示例#3
0
 def test_function_with_variadic_args(self):
     decorator = expects(Any, SimpleInterface)
     decorated = decorator(variadic_function)
     decorated(1, SimpleClass())
     self.assertRaises(TypeError, decorated, 0, 1)
示例#4
0
 def test_keyword_args(self):
     decorator = expects(first = SimpleInterface, second = SimpleInterface)
     decorated = decorator(normal_function)
     decorated(first = SimpleClass(), second = SimpleClass())
示例#5
0
 def test_normal_spec_but_keyword_call(self):
     decorator = expects(SimpleInterface, Any)
     decorated = decorator(normal_function)
     decorated(first = SimpleClass(), second = "")
示例#6
0
 def test_incorrect_iface_arg(self):
     decorator = expects(SimpleInterface, Any)
     decorated = decorator(normal_function)
     self.assertRaises(TypeError, decorated, (1, 0))
示例#7
0
 def test_correct_iface_arg(self):
     decorator = expects(SimpleInterface, Any)
     decorated = decorator(normal_function)
     decorated(SimpleClass(), 1)
示例#8
0
 def test_too_short_argspec(self):
     decorator = expects(Any)
     self.assertRaises(TypeError, decorator, normal_function)
示例#9
0
 def test_any(self):
     decorator = expects(Any, Any)
     decorated = decorator(normal_function)
     decorated(1, [{'foo':42}])
示例#10
0
 def test_non_function(self):
     decorator = expects(Any)
     self.assertRaises(TypeError, decorator, 1)