Skip to content

Commit

Permalink
More types
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Jul 3, 2023
1 parent 9502302 commit f4b77f6
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/molecule/test/a_unit/command/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def test_verify_configs_raises_with_no_configs(caplog):


def test_verify_configs_raises_with_duplicate_configs(
caplog,
caplog: pytest.LogCaptureFixture,
config_instance: config.Config,
):
with pytest.raises(SystemExit) as e:
Expand Down
14 changes: 8 additions & 6 deletions src/molecule/test/a_unit/command/test_idempotence.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from unittest.mock import Mock

import pytest
from pytest_mock import MockerFixture

Expand All @@ -26,7 +28,7 @@


@pytest.fixture()
def _patched_is_idempotent(mocker):
def _patched_is_idempotent(mocker: MockerFixture) -> Mock:
return mocker.patch("molecule.command.idempotence.Idempotence._is_idempotent")


Expand All @@ -42,9 +44,9 @@ def _instance(patched_config_validate, config_instance: config.Config):

def test_execute(
mocker: MockerFixture,
caplog,
caplog: pytest.LogCaptureFixture,
patched_ansible_converge,
_patched_is_idempotent,
_patched_is_idempotent: Mock,
_instance,
):
_instance.execute()
Expand All @@ -61,7 +63,7 @@ def test_execute(


def test_execute_raises_when_not_converged(
caplog,
caplog: pytest.LogCaptureFixture,
patched_ansible_converge,
_instance,
):
Expand All @@ -77,9 +79,9 @@ def test_execute_raises_when_not_converged(

def test_execute_raises_when_fails_idempotence(
mocker: MockerFixture,
caplog,
caplog: pytest.LogCaptureFixture,
patched_ansible_converge,
_patched_is_idempotent,
_patched_is_idempotent: Mock,
_instance,
):
_patched_is_idempotent.return_value = False
Expand Down
4 changes: 2 additions & 2 deletions src/molecule/test/a_unit/dependency/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_env_property(_instance):
assert _instance.env["FOO"] == "bar"


def test_execute(patched_run_command, caplog, _instance):
def test_execute(patched_run_command, caplog: pytest.LogCaptureFixture, _instance):
_instance._sh_command = "patched-command"
_instance.execute()

Expand All @@ -111,7 +111,7 @@ def test_execute(patched_run_command, caplog, _instance):

def test_execute_does_not_execute_when_disabled(
patched_run_command,
caplog,
caplog: pytest.LogCaptureFixture,
_instance,
):
_instance._config.config["dependency"]["enabled"] = False
Expand Down
6 changes: 3 additions & 3 deletions src/molecule/test/a_unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def test_get_driver_name(config_instance: config.Config):


def test_get_driver_name_raises_when_different_driver_used(
caplog,
caplog: pytest.LogCaptureFixture,
config_instance: config.Config,
):
config_instance.state.change_state("driver", "foo")
Expand Down Expand Up @@ -266,7 +266,7 @@ def test_interpolate_curly_default_variable(config_instance: config.Config):


def test_interpolate_raises_on_failed_interpolation(
caplog,
caplog: pytest.LogCaptureFixture,
config_instance: config.Config,
):
string = "$6$8I5Cfmpr$kGZB"
Expand Down Expand Up @@ -311,7 +311,7 @@ def test_validate(

def test_validate_exists_when_validation_fails(
mocker: MockerFixture,
caplog,
caplog: pytest.LogCaptureFixture,
config_instance: config.Config,
):
m = mocker.patch("molecule.model.schema_v3.validate")
Expand Down
8 changes: 4 additions & 4 deletions src/molecule/test/a_unit/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_print_debug():
assert result == expected


def test_print_environment_vars(capsys):
def test_print_environment_vars(capsys: pytest.CaptureFixture[str]) -> None:
env = {
"ANSIBLE_FOO": "foo",
"ANSIBLE_BAR": "bar",
Expand Down Expand Up @@ -86,7 +86,7 @@ def test_sysexit_with_custom_code():
assert e.value.code == 2


def test_sysexit_with_message(caplog):
def test_sysexit_with_message(caplog: pytest.LogCaptureFixture):
with pytest.raises(SystemExit) as e:
util.sysexit_with_message("foo")

Expand All @@ -95,7 +95,7 @@ def test_sysexit_with_message(caplog):
assert "foo" in caplog.text


def test_sysexit_with_warns(caplog):
def test_sysexit_with_warns(caplog: pytest.LogCaptureFixture):
with pytest.raises(SystemExit) as e:
with warnings.catch_warnings(record=True) as warns:
warnings.filterwarnings("default", category=MoleculeRuntimeWarning)
Expand All @@ -109,7 +109,7 @@ def test_sysexit_with_warns(caplog):
assert "xxx" in caplog.text


def test_sysexit_with_message_and_custom_code(caplog):
def test_sysexit_with_message_and_custom_code(caplog: pytest.LogCaptureFixture):
with pytest.raises(SystemExit) as e:
util.sysexit_with_message("foo", 2)

Expand Down
2 changes: 1 addition & 1 deletion src/molecule/test/a_unit/verifier/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_execute(caplog, _patched_ansible_verify, _instance):

def test_execute_does_not_execute(
patched_ansible_converge,
caplog,
caplog: pytest.LogCaptureFixture,
_instance,
):
_instance._config.config["verifier"]["enabled"] = False
Expand Down
2 changes: 1 addition & 1 deletion src/molecule/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def print_debug(title: str, data: str) -> None:
console.print(f"DEBUG: {title}:\n{data}")


def print_environment_vars(env: Optional[dict[str, str]]) -> None:
def print_environment_vars(env: Optional[dict[str, Optional[str]]]) -> None:
"""Print ``Ansible`` and ``Molecule`` environment variables and returns None.
:param env: A dict containing the shell's environment as collected by
Expand Down

0 comments on commit f4b77f6

Please sign in to comment.