Package logilab :: Package common :: Package test :: Module unittest_decorators
[frames] | no frames]

Source Code for Module logilab.common.test.unittest_decorators

 1  """unit tests for the decorators module 
 2  """ 
 3   
 4  from logilab.common.testlib import TestCase, unittest_main 
 5  from logilab.common.decorators import monkeypatch 
6 7 -class DecoratorsTC(TestCase):
8
10 class MyClass: pass 11 @monkeypatch(MyClass) 12 def meth1(self): 13 return 12
14 self.assertEquals([attr for attr in dir(MyClass) if attr[:2] != '__'], 15 ['meth1']) 16 inst = MyClass() 17 self.assertEquals(inst.meth1(), 12)
18
19 - def test_monkeypatch_with_custom_name(self):
20 class MyClass: pass 21 @monkeypatch(MyClass, 'foo') 22 def meth2(self, param): 23 return param + 12
24 self.assertEquals([attr for attr in dir(MyClass) if attr[:2] != '__'], 25 ['foo']) 26 inst = MyClass() 27 self.assertEquals(inst.foo(4), 16) 28 29 30 if __name__ == '__main__': 31 unittest_main() 32