예제 #1
0
파일: __init__.py 프로젝트: ArielAzia/slash
 def setUp(self):
     super(TestCase, self).setUp()
     self._handler = LoggingHandler()
     self._handler.push_application()
     self.addCleanup(self._handler.pop_application)
     gossip.get_group('slash').set_exception_policy(gossip.RaiseImmediately())
     self.override_config("log.console_level", 10000) # silence console in tests
예제 #2
0
def test_nested_groups():

    @gossip.register("a.b.c")
    def handler():
        pass

    assert gossip.get_group("a").name == "a"
    assert gossip.get_group("a.b").name == "b"
예제 #3
0
def test_get_or_create_group():
    group_name = "group_name"
    with pytest.raises(GroupNotFound):
        gossip.get_group(group_name)

    group = gossip.get_or_create_group(group_name)
    assert isinstance(group, gossip.groups.Group)
    assert group is gossip.get_group(group_name)
예제 #4
0
파일: __init__.py 프로젝트: wubob/slash
 def setUp(self):
     super(TestCase, self).setUp()
     self._handler = LoggingHandler()
     self._handler.push_application()
     self.addCleanup(self._handler.pop_application)
     gossip.get_group('slash').set_exception_policy(
         gossip.RaiseImmediately())
     self.override_config("log.console_level",
                          10000)  # silence console in tests
예제 #5
0
def mute_other_sub_group():
    hook_1 = gossip.define("a.b.c")
    hook_2 = gossip.define("a.c.d")
    hook_3 = gossip.define("a.c.e")

    gossip.get_group("a.b").forbid_muting()
    hook_3.forbid_muting()

    assert not hook_1.can_be_muted()
    assert not hook_3.can_be_muted()
    assert hook_2.can_be_muted()
예제 #6
0
def test_mute_group(checkpoint):

    @gossip.register('a.b.c')
    def handler():
        checkpoint()

    gossip.get_group("a").forbid_muting()

    with pytest.raises(CannotMuteHooks):
        with gossip.mute_context(['a.b.c']):
            gossip.trigger('a.b.c')
    assert not checkpoint.called
예제 #7
0
def test_builtin_plugins_hooks_start_condition():
    "make sure that all hooks are either empty, or contain callbacks marked with `slash.<identifier>`"
    for hook in gossip.get_group('slash').get_hooks():
        for registration in hook.get_registrations():
            assert registration.token.startswith(
                'slash.'), 'Callback {} is not a builtin!'.format(
                    hook.full_name)
예제 #8
0
def test_inherit_policy_changing_parent():
    gossip.define("group.hook")
    group = gossip.get_group("group")
    for policy in (gossip.RaiseImmediately(), gossip.RaiseDefer(),
                   gossip.IgnoreExceptions()):
        gossip.set_exception_policy(policy)
        assert group.get_exception_policy() is policy
예제 #9
0
def gossip_raise_immediately():
    g = gossip.get_group('slash')
    prev = g.get_exception_policy()
    g.set_exception_policy(gossip.RaiseImmediately())
    try:
        yield
    finally:
        g.set_exception_policy(prev)
예제 #10
0
def gossip_raise_immediately():
    g = gossip.get_group('slash')
    prev = g.get_exception_policy()
    g.set_exception_policy(gossip.RaiseImmediately())
    try:
        yield
    finally:
        g.set_exception_policy(prev)
예제 #11
0
 def run(self):
     returned = []
     all_hooks = []
     for hook in sorted(gossip.get_group("slash").get_hooks(), key=lambda hook:hook.name):
         section = nodes.section(ids=[hook.name])
         returned.append(section)
         title = "slash.hooks.{0}".format(hook.name)
         args = hook.get_argument_names()
         if args:
             title += "({0})".format(", ".join(args))
         section.append(nodes.title(text=title))
         section.append(nodes.paragraph(text=hook.doc))
     return returned
예제 #12
0
 def run(self):
     returned = []
     all_hooks = []
     for hook in sorted(gossip.get_group("slash").get_hooks(),
                        key=lambda hook: hook.name):
         section = nodes.section(ids=[hook.name])
         returned.append(section)
         title = "slash.hooks.{0}".format(hook.name)
         args = hook.get_argument_names()
         if args:
             title += "({0})".format(", ".join(args))
         section.append(nodes.title(text=title))
         section.append(nodes.paragraph(text=hook.doc))
     return returned
