Page MenuHomeSoftware Heritage

Jenkins > .tox.py3.lib.python3.7.site-packages.swh.scheduler.tests.test_cli_add_forge_now::test_schedule_first_visits_cli[extra_cmd_args2]
Failed

TEST RESULT

Run At
Dec 8 2022, 12:47 PM
Details
self = <AliasedGroup scheduler> args = ['add-forge-now', 'schedule-first-visits', '--type-name', 'test-git', '--environment=staging'] prog_name = 'scheduler', complete_var = None, standalone_mode = True windows_expand_args = True extra = {'obj': {'config': {'scheduler': {'args': {}, 'cls': 'foo'}}, 'environment': 'staging', 'log_level': 30, 'scheduler': <swh.scheduler.backend.SchedulerBackend object at 0x7fe19d58d780>}} ctx = <click.core.Context object at 0x7fe19ca8df60> def main( self, args: t.Optional[t.Sequence[str]] = None, prog_name: t.Optional[str] = None, complete_var: t.Optional[str] = None, standalone_mode: bool = True, windows_expand_args: bool = True, **extra: t.Any, ) -> t.Any: """This is the way to invoke a script with all the bells and whistles as a command line application. This will always terminate the application after a call. If this is not wanted, ``SystemExit`` needs to be caught. This method is also available by directly calling the instance of a :class:`Command`. :param args: the arguments that should be used for parsing. If not provided, ``sys.argv[1:]`` is used. :param prog_name: the program name that should be used. By default the program name is constructed by taking the file name from ``sys.argv[0]``. :param complete_var: the environment variable that controls the bash completion support. The default is ``"_<prog_name>_COMPLETE"`` with prog_name in uppercase. :param standalone_mode: the default behavior is to invoke the script in standalone mode. Click will then handle exceptions and convert them into error messages and the function will never return but shut down the interpreter. If this is set to `False` they will be propagated to the caller and the return value of this function is the return value of :meth:`invoke`. :param windows_expand_args: Expand glob patterns, user dir, and env vars in command line args on Windows. :param extra: extra keyword arguments are forwarded to the context constructor. See :class:`Context` for more information. .. versionchanged:: 8.0.1 Added the ``windows_expand_args`` parameter to allow disabling command line arg expansion on Windows. .. versionchanged:: 8.0 When taking arguments from ``sys.argv`` on Windows, glob patterns, user dir, and env vars are expanded. .. versionchanged:: 3.0 Added the ``standalone_mode`` parameter. """ if args is None: args = sys.argv[1:] if os.name == "nt" and windows_expand_args: args = _expand_args(args) else: args = list(args) if prog_name is None: prog_name = _detect_program_name() # Process shell completion requests and exit early. self._main_shell_completion(extra, prog_name, complete_var) try: try: with self.make_context(prog_name, args, **extra) as ctx: > rv = self.invoke(ctx) .tox/py3/lib/python3.7/site-packages/click/core.py:1055: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <AliasedGroup scheduler> ctx = <click.core.Context object at 0x7fe19ca8df60> def invoke(self, ctx: Context) -> t.Any: def _process_result(value: t.Any) -> t.Any: if self._result_callback is not None: value = ctx.invoke(self._result_callback, value, **ctx.params) return value if not ctx.protected_args: if self.invoke_without_command: # No subcommand was invoked, so the result callback is # invoked with the group return value for regular # groups, or an empty list for chained groups. with ctx: rv = super().invoke(ctx) return _process_result([] if self.chain else rv) ctx.fail(_("Missing command.")) # Fetch args back out args = [*ctx.protected_args, *ctx.args] ctx.args = [] ctx.protected_args = [] # If we're not in chain mode, we only allow the invocation of a # single command but we also inform the current context about the # name of the command to invoke. if not self.chain: # Make sure the context is entered so we do not clean up # resources until the result processor has worked. with ctx: cmd_name, cmd, args = self.resolve_command(ctx, args) assert cmd is not None ctx.invoked_subcommand = cmd_name super().invoke(ctx) sub_ctx = cmd.make_context(cmd_name, args, parent=ctx) with sub_ctx: > return _process_result(sub_ctx.command.invoke(sub_ctx)) .tox/py3/lib/python3.7/site-packages/click/core.py:1657: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <Group add-forge-now> ctx = <click.core.Context object at 0x7fe19c9e9630> def invoke(self, ctx: Context) -> t.Any: def _process_result(value: t.Any) -> t.Any: if self._result_callback is not None: value = ctx.invoke(self._result_callback, value, **ctx.params) return value if not ctx.protected_args: if self.invoke_without_command: # No subcommand was invoked, so the result callback is # invoked with the group return value for regular # groups, or an empty list for chained groups. with ctx: rv = super().invoke(ctx) return _process_result([] if self.chain else rv) ctx.fail(_("Missing command.")) # Fetch args back out args = [*ctx.protected_args, *ctx.args] ctx.args = [] ctx.protected_args = [] # If we're not in chain mode, we only allow the invocation of a # single command but we also inform the current context about the # name of the command to invoke. if not self.chain: # Make sure the context is entered so we do not clean up # resources until the result processor has worked. with ctx: cmd_name, cmd, args = self.resolve_command(ctx, args) assert cmd is not None ctx.invoked_subcommand = cmd_name super().invoke(ctx) > sub_ctx = cmd.make_context(cmd_name, args, parent=ctx) .tox/py3/lib/python3.7/site-packages/click/core.py:1655: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <Command schedule-first-visits>, info_name = 'schedule-first-visits' args = [], parent = <click.core.Context object at 0x7fe19c9e9630>, extra = {} ctx = <click.core.Context object at 0x7fe19ca8dbe0> def make_context( self, info_name: t.Optional[str], args: t.List[str], parent: t.Optional[Context] = None, **extra: t.Any, ) -> Context: """This function when given an info name and arguments will kick off the parsing and create a new :class:`Context`. It does not invoke the actual command callback though. To quickly customize the context class used without overriding this method, set the :attr:`context_class` attribute. :param info_name: the info name for this invocation. Generally this is the most descriptive name for the script or command. For the toplevel script it's usually the name of the script, for commands below it it's the name of the command. :param args: the arguments to parse as list of strings. :param parent: the parent context if available. :param extra: extra keyword arguments forwarded to the context constructor. .. versionchanged:: 8.0 Added the :attr:`context_class` attribute. """ for key, value in self.context_settings.items(): if key not in extra: extra[key] = value ctx = self.context_class( self, info_name=info_name, parent=parent, **extra # type: ignore ) with ctx.scope(cleanup=False): > self.parse_args(ctx, args) .tox/py3/lib/python3.7/site-packages/click/core.py:920: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <Command schedule-first-visits> ctx = <click.core.Context object at 0x7fe19ca8dbe0>, args = [] def parse_args(self, ctx: Context, args: t.List[str]) -> t.List[str]: if not args and self.no_args_is_help and not ctx.resilient_parsing: echo(ctx.get_help(), color=ctx.color) ctx.exit() parser = self.make_parser(ctx) > opts, args, param_order = parser.parse_args(args=args) .tox/py3/lib/python3.7/site-packages/click/core.py:1375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <click.parser.OptionParser object at 0x7fe19ca8ddd8>, args = [] def parse_args( self, args: t.List[str] ) -> t.Tuple[t.Dict[str, t.Any], t.List[str], t.List["CoreParameter"]]: """Parses positional arguments and returns ``(values, args, order)`` for the parsed options and arguments as well as the leftover arguments if there are any. The order is a list of objects as they appear on the command line. If arguments appear multiple times they will be memorized multiple times as well. """ state = ParsingState(args) try: > self._process_args_for_options(state) .tox/py3/lib/python3.7/site-packages/click/parser.py:337: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <click.parser.OptionParser object at 0x7fe19ca8ddd8> state = <click.parser.ParsingState object at 0x7fe19ca8d6a0> def _process_args_for_options(self, state: ParsingState) -> None: while state.rargs: arg = state.rargs.pop(0) arglen = len(arg) # Double dashes always handled explicitly regardless of what # prefixes are valid. if arg == "--": return elif arg[:1] in self._opt_prefixes and arglen > 1: > self._process_opts(arg, state) .tox/py3/lib/python3.7/site-packages/click/parser.py:364: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <click.parser.OptionParser object at 0x7fe19ca8ddd8> arg = '--environment=staging' state = <click.parser.ParsingState object at 0x7fe19ca8d6a0> def _process_opts(self, arg: str, state: ParsingState) -> None: explicit_value = None # Long option handling happens in two parts. The first part is # supporting explicitly attached values. In any case, we will try # to long match the option first. if "=" in arg: long_opt, explicit_value = arg.split("=", 1) else: long_opt = arg norm_long_opt = normalize_opt(long_opt, self.ctx) # At this point we will match the (assumed) long option through # the long option matching code. Note that this allows options # like "-foo" to be matched as long options. try: > self._match_long_opt(norm_long_opt, explicit_value, state) .tox/py3/lib/python3.7/site-packages/click/parser.py:514: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <click.parser.OptionParser object at 0x7fe19ca8ddd8> opt = '--environment', explicit_value = 'staging' state = <click.parser.ParsingState object at 0x7fe19ca8d6a0> def _match_long_opt( self, opt: str, explicit_value: t.Optional[str], state: ParsingState ) -> None: if opt not in self._long_opt: from difflib import get_close_matches possibilities = get_close_matches(opt, self._long_opt) > raise NoSuchOption(opt, possibilities=possibilities, ctx=self.ctx) E click.exceptions.NoSuchOption: No such option: --environment .tox/py3/lib/python3.7/site-packages/click/parser.py:398: NoSuchOption During handling of the above exception, another exception occurred: mocker = <pytest_mock.plugin.MockerFixture object at 0x7fe19d58d5f8> swh_scheduler = <swh.scheduler.backend.SchedulerBackend object at 0x7fe19d58d780> swh_scheduler_celery_app = <Celery celery.tests at 0x7fe19d894128> listed_origins_by_type = {'test-git': [ListedOrigin(lister_id=UUID('903fd47c-b03e-44ce-81c9-22bddb06ae0e'), url='https://test-git.example.com/0...etime(2020, 6, 15, 16, 0, 0, 1005, tzinfo=datetime.timezone.utc), enabled=True, first_seen=None, last_seen=None), ...]} extra_cmd_args = ['--environment=staging'] @pytest.mark.parametrize( "extra_cmd_args", [ [], ["--lister-name", "github", "--lister-instance-name", "github"], ["--environment=staging"], ], ) def test_schedule_first_visits_cli( mocker, swh_scheduler, swh_scheduler_celery_app, listed_origins_by_type, extra_cmd_args, ): for task_type in TASK_TYPES.values(): swh_scheduler.create_task_type(task_type) visit_type = next(iter(listed_origins_by_type)) # enabled origins by default except when --staging flag is provided enabled = "staging" not in extra_cmd_args # Environment command are for the main command, so massage a bit the flags if "--environment" in extra_cmd_args: prefix_cmd_args = extra_cmd_args extra_cmd_args = [] else: prefix_cmd_args = [] for origins in listed_origins_by_type.values(): swh_scheduler.record_listed_origins( (attr.evolve(o, enabled=enabled) for o in origins) ) get_queue_length = mocker.patch( "swh.scheduler.celery_backend.config.get_queue_length" ) get_queue_length.return_value = None send_task = mocker.patch.object(swh_scheduler_celery_app, "send_task") send_task.return_value = None cmd_args = ( prefix_cmd_args + ["schedule-first-visits", "--type-name", visit_type] + extra_cmd_args ) > result = invoke(swh_scheduler, args=tuple(cmd_args)) .tox/py3/lib/python3.7/site-packages/swh/scheduler/tests/test_cli_add_forge_now.py:88: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .tox/py3/lib/python3.7/site-packages/swh/scheduler/tests/test_cli_add_forge_now.py:18: in invoke scheduler, args=["add-forge-now", *args], catch_exceptions=catch_exceptions .tox/py3/lib/python3.7/site-packages/swh/scheduler/tests/test_cli.py:45: in invoke raise result.exception .tox/py3/lib/python3.7/site-packages/click/testing.py:408: in invoke return_value = cli.main(args=args or (), prog_name=prog_name, **extra) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <AliasedGroup scheduler> args = ['add-forge-now', 'schedule-first-visits', '--type-name', 'test-git', '--environment=staging'] prog_name = 'scheduler', complete_var = None, standalone_mode = True windows_expand_args = True extra = {'obj': {'config': {'scheduler': {'args': {}, 'cls': 'foo'}}, 'environment': 'staging', 'log_level': 30, 'scheduler': <swh.scheduler.backend.SchedulerBackend object at 0x7fe19d58d780>}} ctx = <click.core.Context object at 0x7fe19ca8df60> def main( self, args: t.Optional[t.Sequence[str]] = None, prog_name: t.Optional[str] = None, complete_var: t.Optional[str] = None, standalone_mode: bool = True, windows_expand_args: bool = True, **extra: t.Any, ) -> t.Any: """This is the way to invoke a script with all the bells and whistles as a command line application. This will always terminate the application after a call. If this is not wanted, ``SystemExit`` needs to be caught. This method is also available by directly calling the instance of a :class:`Command`. :param args: the arguments that should be used for parsing. If not provided, ``sys.argv[1:]`` is used. :param prog_name: the program name that should be used. By default the program name is constructed by taking the file name from ``sys.argv[0]``. :param complete_var: the environment variable that controls the bash completion support. The default is ``"_<prog_name>_COMPLETE"`` with prog_name in uppercase. :param standalone_mode: the default behavior is to invoke the script in standalone mode. Click will then handle exceptions and convert them into error messages and the function will never return but shut down the interpreter. If this is set to `False` they will be propagated to the caller and the return value of this function is the return value of :meth:`invoke`. :param windows_expand_args: Expand glob patterns, user dir, and env vars in command line args on Windows. :param extra: extra keyword arguments are forwarded to the context constructor. See :class:`Context` for more information. .. versionchanged:: 8.0.1 Added the ``windows_expand_args`` parameter to allow disabling command line arg expansion on Windows. .. versionchanged:: 8.0 When taking arguments from ``sys.argv`` on Windows, glob patterns, user dir, and env vars are expanded. .. versionchanged:: 3.0 Added the ``standalone_mode`` parameter. """ if args is None: args = sys.argv[1:] if os.name == "nt" and windows_expand_args: args = _expand_args(args) else: args = list(args) if prog_name is None: prog_name = _detect_program_name() # Process shell completion requests and exit early. self._main_shell_completion(extra, prog_name, complete_var) try: try: with self.make_context(prog_name, args, **extra) as ctx: rv = self.invoke(ctx) if not standalone_mode: return rv # it's not safe to `ctx.exit(rv)` here! # note that `rv` may actually contain data like "1" which # has obvious effects # more subtle case: `rv=[None, None]` can come out of # chained commands which all returned `None` -- so it's not # even always obvious that `rv` indicates success/failure # by its truthiness/falsiness ctx.exit() except (EOFError, KeyboardInterrupt): echo(file=sys.stderr) raise Abort() from None except ClickException as e: if not standalone_mode: raise e.show() > sys.exit(e.exit_code) E SystemExit: 2 .tox/py3/lib/python3.7/site-packages/click/core.py:1073: SystemExit