henry3260 commented on code in PR #72340:
URL: https://github.com/apache/airflow/pull/72340#discussion_r3897116089
##########
airflow-core/tests/unit/cli/test_cli_parser.py:
##########
@@ -496,6 +496,26 @@ def test_dag_cli_should_display_help(self):
with pytest.raises(SystemExit):
parser.parse_args([*cmd_args, "--help"])
+ @pytest.mark.parametrize(
+ ("selected_names", "source_commands"),
+ [
+ pytest.param(cli_config.DAG_CLI_DAGS_SUBCOMMANDS,
cli_config.DAGS_COMMANDS, id="dags"),
+ pytest.param(cli_config.DAG_CLI_TASKS_SUBCOMMANDS,
cli_config.TASKS_COMMANDS, id="tasks"),
+ ],
+ )
+ def test_dag_cli_subcommands_all_exist(self, selected_names,
source_commands):
+ """A name that no longer exists is silently dropped, so guard against
stale entries."""
+ assert set(selected_names) <= {command.name for command in
source_commands}
+
+ def test_dag_cli_parser_keeps_args_when_rebuilt(self):
+ """``_remove_dag_id_opt`` must not hand argparse a one-shot
generator."""
+ cli_parser.get_parser.cache_clear()
+ first =
vars(cli_parser.get_parser(dag_parser=True).parse_args(["dags", "pause"]))
+ cli_parser.get_parser.cache_clear()
+ second =
vars(cli_parser.get_parser(dag_parser=True).parse_args(["dags", "pause"]))
+
+ assert first.keys() == second.keys()
Review Comment:
`test_dag_cli_parser_keeps_args_when_rebuilt` passes on the unfixed code
when the file runs as a whole, so it doesn't currently guard the tuple() fix.
The generators live on the module-level ActionCommands in `DAG_CLI_DICT`, so
whichever test builds the dag parser first in the process exhausts them not
this one. `test_dag_parser_commands_and_comamnd_group_sections` (L458) and
`test_dag_cli_should_display_help` (L484) both build it beforehand, so at
merge-base first and second are each rebuilt from spent generators, both come
back as {subcommand, func}, and the comparison holds. It only fails when the
test is run in isolation.
Comparing two runs against each other detects divergence but not a shared
absence. Pinning one concrete arg makes it order-independent:
```suggestion
assert "treat_dag_id_as_regex" in first
assert first.keys() == second.keys()
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]