Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Qalthos committed Oct 29, 2024
1 parent f368042 commit dcb5a3d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
14 changes: 9 additions & 5 deletions tests/unit/command/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@


if TYPE_CHECKING:
from unittest.mock import Mock

import pytest

from pytest_mock import MockerFixture

from molecule import config
Expand All @@ -33,15 +37,15 @@
# NOTE(retr0h): The use of the `patched_config_validate` fixture, disables
# config.Config._validate from executing. Thus preventing odd side-effects
# throughout patched.assert_called unit tests.
def test_dependency_execute( # type: ignore[no-untyped-def] # noqa: ANN201, D103
def test_dependency_execute( # noqa: ANN201, D103
mocker: MockerFixture, # noqa: ARG001
caplog, # noqa: ANN001
patched_ansible_galaxy, # noqa: ANN001
patched_config_validate, # noqa: ANN001, ARG001
caplog: pytest.LogCaptureFixture,
patched_ansible_galaxy: Mock,
patched_config_validate: Mock, # noqa: ARG001
config_instance: config.Config,
):
d = dependency.Dependency(config_instance)
d.execute() # type: ignore[no-untyped-call]
d.execute()

patched_ansible_galaxy.assert_called_once_with()

Expand Down
30 changes: 16 additions & 14 deletions tests/unit/command/test_destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,36 @@


if TYPE_CHECKING:
from unittest.mock import MagicMock, Mock

from pytest_mock import MockerFixture

from molecule import config


@pytest.fixture()
def _patched_ansible_destroy(mocker): # type: ignore[no-untyped-def] # noqa: ANN001, ANN202
def _patched_ansible_destroy(mocker: MockerFixture) -> MagicMock:
return mocker.patch("molecule.provisioner.ansible.Ansible.destroy")


@pytest.fixture()
def _patched_destroy_setup(mocker): # type: ignore[no-untyped-def] # noqa: ANN001, ANN202
def _patched_destroy_setup(mocker: MockerFixture) -> MagicMock:
return mocker.patch("molecule.command.destroy.Destroy._setup")


# NOTE(retr0h): The use of the `patched_config_validate` fixture, disables
# config.Config._validate from executing. Thus preventing odd side-effects
# throughout patched.assert_called unit tests.
@pytest.mark.skip(reason="destroy not running for delegated")
def test_destroy_execute( # type: ignore[no-untyped-def] # noqa: ANN201, D103
def test_destroy_execute( # noqa: D103
mocker: MockerFixture, # noqa: ARG001
caplog, # noqa: ANN001
patched_config_validate, # noqa: ANN001, ARG001
_patched_ansible_destroy, # noqa: ANN001, PT019
caplog: pytest.LogCaptureFixture,
patched_config_validate: Mock, # noqa: ARG001
_patched_ansible_destroy: Mock, # noqa: PT019
config_instance: config.Config,
):
) -> None:
d = destroy.Destroy(config_instance)
d.execute() # type: ignore[no-untyped-call]
d.execute()

assert "destroy" in caplog.text

Expand All @@ -71,16 +73,16 @@ def test_destroy_execute( # type: ignore[no-untyped-def] # noqa: ANN201, D103
["command_driver_delegated_section_data"], # noqa: PT007
indirect=True,
)
def test_execute_skips_when_destroy_strategy_is_never( # type: ignore[no-untyped-def] # noqa: ANN201, D103
_patched_destroy_setup, # noqa: ANN001, PT019
caplog, # noqa: ANN001
_patched_ansible_destroy, # noqa: ANN001, PT019
def test_execute_skips_when_destroy_strategy_is_never( # noqa: D103
_patched_destroy_setup: Mock, # noqa: PT019
caplog: pytest.LogCaptureFixture,
_patched_ansible_destroy: Mock, # noqa: PT019
config_instance: config.Config,
):
) -> None:
config_instance.command_args = {"destroy": "never"}

d = destroy.Destroy(config_instance)
d.execute() # type: ignore[no-untyped-call]
d.execute()

msg = "Skipping, '--destroy=never' requested."
assert msg in caplog.text
Expand Down

0 comments on commit dcb5a3d

Please sign in to comment.