def test_wrap(self): """ Test wrapping functions. """ sequence = [] self.before.all(appender(sequence, 'before')) self.around.all(before_after( appender(sequence, 'around_before'), appender(sequence, 'around_after') )) self.after.all(appender(sequence, 'after')) wrapped = appender(sequence, 'wrapped') wrap = self.callbacks.wrap('all', wrapped, 'hook_arg1', 'hook_arg2') wrap('wrap_arg1', 'wrap_arg2') self.assertEqual(sequence, [ ('before', 'hook_arg1', 'hook_arg2'), ('around_before', 'hook_arg1', 'hook_arg2'), ('wrapped', 'wrap_arg1', 'wrap_arg2'), ('around_after', 'hook_arg1', 'hook_arg2'), ('after', 'hook_arg1', 'hook_arg2'), ])
def test_before_after(self): """ Test before_after. """ sequence = [] self.before.all(appender(sequence, 'before')) self.around.all(before_after( appender(sequence, 'around_before'), appender(sequence, 'around_after') )) self.after.all(appender(sequence, 'after')) before, after = self.callbacks.before_after('all') before('before_arg1', 'before_arg2') after('after_arg1', 'after_arg2') self.assertEqual(sequence, [ ('before', 'before_arg1', 'before_arg2'), ('around_before', 'before_arg1', 'before_arg2'), ('around_after', 'before_arg1', 'before_arg2'), ('after', 'after_arg1', 'after_arg2'), ])
def test_before_after(self): """ Test before_after. """ sequence = [] self.before.all(appender(sequence, "before")) self.around.all( before_after(appender(sequence, "around_before"), appender(sequence, "around_after"))) self.after.all(appender(sequence, "after")) before, after = self.callbacks.before_after("all") before("before_arg1", "before_arg2") after("after_arg1", "after_arg2") self.assertEqual( sequence, [ ("before", "before_arg1", "before_arg2"), ("around_before", "before_arg1", "before_arg2"), ("around_after", "before_arg1", "before_arg2"), ("after", "after_arg1", "after_arg2"), ], )
def test_wrap(self): """ Test wrapping functions. """ sequence = [] self.before.all(appender(sequence, "before")) self.around.all( before_after(appender(sequence, "around_before"), appender(sequence, "around_after"))) self.after.all(appender(sequence, "after")) wrapped = appender(sequence, "wrapped") wrap = self.callbacks.wrap("all", wrapped, "hook_arg1", "hook_arg2") wrap("wrap_arg1", "wrap_arg2") self.assertEqual( sequence, [ ("before", "hook_arg1", "hook_arg2"), ("around_before", "hook_arg1", "hook_arg2"), ("wrapped", "wrap_arg1", "wrap_arg2"), ("around_after", "hook_arg1", "hook_arg2"), ("after", "hook_arg1", "hook_arg2"), ], )
def around_hook(cls, sequence): """An around hook appending to a sequence.""" return lambda name: before_after( cls.before_after_hook(sequence, 'around_before')(name), cls.before_after_hook(sequence, 'around_after')(name) )