diff --git a/src/pytest_ansible/host_manager/__init__.py b/src/pytest_ansible/host_manager/__init__.py index 8cbee626..5f352455 100644 --- a/src/pytest_ansible/host_manager/__init__.py +++ b/src/pytest_ansible/host_manager/__init__.py @@ -3,7 +3,6 @@ import ansible from pytest_ansible.has_version import ( - has_ansible_v2, has_ansible_v212, has_ansible_v213, ) @@ -144,8 +143,6 @@ def get_host_manager(*args, **kwargs): from pytest_ansible.host_manager.v213 import HostManagerV213 as HostManager elif has_ansible_v212: from pytest_ansible.host_manager.v212 import HostManagerV212 as HostManager - elif has_ansible_v2: - from pytest_ansible.host_manager.v2 import HostManagerV2 as HostManager else: raise RuntimeError("Unable to find any supported HostManager") diff --git a/src/pytest_ansible/module_dispatcher/v212.py b/src/pytest_ansible/module_dispatcher/v212.py index b290e610..454c471a 100644 --- a/src/pytest_ansible/module_dispatcher/v212.py +++ b/src/pytest_ansible/module_dispatcher/v212.py @@ -18,17 +18,9 @@ from pytest_ansible.errors import AnsibleConnectionFailure from pytest_ansible.has_version import has_ansible_v212 -from pytest_ansible.module_dispatcher.v2 import ModuleDispatcherV2 from pytest_ansible.results import AdHocResult - -# pylint: disable=ungrouped-imports, wrong-import-position -if not has_ansible_v212: - msg = "Only supported with ansible-2.12 and newer" - raise ImportError(msg) - - -# pylint: enable=ungrouped-imports +from pytest_ansible.module_dispatcher import BaseModuleDispatcher class ResultAccumulator(CallbackBase): @@ -60,7 +52,7 @@ def results(self): return {"contacted": self.contacted, "unreachable": self.unreachable} -class ModuleDispatcherV212(ModuleDispatcherV2): +class ModuleDispatcherV212(BaseModuleDispatcher): """Pass.""" if TYPE_CHECKING: @@ -74,6 +66,13 @@ class ModuleDispatcherV212(ModuleDispatcherV2): "loader", ) + def __init__(self, **kwargs) -> None: + """Fixme.""" + super().__init__(**kwargs) + if not has_ansible_v212: + msg = "Only supported with ansible-2.12 and newer" + raise ImportError(msg) + def has_module(self, name): """Fixme.""" # Make sure we parse module_path and pass it to the loader, diff --git a/src/pytest_ansible/module_dispatcher/v213.py b/src/pytest_ansible/module_dispatcher/v213.py index 510017e4..8a968fbc 100644 --- a/src/pytest_ansible/module_dispatcher/v213.py +++ b/src/pytest_ansible/module_dispatcher/v213.py @@ -15,14 +15,9 @@ from pytest_ansible.errors import AnsibleConnectionFailure from pytest_ansible.has_version import has_ansible_v213 -from pytest_ansible.module_dispatcher.v2 import ModuleDispatcherV2 from pytest_ansible.results import AdHocResult - -# pylint: disable=ungrouped-imports, wrong-import-position -if not has_ansible_v213: - msg = "Only supported with ansible-2.13 and newer" - raise ImportError(msg) +from pytest_ansible.module_dispatcher import BaseModuleDispatcher HAS_CUSTOM_LOADER_SUPPORT = True @@ -65,7 +60,7 @@ def results(self): return {"contacted": self.contacted, "unreachable": self.unreachable} -class ModuleDispatcherV213(ModuleDispatcherV2): +class ModuleDispatcherV213(BaseModuleDispatcher): """Pass.""" required_kwargs = ( @@ -76,6 +71,13 @@ class ModuleDispatcherV213(ModuleDispatcherV2): "loader", ) + def __init__(self, **kwargs) -> None: + """Fixme.""" + super().__init__(**kwargs) + if not has_ansible_v213: + msg = "Only supported with ansible-2.13 and newer" + raise ImportError(msg) + def has_module(self, name): """Fixme.""" # Make sure we parse module_path and pass it to the loader, diff --git a/tests/test_host_manager.py b/tests/test_host_manager.py index 51d34d1a..5e21e625 100644 --- a/tests/test_host_manager.py +++ b/tests/test_host_manager.py @@ -16,7 +16,10 @@ ] -@pytest.mark.parametrize("include_extra_inventory", (True, False)) +@pytest.mark.parametrize( + "include_extra_inventory", + (True, False), +) def test_host_manager_len(hosts, include_extra_inventory): _hosts = hosts(include_extra_inventory=include_extra_inventory) assert len(_hosts) == len(ALL_HOSTS) + len( @@ -24,7 +27,10 @@ def test_host_manager_len(hosts, include_extra_inventory): ) -@pytest.mark.parametrize("include_extra_inventory", (True, False)) +@pytest.mark.parametrize( + "include_extra_inventory", + (True, False), +) def test_host_manager_keys(hosts, include_extra_inventory): _hosts = hosts(include_extra_inventory=include_extra_inventory) sorted_keys = _hosts.keys() @@ -37,7 +43,10 @@ def test_host_manager_keys(hosts, include_extra_inventory): ("host_pattern", "num_hosts"), POSITIVE_HOST_PATTERNS + EXTRA_HOST_POSITIVE_PATTERNS, ) -@pytest.mark.parametrize("include_extra_inventory", (True, False)) +@pytest.mark.parametrize( + "include_extra_inventory", + (True, False), +) def test_host_manager_contains(host_pattern, num_hosts, hosts, include_extra_inventory): _hosts = hosts(include_extra_inventory=include_extra_inventory) if not include_extra_inventory and host_pattern.startswith("extra"): @@ -46,7 +55,10 @@ def test_host_manager_contains(host_pattern, num_hosts, hosts, include_extra_inv assert host_pattern in _hosts, f"{host_pattern} not in hosts" -@pytest.mark.parametrize(("host_pattern", "num_hosts"), NEGATIVE_HOST_PATTERNS) +@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, @@ -62,7 +74,10 @@ def test_host_manager_not_contains( ("host_pattern", "num_hosts"), POSITIVE_HOST_PATTERNS + EXTRA_HOST_POSITIVE_PATTERNS, ) -@pytest.mark.parametrize("include_extra_inventory", (True, False)) +@pytest.mark.parametrize( + "include_extra_inventory", + (True, False), +) def test_host_manager_getitem(host_pattern, num_hosts, hosts, include_extra_inventory): _hosts = hosts(include_extra_inventory=include_extra_inventory) if not include_extra_inventory and host_pattern.startswith("extra"): @@ -71,14 +86,15 @@ def test_host_manager_getitem(host_pattern, num_hosts, hosts, include_extra_inve assert _hosts[host_pattern] -@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, -): +@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): _hosts = hosts(include_extra_inventory=include_extra_inventory) with pytest.raises(KeyError): assert _hosts[host_pattern] @@ -88,7 +104,10 @@ def test_host_manager_not_getitem( ("host_pattern", "num_hosts"), POSITIVE_HOST_PATTERNS + EXTRA_HOST_POSITIVE_PATTERNS, ) -@pytest.mark.parametrize("include_extra_inventory", (True, False)) +@pytest.mark.parametrize( + "include_extra_inventory", + (True, False), +) def test_host_manager_getattr(host_pattern, num_hosts, hosts, include_extra_inventory): _hosts = hosts(include_extra_inventory=include_extra_inventory) if not include_extra_inventory and host_pattern.startswith("extra"): @@ -97,8 +116,14 @@ def test_host_manager_getattr(host_pattern, num_hosts, hosts, include_extra_inve assert hasattr(_hosts, host_pattern) -@pytest.mark.parametrize(("host_slice", "num_hosts"), POSITIVE_HOST_SLICES) -@pytest.mark.parametrize("include_extra_inventory", (True, False)) +@pytest.mark.parametrize( + ("host_slice", "num_hosts"), + POSITIVE_HOST_SLICES, +) +@pytest.mark.parametrize( + "include_extra_inventory", + (True, False), +) def test_host_manager_slice(host_slice, num_hosts, hosts, include_extra_inventory): _hosts = hosts(include_extra_inventory=include_extra_inventory) assert ( @@ -107,22 +132,29 @@ def test_host_manager_slice(host_slice, num_hosts, hosts, include_extra_inventor # pylint: disable=pointless-statement -@pytest.mark.parametrize("host_slice", NEGATIVE_HOST_SLICES) -@pytest.mark.parametrize("include_extra_inventory", (True, False)) +@pytest.mark.parametrize( + "host_slice", + NEGATIVE_HOST_SLICES, +) +@pytest.mark.parametrize( + "include_extra_inventory", + (True, False), +) def test_host_manager_not_slice(host_slice, hosts, include_extra_inventory): _hosts = hosts(include_extra_inventory=include_extra_inventory) with pytest.raises(KeyError): _hosts[host_slice] -@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, -): +@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): _hosts = hosts(include_extra_inventory=include_extra_inventory) assert not hasattr(_hosts, host_pattern) with pytest.raises(AttributeError): diff --git a/tests/test_module_dispatcher.py b/tests/test_module_dispatcher.py index f67d0e1a..ef8620c6 100644 --- a/tests/test_module_dispatcher.py +++ b/tests/test_module_dispatcher.py @@ -21,25 +21,40 @@ def test_importerror_requires_v1(): import pytest_ansible.module_dispatcher.v1 # NOQA -@pytest.mark.parametrize(("host_pattern", "num_hosts"), POSITIVE_HOST_PATTERNS) -@pytest.mark.parametrize("include_extra_inventory", (True, False)) +@pytest.mark.parametrize( + ("host_pattern", "num_hosts"), + POSITIVE_HOST_PATTERNS, +) +@pytest.mark.parametrize( + "include_extra_inventory", + (True, False), +) def test_dispatcher_len(host_pattern, num_hosts, hosts, include_extra_inventory): hosts = hosts(include_extra_inventory=include_extra_inventory) assert len(getattr(hosts, host_pattern)) == num_hosts[include_extra_inventory] -@pytest.mark.parametrize(("host_pattern", "num_hosts"), POSITIVE_HOST_PATTERNS) -@pytest.mark.parametrize("include_extra_inventory", (True, False)) +@pytest.mark.parametrize( + ("host_pattern", "num_hosts"), + POSITIVE_HOST_PATTERNS, +) +@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"] -@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 -): +@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"]