Пример #1
0
        def prepare_hooks():
            """Set up various hooks to test clearing only some of them."""
            callbacks = CallbackDict()
            sequence = []

            for when in ('before', 'after', 'around'):
                add_callback = CallbackDecorator(callbacks, when).all
                if when == 'around':
                    hook = self.around_hook(sequence)
                else:
                    hook = self.before_after_hook(sequence, when)

                # Default priority class
                add_callback(hook('Default'))

                # Default priority class, specifying a name
                add_callback(hook('Named'), name='named')

                # Different priority classes
                CallbackDecorator(callbacks, when,
                                  priority_class=-1).all(hook('Minus'))
                CallbackDecorator(callbacks, when,
                                  priority_class=1).all(hook('Plus'))

                # Different priority class, specifying a name
                CallbackDecorator(callbacks, when,
                                  priority_class=1).all(hook('PlusNamed'),
                                                        name='named')

            return callbacks, sequence
Пример #2
0
        def prepare_hooks():
            """Set up various hooks to test clearing only some of them."""
            callbacks = CallbackDict()
            sequence = []

            for when in ("before", "after", "around"):
                add_callback = CallbackDecorator(callbacks, when).all
                if when == "around":
                    hook = self.around_hook(sequence)
                else:
                    hook = self.before_after_hook(sequence, when)

                # Default priority class
                add_callback(hook("Default"))

                # Default priority class, specifying a name
                add_callback(hook("Named"), name="named")

                # Different priority classes
                CallbackDecorator(callbacks, when,
                                  priority_class=-1).all(hook("Minus"))
                CallbackDecorator(callbacks, when,
                                  priority_class=1).all(hook("Plus"))

                # Different priority class, specifying a name
                CallbackDecorator(callbacks, when,
                                  priority_class=1).all(hook("PlusNamed"),
                                                        name="named")

            return callbacks, sequence
Пример #3
0
    def setUp(self):
        self.callbacks = CallbackDict()

        self.before = CallbackDecorator(self.callbacks, 'before')
        self.around = CallbackDecorator(self.callbacks, 'around')
        self.after = CallbackDecorator(self.callbacks, 'after')
Пример #4
0
    def setUp(self):
        self.callbacks = CallbackDict()

        self.before = CallbackDecorator(self.callbacks, "before")
        self.around = CallbackDecorator(self.callbacks, "around")
        self.after = CallbackDecorator(self.callbacks, "after")