From d0f1e90b27ef03c7569e89bedfdd212c07a51de2 Mon Sep 17 00:00:00 2001 From: Kate Case Date: Fri, 31 Jan 2025 14:40:46 -0500 Subject: [PATCH] Fix tests. --- src/molecule/command/destroy.py | 7 ++++--- src/molecule/scenarios.py | 6 +++++- tests/unit/command/test_base.py | 8 ++++---- tests/unit/test_scenarios.py | 12 ++++++------ 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/molecule/command/destroy.py b/src/molecule/command/destroy.py index da260c248..91c2d928a 100644 --- a/src/molecule/command/destroy.py +++ b/src/molecule/command/destroy.py @@ -94,7 +94,8 @@ def execute(self, action_args: list[str] | None = None) -> None: # noqa: ARG002 ) def destroy( ctx: click.Context, - scenario_name: str | None, + scenario_name: list[str] | None, + exclude: list[str], driver_name: str, __all: bool, # noqa: FBT001 parallel: bool, # noqa: FBT001 @@ -104,6 +105,7 @@ def destroy( Args: ctx: Click context object holding commandline arguments. scenario_name: Name of the scenario to target. + exclude: Name of the scenarios to avoid targeting. driver_name: Molecule driver to use. __all: Whether molecule should target scenario_name or all scenarios. parallel: Whether the scenario(s) should be run in parallel mode. @@ -122,5 +124,4 @@ def destroy( if parallel: util.validate_parallel_cmd_args(command_args) - scenarios = None if scenario_name is None else [scenario_name] - base.execute_cmdline_scenarios(scenarios, args, command_args) + base.execute_cmdline_scenarios(scenario_name, args, command_args, excludes=exclude) diff --git a/src/molecule/scenarios.py b/src/molecule/scenarios.py index b9045ce50..d0f1998e8 100644 --- a/src/molecule/scenarios.py +++ b/src/molecule/scenarios.py @@ -124,7 +124,11 @@ def _verify(self) -> None: """Verify the specified scenario was found.""" scenario_names = [c.scenario.name for c in self._configs] if missing_names := set(self._scenario_names).difference(scenario_names): - msg = f"Scenario(s) '{missing_names}' not found. Exiting." + scenario = "Scenario" + if len(missing_names) > 1: + scenario += "s" + missing = ", ".join(missing_names) + msg = f"{scenario} '{missing}' not found. Exiting." util.sysexit_with_message(msg) def _filter_for_scenario(self) -> list[Scenario]: diff --git a/tests/unit/command/test_base.py b/tests/unit/command/test_base.py index 0955f3dbf..8d2e65117 100644 --- a/tests/unit/command/test_base.py +++ b/tests/unit/command/test_base.py @@ -252,7 +252,7 @@ def test_execute_cmdline_scenarios_prune( patched_execute_subcommand: Mocked execute_subcommand function. patched_prune: Mocked prune function. """ - scenario_name = "default" + scenario_name = ["default"] args: MoleculeArgs = {} command_args: CommandArgs = {"destroy": "always", "subcommand": "test"} @@ -273,7 +273,7 @@ def test_execute_cmdline_scenarios_no_prune( patched_prune: Mocked prune function. patched_execute_subcommand: Mocked execute_subcommand function. """ - scenario_name = "default" + scenario_name = ["default"] args: MoleculeArgs = {} command_args: CommandArgs = {"destroy": "never", "subcommand": "test"} @@ -301,7 +301,7 @@ def test_execute_cmdline_scenarios_exit_destroy( patched_execute_subcommand: Mocked execute_subcommand function. patched_sysexit: Mocked util.sysexit function. """ - scenario_name = "default" + scenario_name = ["default"] args: MoleculeArgs = {} command_args: CommandArgs = {"destroy": "always", "subcommand": "test"} patched_execute_scenario.side_effect = SystemExit() @@ -335,7 +335,7 @@ def test_execute_cmdline_scenarios_exit_nodestroy( patched_prune: Mocked prune function. patched_sysexit: Mocked util.sysexit function. """ - scenario_name = "default" + scenario_name = ["default"] args: MoleculeArgs = {} command_args: CommandArgs = {"destroy": "never", "subcommand": "test"} diff --git a/tests/unit/test_scenarios.py b/tests/unit/test_scenarios.py index 9d135dd6f..bc7629731 100644 --- a/tests/unit/test_scenarios.py +++ b/tests/unit/test_scenarios.py @@ -49,7 +49,7 @@ def test_configs_private_member( # noqa: D103 def test_scenario_name_private_member( # noqa: D103 _instance: scenarios.Scenarios, # noqa: PT019 ) -> None: - assert _instance._scenario_name is None + assert _instance._scenario_names is None def test_scenarios_private_member( # noqa: D103 @@ -80,7 +80,7 @@ def test_all_property(_instance: scenarios.Scenarios) -> None: # noqa: PT019, D def test_all_filters_on_scenario_name_property( # noqa: D103 _instance: scenarios.Scenarios, # noqa: PT019 ) -> None: - _instance._scenario_name = "default" + _instance._scenario_names = ["default"] assert len(_instance.all) == 1 @@ -126,7 +126,7 @@ def test_print_matrix( # noqa: D103 def test_verify_does_not_raise_when_found( # noqa: D103 _instance: scenarios.Scenarios, # noqa: PT019 ) -> None: - _instance._scenario_name = "default" + _instance._scenario_names = ["default"] _instance._verify() @@ -135,7 +135,7 @@ def test_verify_raises_when_scenario_not_found( # noqa: D103 _instance: scenarios.Scenarios, # noqa: PT019 caplog: pytest.LogCaptureFixture, ) -> None: - _instance._scenario_name = "invalid" + _instance._scenario_names = ["invalid"] with pytest.raises(SystemExit) as e: _instance._verify() @@ -148,12 +148,12 @@ def test_verify_raises_when_scenario_not_found( # noqa: D103 def test_filter_for_scenario( # noqa: D103 _instance: scenarios.Scenarios, # noqa: PT019 ) -> None: - _instance._scenario_name = "default" + _instance._scenario_names = ["default"] result = _instance._filter_for_scenario() assert len(result) == 1 assert result[0].name == "default" - _instance._scenario_name = "invalid" + _instance._scenario_names = ["invalid"] result = _instance._filter_for_scenario() assert result == []