Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Qalthos committed Jan 31, 2025
1 parent 1db07cd commit d0f1e90
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
7 changes: 4 additions & 3 deletions src/molecule/command/destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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)
6 changes: 5 additions & 1 deletion src/molecule/scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/command/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand All @@ -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"}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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"}

Expand Down
12 changes: 6 additions & 6 deletions tests/unit/test_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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 == []

Expand Down

0 comments on commit d0f1e90

Please sign in to comment.