Exemplo n.º 1
0
 def test_enforced_returns_on_incorrect_object(self):
     class Class(object):
         def method(self):
             return "foo"
     obj = Class()
     wrapped_obj = enforce(TypedReturnInterface).on(obj)
     self.assertRaises(TypeError, wrapped_obj.method)
Exemplo n.º 2
0
 def test_enforced_returns_on_correct_object(self):
     class Class(object):
         def method(self):
             return 1
     obj = Class()
     wrapped_obj = enforce(TypedReturnInterface).on(obj)
     wrapped_obj.method()
Exemplo n.º 3
0
 def test_enforced_expects(self):
     class Class(object):
         def method(self, n):
             self.n = n
     obj = Class()
     wrapped_obj = enforce(TypedArgsInterface).on(obj)
     wrapped_obj.method(1)
     assert wrapped_obj.n == 1
     self.assertRaises(TypeError, wrapped_obj.method, "foo")
Exemplo n.º 4
0
 def test_enforced_expects_with_2args(self):
     class Class(object):
         def method(self, n, s):
             self.n = n
             self.s = s
     obj = Class()
     wrapped_obj = enforce(TypedTwoArgsInterface).on(obj)
     wrapped_obj.method(1, "bar")
     assert wrapped_obj.n == 1 and wrapped_obj.s == "bar"
     self.assertRaises(TypeError, wrapped_obj.method, "foo", 1)
Exemplo n.º 5
0
 def test_enforce_syntax(self):
     class Class(object):
         def method(self):
             return 1
         
     wrapped_obj = enforce(TypedReturnInterface).on(Class())
     wrapped_obj.method()
     wrapped_obj = enforce(TypedReturnInterface)(Class())
     wrapped_obj.method()
     wrapped_obj = enforce(TypedReturnInterface, Class())
     wrapped_obj.method()
     
     obj = Class() ; enforce(TypedReturnInterface).on(obj)
     obj.method()
     obj = Class() ; enforce(TypedReturnInterface)(obj)
     obj.method()
     obj = Class() ; enforce(TypedReturnInterface, obj)
     obj.method()