예제 #1
0
파일: test_meta.py 프로젝트: Atch0um/pyrser
 def test_it_attach_method_as_hook_to_class_with_rulename(self):
     hooks = {}
     cls = mock.Mock(__name__='cls', _hooks=hooks)
     del cls.fn
     fn = mock.Mock(__name__='fn')
     meta.hook(cls, 'hookname')(fn)
     self.assertIs(fn, cls.fn)
     cls.set_one.assert_call_once_with(hooks, 'cls.hookname', fn)
예제 #2
0
파일: test_meta.py 프로젝트: vhb/pyrser
 def test_it_attach_method_as_hook_to_class(self):
     hooks = {}
     cls = mock.Mock(__name__='cls', _hooks=hooks)
     del cls.fn
     fn = mock.Mock(__name__='fn')
     meta.hook(cls)(fn)
     self.assertIs(fn, cls.fn)
     cls.set_one.assert_call_once_with(hooks, 'cls.fn', fn)
예제 #3
0
파일: test_meta.py 프로젝트: Atch0um/pyrser
 def test_it_does_not_attach_a_hook_if_method_already_exist(self):
     cls = mock.Mock(__name__='cls')
     method = mock.Mock(__name__='method')
     with self.assertRaises(AttributeError):
         meta.hook(cls, 'rulename')(method)
예제 #4
0
파일: grammar.py 프로젝트: Atch0um/pyrser
    def hook(cls, hook_name=None, erase=False):
        from pyrser.meta import hook

        return hook(cls, hook_name, erase)
예제 #5
0
파일: test_meta.py 프로젝트: vhb/pyrser
 def test_it_does_not_attach_a_hook_if_method_already_exist(self):
     cls = mock.Mock(__name__='cls')
     method = mock.Mock(__name__='method')
     with self.assertRaises(AttributeError):
         meta.hook(cls, 'rulename')(method)