def cmdutils_patch(monkeypatch, stubs): """Patch the cmdutils module to provide fake commands.""" @cmdutils.argument('section_', completion=usertypes.Completion.section) @cmdutils.argument('option', completion=usertypes.Completion.option) @cmdutils.argument('value', completion=usertypes.Completion.value) def set_command(section_=None, option=None, value=None): """docstring.""" pass @cmdutils.argument('topic', completion=usertypes.Completion.helptopic) def show_help(tab=False, bg=False, window=False, topic=None): """docstring.""" pass @cmdutils.argument('url', completion=usertypes.Completion.url) @cmdutils.argument('count', count=True) def openurl(url=None, implicit=False, bg=False, tab=False, window=False, count=None): """docstring.""" pass @cmdutils.argument('win_id', win_id=True) @cmdutils.argument('command', completion=usertypes.Completion.command) def bind(key, win_id, command=None, *, mode='normal', force=False): """docstring.""" # pylint: disable=unused-variable pass def tab_detach(): """docstring.""" pass cmd_utils = stubs.FakeCmdUtils({ 'set': command.Command(name='set', handler=set_command), 'help': command.Command(name='help', handler=show_help), 'open': command.Command(name='open', handler=openurl, maxsplit=0), 'bind': command.Command(name='bind', handler=bind), 'tab-detach': command.Command(name='tab-detach', handler=tab_detach), }) monkeypatch.setattr('qutebrowser.completion.completer.cmdutils', cmd_utils)
def cmdutils_patch(monkeypatch, stubs, miscmodels_patch): """Patch the cmdutils module to provide fake commands.""" @cmdutils.argument('section_', completion=miscmodels_patch.section) @cmdutils.argument('option', completion=miscmodels_patch.option) @cmdutils.argument('value', completion=miscmodels_patch.value) def set_command(section_=None, option=None, value=None): """docstring.""" pass @cmdutils.argument('topic', completion=miscmodels_patch.helptopic) def show_help(tab=False, bg=False, window=False, topic=None): """docstring.""" pass @cmdutils.argument('url', completion=miscmodels_patch.url) @cmdutils.argument('count', count=True) def openurl(url=None, related=False, bg=False, tab=False, window=False, count=None): """docstring.""" pass @cmdutils.argument('win_id', win_id=True) @cmdutils.argument('command', completion=miscmodels_patch.command) def bind(key, win_id, command=None, *, mode='normal'): """docstring.""" pass def tab_detach(): """docstring.""" pass cmd_utils = stubs.FakeCmdUtils({ 'set': command.Command(name='set', handler=set_command), 'help': command.Command(name='help', handler=show_help), 'open': command.Command(name='open', handler=openurl, maxsplit=0), 'bind': command.Command(name='bind', handler=bind), 'tab-detach': command.Command(name='tab-detach', handler=tab_detach), }) monkeypatch.setattr(completer, 'cmdutils', cmd_utils)
def __call__(self, func): """Register the command before running the function. Gets called when a function should be decorated. Doesn't actually decorate anything, but creates a Command object and registers it in the cmd_dict. Args: func: The function to be decorated. Return: The original function (unmodified). """ global aliases names = self._get_names(func) log.commands.vdebug("Registering command {}".format(names[0])) for name in names: if name in cmd_dict: raise ValueError("{} is already registered!".format(name)) cmd = command.Command(name=names[0], instance=self._instance, handler=func, **self._kwargs) for name in names: cmd_dict[name] = cmd aliases += names[1:] return func
def __call__(self, func: typing.Callable) -> typing.Callable: """Register the command before running the function. Gets called when a function should be decorated. Doesn't actually decorate anything, but creates a Command object and registers it in the global commands dict. Args: func: The function to be decorated. Return: The original function (unmodified). """ if self._name is None: name = func.__name__.lower().replace('_', '-') else: assert isinstance(self._name, str), self._name name = self._name cmd = command.Command(name=name, instance=self._instance, handler=func, **self._kwargs) cmd.register() return func
def __call__(self, func): """Register the command before running the function. Gets called when a function should be decorated. Doesn't actually decorate anything, but creates a Command object and registers it in the cmd_dict. Args: func: The function to be decorated. Return: The original function (unmodified). """ if self._name is None: name = func.__name__.lower().replace('_', '-') else: assert isinstance(self._name, str), self._name name = self._name log.commands.vdebug("Registering command {}".format(name)) if name in cmd_dict: raise ValueError("{} is already registered!".format(name)) cmd = command.Command(name=name, instance=self._instance, handler=func, **self._kwargs) cmd_dict[name] = cmd return func
def __call__(self, func: typing.Callable) -> typing.Callable: """Register the command before running the function. Gets called when a function should be decorated. Doesn't actually decorate anything, but creates a Command object and registers it in the global commands dict. Args: func: The function to be decorated. Return: The original function (unmodified). """ if self._name is None: name = func.__name__.lower().replace('_', '-') else: assert isinstance(self._name, str), self._name name = self._name log.commands.vdebug( # type: ignore "Registering command {} (from {}:{})".format( name, func.__module__, func.__qualname__)) if name in objects.commands: raise ValueError("{} is already registered!".format(name)) cmd = command.Command(name=name, instance=self._instance, handler=func, **self._kwargs) objects.commands[name] = cmd return func
def __call__(self, func: Callable) -> Callable: """Register the command before running the function. Gets called when a function should be decorated. Doesn't actually decorate anything, but creates a Command object and registers it in the global commands dict. Args: func: The function to be decorated. Return: The original function (unmodified). """ if self._name is None: name = func.__name__.lower().replace('_', '-') else: assert isinstance(self._name, str), self._name name = self._name cmd = command.Command( name=name, instance=self._instance, handler=func, **self._kwargs, ) cmd.register() if self._deprecated_name is not None: deprecated_cmd = command.Command( name=self._deprecated_name, instance=self._instance, handler=func, deprecated=f"use {name} instead", **self._kwargs, ) deprecated_cmd.register() # This is checked by future @cmdutils.argument calls so they fail # (as they'd be silently ignored otherwise) func.qute_args = None # type: ignore[attr-defined] return func
def cmdutils_patch(monkeypatch, stubs, miscmodels_patch): """Patch the cmdutils module to provide fake commands.""" @cmdutils.argument('section_', completion=miscmodels_patch.section) @cmdutils.argument('option', completion=miscmodels_patch.option) @cmdutils.argument('value', completion=miscmodels_patch.value) def set_command(section_=None, option=None, value=None): """docstring.""" @cmdutils.argument('topic', completion=miscmodels_patch.helptopic) def show_help(tab=False, bg=False, window=False, topic=None): """docstring.""" @cmdutils.argument('url', completion=miscmodels_patch.url) @cmdutils.argument('count', value=cmdutils.Value.count) def openurl(url=None, related=False, bg=False, tab=False, window=False, count=None): """docstring.""" @cmdutils.argument('win_id', value=cmdutils.Value.win_id) @cmdutils.argument('command', completion=miscmodels_patch.command) def bind(key, win_id, command=None, *, mode='normal'): """docstring.""" def tab_give(): """docstring.""" @cmdutils.argument('option', completion=miscmodels_patch.option) @cmdutils.argument('values', completion=miscmodels_patch.value) def config_cycle(option, *values): """For testing varargs.""" commands = { 'set': command.Command(name='set', handler=set_command), 'help': command.Command(name='help', handler=show_help), 'open': command.Command(name='open', handler=openurl, maxsplit=0), 'bind': command.Command(name='bind', handler=bind), 'tab-give': command.Command(name='tab-give', handler=tab_give), 'config-cycle': command.Command(name='config-cycle', handler=config_cycle), } monkeypatch.setattr(completer.objects, 'commands', commands)
def __call__(self, func): """Register the command before running the function. Gets called when a function should be decorated. Doesn't actually decorate anything, but creates a Command object and registers it in the cmd_dict. Args: func: The function to be decorated. Return: The original function (unmodified). """ global aliases names = self._get_names(func) log.commands.vdebug("Registering command {}".format(names[0])) for name in names: if name in cmd_dict: raise ValueError("{} is already registered!".format(name)) cmd = command.Command(name=names[0], maxsplit=self._maxsplit, hide=self._hide, instance=self._instance, scope=self._scope, completion=self._completion, modes=self._modes, not_modes=self._not_modes, needs_js=self._needs_js, is_debug=self._debug, ignore_args=self._ignore_args, deprecated=self._deprecated, handler=func) for name in names: cmd_dict[name] = cmd aliases += names[1:] return func