예제 #13
0
 def run(self):
     returned = []
     for hook in sorted(gossip.get_group("slash").get_hooks(),
                        key=lambda hook: hook.name):
         section = nodes.section(ids=[hook.name],
                                 names=['hooks.{}'.format(hook.name)])
         self.state.document.note_explicit_target(section)
         returned.append(section)
         title = "slash.hooks.{}".format(hook.name)
         args = hook.get_argument_names()
         if args:
             title += "({})".format(", ".join(args))
         section.append(nodes.title(text=title))
         section.append(nodes.paragraph(text=hook.doc))
     return returned
예제 #14
0
def test_group_only_token_unregistration(registrations):  # pylint: disable=unused-argument

    gossip.get_group("group2").unregister_token("token1")
    assert len(_get_all_registrations()) == 3
예제 #15
0
 def _cleanup():
     for hook in gossip.get_group("slash").get_hooks():
         hook.unregister_all()
     assert not gossip.get_group("slash").get_subgroups()
예제 #16
0
    def _get_plugin_registrations(self, plugin):
        plugin_name = plugin.get_name()
        returned = []
        unknown = []
        global_needs = try_get_mark(plugin, 'plugin_needs', [])
        global_provides = try_get_mark(plugin, 'plugin_provides', [])

        has_session_end = has_session_start = False

        register_no_op_hooks = set()
        if global_provides:
            register_no_op_hooks.update(
                hook.full_name
                for hook in gossip.get_group('slash').get_hooks())

        for method_name in dir(type(plugin)):
            if method_name in _SKIPPED_PLUGIN_METHOD_NAMES:
                continue

            method = getattr(plugin, method_name)

            if not hasattr(method, '__call__'):
                continue

            registration_list = try_get_mark(method, 'register_on', NOTHING)

            if registration_list is not NOTHING:
                registration_list = registration_list[:]
            else:
                if method_name.startswith('_'):
                    continue
                registration_list = [
                    RegistrationInfo("slash.{}".format(method_name),
                                     expect_exists=True)
                ]

            for registration_info in registration_list:
                if registration_info.hook_name is None:
                    # asked not to register for nothing
                    continue

                if not try_get_mark(method, 'register_if', True):
                    continue

                plugin_needs = list(
                    itertools.chain(
                        try_get_mark(method, 'plugin_needs', []), global_needs,
                        registration_info.register_kwargs.get('needs', [])))

                plugin_provides = list(
                    itertools.chain(
                        try_get_mark(method, 'plugin_provides', []),
                        global_provides,
                        registration_info.register_kwargs.get('provides', [])))

                try:
                    if registration_info.expect_exists:
                        hook = gossip.get_hook(registration_info.hook_name)
                    else:
                        hook = gossip.hooks.get_or_create_hook(
                            registration_info.hook_name)
                        if not hook.is_defined() and hook.group.is_strict():
                            raise LookupError()
                except LookupError:
                    unknown.append(registration_info.hook_name)
                    continue

                assert hook is not None
                register_no_op_hooks.discard(registration_info.hook_name)

                kwargs = registration_info.register_kwargs.copy()
                kwargs.update({
                    'needs': plugin_needs,
                    'provides': plugin_provides,
                    'token': self._get_token(plugin_name),
                })
                if registration_info.hook_name == 'slash.session_start':
                    has_session_start = True
                    kwargs['toggles_on'] = plugin.__toggles__['session']
                elif registration_info.hook_name == 'slash.session_end':
                    has_session_end = True
                    kwargs['toggles_off'] = plugin.__toggles__['session']

                returned.append((hook, method, kwargs))

        if has_session_end and not has_session_start:
            hook = gossip.get_hook('slash.session_start')
            returned.append((hook, lambda: None, {
                'toggles_on': plugin.__toggles__['session']
            }))
            register_no_op_hooks.discard(hook.full_name)

        for hook_name in register_no_op_hooks:
            hook = gossip.get_hook(hook_name)
            hook.register_no_op(provides=global_provides,
                                token=self._get_token(plugin_name))

        if unknown:
            raise IncompatiblePlugin("Unknown hooks: {}".format(
                ", ".join(unknown)))
        return returned
