summaryrefslogtreecommitdiffstats
path: root/test/units/utils
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-05 16:16:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-05 16:16:49 +0000
commit48e387c5c12026a567eb7b293a3a590241c0cecb (patch)
tree80f2573be2d7d534b8ac4d2a852fe43f7ac35324 /test/units/utils
parentReleasing progress-linux version 2.16.6-1~progress7.99u1. (diff)
downloadansible-core-48e387c5c12026a567eb7b293a3a590241c0cecb.tar.xz
ansible-core-48e387c5c12026a567eb7b293a3a590241c0cecb.zip
Merging upstream version 2.17.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/units/utils')
-rw-r--r--test/units/utils/collection_loader/fixtures/collections/ansible_collections/ansible/builtin/plugins/modules/shouldnotload.py5
-rw-r--r--test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/action/my_action.py5
-rw-r--r--test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/module_utils/my_other_util.py3
-rw-r--r--test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/module_utils/my_util.py4
-rw-r--r--test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/modules/__init__.py5
-rw-r--r--test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/modules/amodule.py6
-rw-r--r--test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/__init__.py5
-rw-r--r--test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/ansible/__init__.py5
-rw-r--r--test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/testns/__init__.py5
-rw-r--r--test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/testns/testcoll/__init__.py5
-rw-r--r--test/units/utils/collection_loader/test_collection_loader.py59
-rw-r--r--test/units/utils/display/test_broken_cowsay.py4
-rw-r--r--test/units/utils/display/test_curses.py3
-rw-r--r--test/units/utils/display/test_display.py3
-rw-r--r--test/units/utils/display/test_logger.py3
-rw-r--r--test/units/utils/display/test_warning.py3
-rw-r--r--test/units/utils/test_cleanup_tmp_file.py3
-rw-r--r--test/units/utils/test_context_objects.py3
-rw-r--r--test/units/utils/test_display.py3
-rw-r--r--test/units/utils/test_encrypt.py101
-rw-r--r--test/units/utils/test_helpers.py3
-rw-r--r--test/units/utils/test_isidentifier.py4
-rw-r--r--test/units/utils/test_plugin_docs.py5
-rw-r--r--test/units/utils/test_shlex.py3
-rw-r--r--test/units/utils/test_unsafe_proxy.py3
-rw-r--r--test/units/utils/test_vars.py17
-rw-r--r--test/units/utils/test_version.py3
27 files changed, 75 insertions, 196 deletions
diff --git a/test/units/utils/collection_loader/fixtures/collections/ansible_collections/ansible/builtin/plugins/modules/shouldnotload.py b/test/units/utils/collection_loader/fixtures/collections/ansible_collections/ansible/builtin/plugins/modules/shouldnotload.py
index 4041a33..6f98990 100644
--- a/test/units/utils/collection_loader/fixtures/collections/ansible_collections/ansible/builtin/plugins/modules/shouldnotload.py
+++ b/test/units/utils/collection_loader/fixtures/collections/ansible_collections/ansible/builtin/plugins/modules/shouldnotload.py
@@ -1,4 +1,3 @@
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations # pragma: nocover
-raise Exception('this module should never be loaded')
+raise Exception('this module should never be loaded') # pragma: nocover
diff --git a/test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/action/my_action.py b/test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/action/my_action.py
index a85f422..42f089d 100644
--- a/test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/action/my_action.py
+++ b/test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/action/my_action.py
@@ -1,8 +1,7 @@
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
from ..module_utils.my_util import question # pylint: disable=unused-import
def action_code():
- return "hello from my_action.py"
+ raise Exception('hello from my_action.py, this code should never execute') # pragma: nocover
diff --git a/test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/module_utils/my_other_util.py b/test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/module_utils/my_other_util.py
index 463b133..ddb7e47 100644
--- a/test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/module_utils/my_other_util.py
+++ b/test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/module_utils/my_other_util.py
@@ -1,4 +1,3 @@
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
from .my_util import question # pylint: disable=unused-import
diff --git a/test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/module_utils/my_util.py b/test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/module_utils/my_util.py
index c431c34..f551875 100644
--- a/test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/module_utils/my_util.py
+++ b/test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/module_utils/my_util.py
@@ -1,6 +1,6 @@
# WARNING: Changing line numbers of code in this file will break collection tests that use tracing to check paths and line numbers.
-# Also, do not import division from __future__ as this will break detection of __future__ inheritance on Python 2.
+# Also, do not import annotations from __future__ as this will break detection of __future__ inheritance.
-def question():
+def question() -> float:
return 3 / 2
diff --git a/test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/modules/__init__.py b/test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/modules/__init__.py
index 6d69703..9e774e1 100644
--- a/test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/modules/__init__.py
+++ b/test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/modules/__init__.py
@@ -1,5 +1,4 @@
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations # pragma: nocover
-raise Exception('this should never run')
+raise Exception('this should never run') # pragma: nocover
diff --git a/test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/modules/amodule.py b/test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/modules/amodule.py
index 99320a0..bca4751 100644
--- a/test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/modules/amodule.py
+++ b/test/units/utils/collection_loader/fixtures/collections/ansible_collections/testns/testcoll/plugins/modules/amodule.py
@@ -1,6 +1,4 @@
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations # pragma: nocover
-def module_code():
- return "hello from amodule.py"
+raise Exception('hello from amodule.py, this code should never execute') # pragma: nocover
diff --git a/test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/__init__.py b/test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/__init__.py
index 6068ac1..c197d42 100644
--- a/test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/__init__.py
+++ b/test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/__init__.py
@@ -1,5 +1,4 @@
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations # pragma: nocover
-raise Exception('this code should never execute')
+raise Exception('this code should never execute') # pragma: nocover
diff --git a/test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/ansible/__init__.py b/test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/ansible/__init__.py
index 6068ac1..c197d42 100644
--- a/test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/ansible/__init__.py
+++ b/test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/ansible/__init__.py
@@ -1,5 +1,4 @@
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations # pragma: nocover
-raise Exception('this code should never execute')
+raise Exception('this code should never execute') # pragma: nocover
diff --git a/test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/testns/__init__.py b/test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/testns/__init__.py
index 6068ac1..c197d42 100644
--- a/test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/testns/__init__.py
+++ b/test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/testns/__init__.py
@@ -1,5 +1,4 @@
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations # pragma: nocover
-raise Exception('this code should never execute')
+raise Exception('this code should never execute') # pragma: nocover
diff --git a/test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/testns/testcoll/__init__.py b/test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/testns/testcoll/__init__.py
index 6068ac1..c197d42 100644
--- a/test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/testns/testcoll/__init__.py
+++ b/test/units/utils/collection_loader/fixtures/collections_masked/ansible_collections/testns/testcoll/__init__.py
@@ -1,5 +1,4 @@
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations # pragma: nocover
-raise Exception('this code should never execute')
+raise Exception('this code should never execute') # pragma: nocover
diff --git a/test/units/utils/collection_loader/test_collection_loader.py b/test/units/utils/collection_loader/test_collection_loader.py
index feaaf97..51aab2c 100644
--- a/test/units/utils/collection_loader/test_collection_loader.py
+++ b/test/units/utils/collection_loader/test_collection_loader.py
@@ -1,14 +1,13 @@
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
+import inspect
import os
import pkgutil
import pytest
import re
import sys
+from importlib import import_module
-from ansible.module_utils.six import PY3, string_types
-from ansible.module_utils.compat.importlib import import_module
from ansible.modules import ping as ping_module
from ansible.utils.collection_loader import AnsibleCollectionConfig, AnsibleCollectionRef
from ansible.utils.collection_loader._collection_finder import (
@@ -37,7 +36,7 @@ def teardown(*args, **kwargs):
r'FileFinder\.find_loader\(\) is deprecated and slated for removal in Python 3\.12; use find_spec\(\) instead'
':DeprecationWarning',
)
-@pytest.mark.skipif(not PY3 or sys.version_info >= (3, 12), reason='Testing Python 2 codepath (find_module) on Python 3, <= 3.11')
+@pytest.mark.skipif(sys.version_info >= (3, 12), reason='Testing Python 2 codepath (find_module) on Python 3, <= 3.11')
def test_find_module_py3_lt_312():
dir_to_a_file = os.path.dirname(ping_module.__file__)
path_hook_finder = _AnsiblePathHookFinder(_AnsibleCollectionFinder(), dir_to_a_file)
@@ -186,8 +185,7 @@ def test_root_loader():
name = 'ansible_collections'
# ensure this works even when ansible_collections doesn't exist on disk
for paths in [], default_test_collection_paths:
- if name in sys.modules:
- del sys.modules[name]
+ sys.modules.pop(name, None)
loader = _AnsibleCollectionRootPkgLoader(name, paths)
assert repr(loader).startswith('_AnsibleCollectionRootPkgLoader(path=')
module = loader.load_module(name)
@@ -214,8 +212,7 @@ def test_nspkg_loader_load_module():
module_to_load = name.rpartition('.')[2]
paths = extend_paths(default_test_collection_paths, parent_pkg)
existing_child_paths = [p for p in extend_paths(paths, module_to_load) if os.path.exists(p)]
- if name in sys.modules:
- del sys.modules[name]
+ sys.modules.pop(name, None)
loader = _AnsibleCollectionNSPkgLoader(name, path_list=paths)
assert repr(loader).startswith('_AnsibleCollectionNSPkgLoader(path=')
module = loader.load_module(name)
@@ -244,8 +241,7 @@ def test_collpkg_loader_load_module():
paths = extend_paths(default_test_collection_paths, parent_pkg)
existing_child_paths = [p for p in extend_paths(paths, module_to_load) if os.path.exists(p)]
is_builtin = 'ansible.builtin' in name
- if name in sys.modules:
- del sys.modules[name]
+ sys.modules.pop(name, None)
loader = _AnsibleCollectionPkgLoader(name, path_list=paths)
assert repr(loader).startswith('_AnsibleCollectionPkgLoader(path=')
module = loader.load_module(name)
@@ -267,13 +263,16 @@ def test_collpkg_loader_load_module():
# FIXME: validate _collection_meta contents match what's on disk (or not)
- # if the module has metadata, try loading it with busted metadata
- if module._collection_meta:
- _collection_finder = import_module('ansible.utils.collection_loader._collection_finder')
- with patch.object(_collection_finder, '_meta_yml_to_dict', side_effect=Exception('bang')):
- with pytest.raises(Exception) as ex:
- _AnsibleCollectionPkgLoader(name, path_list=paths).load_module(name)
- assert 'error parsing collection metadata' in str(ex.value)
+ # verify the module has metadata, then try loading it with busted metadata
+ assert module._collection_meta
+
+ _collection_finder = import_module('ansible.utils.collection_loader._collection_finder')
+
+ with patch.object(_collection_finder, '_meta_yml_to_dict', side_effect=Exception('bang')):
+ with pytest.raises(Exception) as ex:
+ _AnsibleCollectionPkgLoader(name, path_list=paths).load_module(name)
+
+ assert 'error parsing collection metadata' in str(ex.value)
def test_coll_loader():
@@ -298,10 +297,7 @@ def test_path_hook_setup():
except Exception as phe:
pathhook_exc = phe
- if PY3:
- assert str(pathhook_exc) == 'need exactly one FileFinder import hook (found 0)'
- else:
- assert found_hook is None
+ assert str(pathhook_exc) == 'need exactly one FileFinder import hook (found 0)'
assert repr(_AnsiblePathHookFinder(object(), '/bogus/path')) == "_AnsiblePathHookFinder(path='/bogus/path')"
@@ -410,7 +406,7 @@ def test_import_from_collection(monkeypatch):
original_trace_function = sys.gettrace()
trace_log = []
- if original_trace_function:
+ if original_trace_function: # pragma: nocover
# enable tracing while preserving the existing trace function (coverage)
def my_trace_function(frame, event, arg):
trace_log.append((frame.f_code.co_filename, frame.f_lineno, event))
@@ -423,7 +419,7 @@ def test_import_from_collection(monkeypatch):
sys.settrace(my_trace_function)
return my_trace_function
- else:
+ else: # pragma: nocover
# no existing trace function, so our trace function is much simpler
def my_trace_function(frame, event, arg):
trace_log.append((frame.f_code.co_filename, frame.f_lineno, event))
@@ -485,11 +481,8 @@ def test_import_from_collection(monkeypatch):
import ansible_collections.testns.testcoll.plugins.action.my_action
# verify that code loaded from a collection does not inherit __future__ statements from the collection loader
- if sys.version_info[0] == 2:
- # if the collection code inherits the division future feature from the collection loader this will fail
- assert answer == 1
- else:
- assert answer == 1.5
+ # if the collection code inherits the annotations future feature from the collection loader this will fail
+ assert inspect.get_annotations(question)['return'] is float
# verify that the filename and line number reported by the trace is correct
# this makes sure that collection loading preserves file paths and line numbers
@@ -822,7 +815,7 @@ def test_collectionref_components_valid(name, subdirs, resource, ref_type, pytho
]
)
def test_legacy_plugin_dir_to_plugin_type(dirname, expected_result):
- if isinstance(expected_result, string_types):
+ if isinstance(expected_result, str):
assert AnsibleCollectionRef.legacy_plugin_dir_to_plugin_type(dirname) == expected_result
else:
with pytest.raises(expected_result):
@@ -846,12 +839,8 @@ def test_collectionref_components_invalid(name, subdirs, resource, ref_type, exp
assert re.search(expected_error_expression, str(curerr.value))
-@pytest.mark.skipif(not PY3, reason='importlib.resources only supported for py3')
def test_importlib_resources():
- if sys.version_info < (3, 10):
- from importlib_resources import files
- else:
- from importlib.resources import files
+ from importlib.resources import files
from pathlib import Path
f = get_default_finder()
diff --git a/test/units/utils/display/test_broken_cowsay.py b/test/units/utils/display/test_broken_cowsay.py
index 96157e1..854b78b 100644
--- a/test/units/utils/display/test_broken_cowsay.py
+++ b/test/units/utils/display/test_broken_cowsay.py
@@ -2,9 +2,7 @@
# Copyright (c) 2021 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import absolute_import, division, print_function
-
-__metaclass__ = type
+from __future__ import annotations
from ansible.utils.display import Display
diff --git a/test/units/utils/display/test_curses.py b/test/units/utils/display/test_curses.py
index 05efc41..6816b71 100644
--- a/test/units/utils/display/test_curses.py
+++ b/test/units/utils/display/test_curses.py
@@ -2,8 +2,7 @@
# Copyright (c) 2021 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import absolute_import, division, print_function
-__metaclass__ = type
+from __future__ import annotations
import curses
import importlib
diff --git a/test/units/utils/display/test_display.py b/test/units/utils/display/test_display.py
index cdeb496..af5f659 100644
--- a/test/units/utils/display/test_display.py
+++ b/test/units/utils/display/test_display.py
@@ -2,8 +2,7 @@
# Copyright (c) 2020 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import absolute_import, division, print_function
-__metaclass__ = type
+from __future__ import annotations
from ansible.utils.display import Display
diff --git a/test/units/utils/display/test_logger.py b/test/units/utils/display/test_logger.py
index ed69393..8767aff 100644
--- a/test/units/utils/display/test_logger.py
+++ b/test/units/utils/display/test_logger.py
@@ -2,8 +2,7 @@
# Copyright (c) 2020 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import absolute_import, division, print_function
-__metaclass__ = type
+from __future__ import annotations
import logging
diff --git a/test/units/utils/display/test_warning.py b/test/units/utils/display/test_warning.py
index be63c34..32870fa 100644
--- a/test/units/utils/display/test_warning.py
+++ b/test/units/utils/display/test_warning.py
@@ -2,8 +2,7 @@
# Copyright (c) 2020 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import absolute_import, division, print_function
-__metaclass__ = type
+from __future__ import annotations
import pytest
diff --git a/test/units/utils/test_cleanup_tmp_file.py b/test/units/utils/test_cleanup_tmp_file.py
index 35374f4..213961d 100644
--- a/test/units/utils/test_cleanup_tmp_file.py
+++ b/test/units/utils/test_cleanup_tmp_file.py
@@ -2,8 +2,7 @@
# Copyright: (c) 2019, Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
import os
import tempfile
diff --git a/test/units/utils/test_context_objects.py b/test/units/utils/test_context_objects.py
index c56a41d..eb6bfa9 100644
--- a/test/units/utils/test_context_objects.py
+++ b/test/units/utils/test_context_objects.py
@@ -2,8 +2,7 @@
# Copyright: (c) 2018, Toshio Kuratomi <tkuratomi@ansible.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
import argparse
diff --git a/test/units/utils/test_display.py b/test/units/utils/test_display.py
index 80b7a09..ae7b16b 100644
--- a/test/units/utils/test_display.py
+++ b/test/units/utils/test_display.py
@@ -2,8 +2,7 @@
# (c) 2020 Matt Martz <matt@sivel.net>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import absolute_import, division, print_function
-__metaclass__ = type
+from __future__ import annotations
import locale
import sys
diff --git a/test/units/utils/test_encrypt.py b/test/units/utils/test_encrypt.py
index be32579..4683b81 100644
--- a/test/units/utils/test_encrypt.py
+++ b/test/units/utils/test_encrypt.py
@@ -1,10 +1,7 @@
# (c) 2018, Matthias Fuchs <matthias.s.fuchs@gmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import sys
+from __future__ import annotations
import pytest
@@ -13,50 +10,17 @@ from ansible.plugins.filter.core import get_encrypted_password
from ansible.utils import encrypt
-class passlib_off(object):
- def __init__(self):
- self.orig = encrypt.PASSLIB_AVAILABLE
-
- def __enter__(self):
- encrypt.PASSLIB_AVAILABLE = False
- return self
-
- def __exit__(self, exception_type, exception_value, traceback):
- encrypt.PASSLIB_AVAILABLE = self.orig
-
-
def assert_hash(expected, secret, algorithm, **settings):
-
assert encrypt.do_encrypt(secret, algorithm, **settings) == expected
- if encrypt.PASSLIB_AVAILABLE:
- assert encrypt.PasslibHash(algorithm).hash(secret, **settings) == expected
- else:
- with pytest.raises(AnsibleError) as excinfo:
- encrypt.PasslibHash(algorithm).hash(secret, **settings)
- assert excinfo.value.args[0] == "passlib must be installed and usable to hash with '%s'" % algorithm
+ assert encrypt.PasslibHash(algorithm).hash(secret, **settings) == expected
-@pytest.mark.skipif(sys.platform.startswith('darwin'), reason='macOS requires passlib')
-def test_passlib_or_crypt():
- with passlib_off():
- expected = "$5$rounds=5000$12345678$uAZsE3BenI2G.nA8DpTl.9Dc8JiqacI53pEqRr5ppT7"
- assert encrypt.passlib_or_crypt("123", "sha256_crypt", salt="12345678", rounds=5000) == expected
-
+@pytest.mark.skipif(not encrypt.PASSLIB_AVAILABLE, reason='passlib must be installed to run this test')
+def test_passlib():
expected = "$5$12345678$uAZsE3BenI2G.nA8DpTl.9Dc8JiqacI53pEqRr5ppT7"
assert encrypt.passlib_or_crypt("123", "sha256_crypt", salt="12345678", rounds=5000) == expected
-@pytest.mark.skipif(sys.platform.startswith('darwin'), reason='macOS requires passlib')
-def test_encrypt_with_rounds_no_passlib():
- with passlib_off():
- assert_hash("$5$rounds=5000$12345678$uAZsE3BenI2G.nA8DpTl.9Dc8JiqacI53pEqRr5ppT7",
- secret="123", algorithm="sha256_crypt", salt="12345678", rounds=5000)
- assert_hash("$5$rounds=10000$12345678$JBinliYMFEcBeAXKZnLjenhgEhTmJBvZn3aR8l70Oy/",
- secret="123", algorithm="sha256_crypt", salt="12345678", rounds=10000)
- assert_hash("$6$rounds=5000$12345678$LcV9LQiaPekQxZ.OfkMADjFdSO2k9zfbDQrHPVcYjSLqSdjLYpsgqviYvTEP/R41yPmhH3CCeEDqVhW1VHr3L.",
- secret="123", algorithm="sha512_crypt", salt="12345678", rounds=5000)
-
-
@pytest.mark.skipif(not encrypt.PASSLIB_AVAILABLE, reason='passlib must be installed to run this test')
def test_encrypt_with_ident():
assert_hash("$2$12$123456789012345678901ufd3hZRrev.WXCbemqGIV/gmWaTGLImm",
@@ -85,19 +49,6 @@ def test_encrypt_with_rounds():
secret="123", algorithm="sha512_crypt", salt="12345678", rounds=5000)
-@pytest.mark.skipif(sys.platform.startswith('darwin'), reason='macOS requires passlib')
-def test_encrypt_default_rounds_no_passlib():
- with passlib_off():
- assert_hash("$1$12345678$tRy4cXc3kmcfRZVj4iFXr/",
- secret="123", algorithm="md5_crypt", salt="12345678")
- assert_hash("$5$12345678$uAZsE3BenI2G.nA8DpTl.9Dc8JiqacI53pEqRr5ppT7",
- secret="123", algorithm="sha256_crypt", salt="12345678")
- assert_hash("$6$12345678$LcV9LQiaPekQxZ.OfkMADjFdSO2k9zfbDQrHPVcYjSLqSdjLYpsgqviYvTEP/R41yPmhH3CCeEDqVhW1VHr3L.",
- secret="123", algorithm="sha512_crypt", salt="12345678")
-
- assert encrypt.CryptHash("md5_crypt").hash("123")
-
-
# If passlib is not installed. this is identical to the test_encrypt_default_rounds_no_passlib() test
@pytest.mark.skipif(not encrypt.PASSLIB_AVAILABLE, reason='passlib must be installed to run this test')
def test_encrypt_default_rounds():
@@ -111,16 +62,6 @@ def test_encrypt_default_rounds():
assert encrypt.PasslibHash("md5_crypt").hash("123")
-@pytest.mark.skipif(sys.platform.startswith('darwin'), reason='macOS requires passlib')
-def test_password_hash_filter_no_passlib():
- with passlib_off():
- assert not encrypt.PASSLIB_AVAILABLE
- assert get_encrypted_password("123", "md5", salt="12345678") == "$1$12345678$tRy4cXc3kmcfRZVj4iFXr/"
-
- with pytest.raises(AnsibleFilterError):
- get_encrypted_password("123", "crypt16", salt="12")
-
-
@pytest.mark.skipif(not encrypt.PASSLIB_AVAILABLE, reason='passlib must be installed to run this test')
def test_password_hash_filter_passlib():
@@ -148,16 +89,6 @@ def test_password_hash_filter_passlib():
assert get_encrypted_password("123", "pbkdf2_sha256", ident='invalid_ident')
-@pytest.mark.skipif(sys.platform.startswith('darwin'), reason='macOS requires passlib')
-def test_do_encrypt_no_passlib():
- with passlib_off():
- assert not encrypt.PASSLIB_AVAILABLE
- assert encrypt.do_encrypt("123", "md5_crypt", salt="12345678") == "$1$12345678$tRy4cXc3kmcfRZVj4iFXr/"
-
- with pytest.raises(AnsibleError):
- encrypt.do_encrypt("123", "crypt16", salt="12")
-
-
@pytest.mark.skipif(not encrypt.PASSLIB_AVAILABLE, reason='passlib must be installed to run this test')
def test_do_encrypt_passlib():
with pytest.raises(AnsibleError):
@@ -183,30 +114,6 @@ def test_random_salt():
assert res_char in expected_salt_candidate_chars
-@pytest.mark.skipif(sys.platform.startswith('darwin'), reason='macOS requires passlib')
-def test_invalid_crypt_salt():
- pytest.raises(
- AnsibleError,
- encrypt.CryptHash('bcrypt')._salt,
- '_',
- None
- )
- encrypt.CryptHash('bcrypt')._salt('1234567890123456789012', None)
- pytest.raises(
- AnsibleError,
- encrypt.CryptHash('bcrypt')._salt,
- 'kljsdf',
- None
- )
- encrypt.CryptHash('sha256_crypt')._salt('123456', None)
- pytest.raises(
- AnsibleError,
- encrypt.CryptHash('sha256_crypt')._salt,
- '1234567890123456789012',
- None
- )
-
-
def test_passlib_bcrypt_salt(recwarn):
passlib_exc = pytest.importorskip("passlib.exc")
diff --git a/test/units/utils/test_helpers.py b/test/units/utils/test_helpers.py
index ec37b39..75e42c3 100644
--- a/test/units/utils/test_helpers.py
+++ b/test/units/utils/test_helpers.py
@@ -15,8 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
import unittest
diff --git a/test/units/utils/test_isidentifier.py b/test/units/utils/test_isidentifier.py
index de6de64..e4b2a40 100644
--- a/test/units/utils/test_isidentifier.py
+++ b/test/units/utils/test_isidentifier.py
@@ -2,9 +2,7 @@
# Copyright: (c) 2020 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-# Make coding more python3-ish
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
import pytest
diff --git a/test/units/utils/test_plugin_docs.py b/test/units/utils/test_plugin_docs.py
index ff973b1..d80f447 100644
--- a/test/units/utils/test_plugin_docs.py
+++ b/test/units/utils/test_plugin_docs.py
@@ -2,8 +2,7 @@
# (c) 2020 Felix Fontein <felix@fontein.de>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import absolute_import, division, print_function
-__metaclass__ = type
+from __future__ import annotations
import copy
@@ -292,7 +291,7 @@ ADD_TESTS = [
),
(
# Return values
- True, # this value is is ignored
+ True, # this value is ignored
True,
{
'rv1': {
diff --git a/test/units/utils/test_shlex.py b/test/units/utils/test_shlex.py
index e13d302..97a69c6 100644
--- a/test/units/utils/test_shlex.py
+++ b/test/units/utils/test_shlex.py
@@ -15,8 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
import unittest
diff --git a/test/units/utils/test_unsafe_proxy.py b/test/units/utils/test_unsafe_proxy.py
index 55f1b6d..483826a 100644
--- a/test/units/utils/test_unsafe_proxy.py
+++ b/test/units/utils/test_unsafe_proxy.py
@@ -2,8 +2,7 @@
# (c) 2018 Matt Martz <matt@sivel.net>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import absolute_import, division, print_function
-__metaclass__ = type
+from __future__ import annotations
import pathlib
import sys
diff --git a/test/units/utils/test_vars.py b/test/units/utils/test_vars.py
index 9be33de..11b01d1 100644
--- a/test/units/utils/test_vars.py
+++ b/test/units/utils/test_vars.py
@@ -16,17 +16,16 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-# Make coding more python3-ish
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
+from __future__ import annotations
from collections import defaultdict
from unittest import mock
-from units.compat import unittest
+import unittest
from ansible.errors import AnsibleError
from ansible.utils.vars import combine_vars, merge_hash
+from ansible.vars.manager import VarsWithSources
class TestVariableUtils(unittest.TestCase):
@@ -43,6 +42,11 @@ class TestVariableUtils(unittest.TestCase):
result=dict(a=1, b=2),
),
dict(
+ a=dict(a=1),
+ b=VarsWithSources().new_vars_with_sources(dict(b=2), dict(b='task vars')),
+ result=dict(a=1, b=2),
+ ),
+ dict(
a=dict(a=1, c=dict(foo='bar')),
b=dict(b=2, c=dict(baz='bam')),
result=dict(a=1, b=2, c=dict(foo='bar', baz='bam'))
@@ -60,6 +64,11 @@ class TestVariableUtils(unittest.TestCase):
result=dict(a=1, b=2)
),
dict(
+ a=dict(a=1),
+ b=VarsWithSources().new_vars_with_sources(dict(b=2), dict(b='task vars')),
+ result=dict(a=1, b=2),
+ ),
+ dict(
a=dict(a=1, c=dict(foo='bar')),
b=dict(b=2, c=dict(baz='bam')),
result=dict(a=1, b=2, c=dict(baz='bam'))
diff --git a/test/units/utils/test_version.py b/test/units/utils/test_version.py
index 3c2cbaf..715076a 100644
--- a/test/units/utils/test_version.py
+++ b/test/units/utils/test_version.py
@@ -2,8 +2,7 @@
# (c) 2020 Matt Martz <matt@sivel.net>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-from __future__ import absolute_import, division, print_function
-__metaclass__ = type
+from __future__ import annotations
from ansible.module_utils.compat.version import LooseVersion, StrictVersion