Skip to content

Commit

Permalink
chore: auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] authored and CFSNM committed Nov 30, 2023
1 parent b4d088f commit a5e701a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 281 deletions.
29 changes: 0 additions & 29 deletions src/pytest_ansible/host_manager/v2.py

This file was deleted.

236 changes: 0 additions & 236 deletions src/pytest_ansible/module_dispatcher/v2.py

This file was deleted.

20 changes: 11 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@

from pytest_ansible.host_manager import get_host_manager


try:
from ansible.utils import context_objects as co
except ImportError:
# if it does not exist because of old version of ansible, we don't need it
co = None


pytest_plugins = ["pytester"]


ALL_HOSTS = ["another_host", "localhost", "yet_another_host"]

ALL_EXTRA_HOSTS = ["extra-hosts", "extra-hosts_extra", "yet_another_extra-hosts"]


POSITIVE_HOST_PATTERNS = [
# True means we are including the extra inventory, False not
pytest.param("all", {True: 6, False: 3}, id="0"),
Expand All @@ -28,22 +24,28 @@
pytest.param("!localhost", {True: 5, False: 2}, id="5"),
pytest.param("all[0]", {True: 2, False: 1}, id="6"),
pytest.param("all[-1]", {True: 2, False: 1}, id="7"),
pytest.param("*[0:1]", {True: 4, False: 2}, marks=pytest.mark.requires_ansible_v2(), id="8"),
pytest.param(
"*[0:1]", {True: 4, False: 2}, marks=pytest.mark.requires_ansible_v2(), id="8"
),
# this is confusing, but how host slicing works on v2
pytest.param("*[0:]", {True: 6, False: 3}, marks=pytest.mark.requires_ansible_v2(), id="9")
pytest.param(
"*[0:]", {True: 6, False: 3}, marks=pytest.mark.requires_ansible_v2(), id="9"
),
]

EXTRA_HOST_POSITIVE_PATTERNS = [
# True means we are including the extra inventory, False not
pytest.param(
"extra-hosts",
{True: 1, False: 0},
marks=pytest.mark.requires_ansible_v2(), id="10",
marks=pytest.mark.requires_ansible_v2(),
id="10",
),
pytest.param(
"extra-hosts_extra",
{True: 1, False: 0},
marks=pytest.mark.requires_ansible_v2(), id="11",
marks=pytest.mark.requires_ansible_v2(),
id="11",
),
pytest.param(
"extra-host*",
Expand Down Expand Up @@ -161,4 +163,4 @@ def create_host_manager(include_extra_inventory=False):
kwargs["extra_inventory"] = ",".join(ALL_EXTRA_HOSTS)
return get_host_manager(**kwargs)

return create_host_manager
return create_host_manager
14 changes: 10 additions & 4 deletions tests/test_host_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def test_host_manager_contains(host_pattern, num_hosts, hosts, include_extra_inv

@pytest.mark.parametrize(("host_pattern", "num_hosts"), NEGATIVE_HOST_PATTERNS)
@pytest.mark.parametrize("include_extra_inventory", (True, False))
def test_host_manager_not_contains(host_pattern, num_hosts, hosts, include_extra_inventory):
def test_host_manager_not_contains(
host_pattern, num_hosts, hosts, include_extra_inventory
):
_hosts = hosts(include_extra_inventory=include_extra_inventory)
assert host_pattern not in _hosts

Expand All @@ -68,7 +70,9 @@ def test_host_manager_getitem(host_pattern, num_hosts, hosts, include_extra_inve

@pytest.mark.parametrize(("host_pattern", "num_hosts"), NEGATIVE_HOST_PATTERNS)
@pytest.mark.parametrize("include_extra_inventory", (True, False))
def test_host_manager_not_getitem(host_pattern, num_hosts, hosts, include_extra_inventory):
def test_host_manager_not_getitem(
host_pattern, num_hosts, hosts, include_extra_inventory
):
_hosts = hosts(include_extra_inventory=include_extra_inventory)
with pytest.raises(KeyError):
assert _hosts[host_pattern]
Expand Down Expand Up @@ -107,7 +111,9 @@ def test_host_manager_not_slice(host_slice, hosts, include_extra_inventory):

@pytest.mark.parametrize(("host_pattern", "num_hosts"), NEGATIVE_HOST_PATTERNS)
@pytest.mark.parametrize("include_extra_inventory", (True, False))
def test_host_manager_not_getattr(host_pattern, num_hosts, hosts, include_extra_inventory):
def test_host_manager_not_getattr(
host_pattern, num_hosts, hosts, include_extra_inventory
):
_hosts = hosts(include_extra_inventory=include_extra_inventory)
assert not hasattr(_hosts, host_pattern)
with pytest.raises(AttributeError):
Expand All @@ -121,4 +127,4 @@ def test_defaults(request):
hosts = plugin.initialize(config=request.config, request=request)

assert "connection" in hosts.options
assert hosts.options["connection"] == DEFAULT_TRANSPORT
assert hosts.options["connection"] == DEFAULT_TRANSPORT
4 changes: 1 addition & 3 deletions tests/test_module_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ def test_dispatcher_len(host_pattern, num_hosts, hosts, include_extra_inventory)
@pytest.mark.parametrize("include_extra_inventory", (True, False))
def test_dispatcher_contains(host_pattern, num_hosts, hosts, include_extra_inventory):
hosts = hosts(include_extra_inventory=include_extra_inventory)
assert host_pattern in hosts.all
assert host_pattern in hosts["all"]


@pytest.mark.parametrize(("host_pattern", "num_hosts"), NEGATIVE_HOST_PATTERNS)
@pytest.mark.parametrize("include_extra_inventory", (True, False))
def test_dispatcher_not_contains(host_pattern, num_hosts, hosts, include_extra_inventory):
hosts = hosts(include_extra_inventory=include_extra_inventory)
assert host_pattern not in hosts.all
assert host_pattern not in hosts["all"]


Expand All @@ -53,4 +51,4 @@ def test_ansible_module_error(hosts):
assert (
str(exc_info.value)
== f"The module {'a_module_that_most_certainly_does_not_exist'} was not found in configured module paths."
)
)

0 comments on commit a5e701a

Please sign in to comment.