예제 #17
0
파일: hooks.py 프로젝트: E8-Storage/slash
_define('test_success', doc="Called on test success")
_define('test_error', doc="Called on test error")
_define('test_failure', doc="Called on test failure")
_define('test_skip', doc="Called on test skip", arg_names=("reason",))

_define('error_added', doc='Called when an error is added to a result (either test result or global)', arg_names=('error', 'result'))

_define('result_summary', doc="Called at the end of the execution, when printing results")

_define('exception_caught_before_debugger',
        doc="Called whenever an exception is caught, but a debugger hasn't been entered yet")

_define('exception_caught_after_debugger',
        doc="Called whenever an exception is caught, and a debugger has already been run")

_slash_group = gossip.get_group('slash')
_slash_group.set_strict()
_slash_group.set_exception_policy(gossip.RaiseDefer())

@gossip.register('gossip.on_handler_exception') # pylint: disable=unused-argument
def debugger(handler, exception, hook): # pylint: disable=unused-argument
    from .exception_handling import handle_exception

    if hook.group is _slash_group and config.root.debug.debug_hook_handlers:
        handle_exception(exception)

@_deprecated_to_gossip
def add_custom_hook(hook_name):
    """
    Adds an additional hook to the set of available hooks
    """
예제 #18
0
파일: conftest.py 프로젝트: youht88/gossip
 def get_group(self):
     return gossip.get_group(self.hook_name.rsplit('.', 1)[0])
예제 #19
0
def test_group_only_token_unregistration(registrations):  # pylint: disable=unused-argument

    gossip.get_group("group2").unregister_token("token1")
    assert len(_get_all_registrations()) == 3
예제 #20
0
파일: hooks.py 프로젝트: yaelmi3/slash
def get_all_hooks():
    return [
        (hook.name, hook)
        for hook in gossip.get_group('slash').get_hooks()]
예제 #21
0
파일: hooks.py 프로젝트: yaelmi3/slash
_define('exception_caught_before_debugger',
        doc="Called whenever an exception is caught, but a debugger hasn't been entered yet")
_define('entering_debugger', doc='Called right before entering debugger', arg_names=('exc_info',))

_define('exception_caught_after_debugger',
        doc="Called whenever an exception is caught, and a debugger has already been run")
_define('before_worker_start', doc="Called in parallel execution mode, before the parent starts the child worker",
        arg_names=("worker_config",))

_define('prepare_notification', doc='Called with a message object prior to it being sent via the notifications plugin (if enabled)',
        arg_names=("message",))

_define('before_interactive_shell', doc='Called before starting interactive shell', arg_names=("namespace",))

_slash_group = gossip.get_group('slash')
_slash_group.set_strict()
_slash_group.set_exception_policy(gossip.RaiseDefer())

@gossip.register('gossip.on_handler_exception') # pylint: disable=unused-argument
def debugger(handler, exception, hook): # pylint: disable=unused-argument
    from .exception_handling import handle_exception

    if hook.group is _slash_group and config.root.debug.debug_hook_handlers:
        handle_exception(exception)

@_deprecated_to_gossip
def add_custom_hook(hook_name):
    """
    Adds an additional hook to the set of available hooks
    """
예제 #22
0
파일: hooks.py 프로젝트: E8-Storage/slash
def get_all_hooks():
    return [
        (hook.name, hook)
        for hook in gossip.get_group('slash').get_hooks()]
예제 #23
0
 def _cleanup():
     for hook in gossip.get_group("slash").get_hooks():
         hook.unregister_all()
     assert not gossip.get_group("slash").get_subgroups()
예제 #24
0
def test_inherit_policy_changing_parent():
    gossip.define("group.hook")
    group = gossip.get_group("group")
    for policy in (gossip.RaiseImmediately(), gossip.RaiseDefer(), gossip.IgnoreExceptions()):
        gossip.set_exception_policy(policy)
        assert group.get_exception_policy() is policy
예제 #25
0
파일: conftest.py 프로젝트: youht88/gossip
 def get_parent_group(self):
     return gossip.get_group(self.hook_name.split('.')[0])