Fix unittests for always adding basic to the AnsiBallZ zips

This commit is contained in:
Toshio Kuratomi 2018-08-23 20:54:40 -07:00
parent 55503004ec
commit 8ec973b453

View file

@ -36,6 +36,37 @@ from ansible.module_utils.six.moves import builtins
original_find_module = imp.find_module original_find_module = imp.find_module
# These are the modules that are brought in by module_utils/basic.py This may need to be updated
# when basic.py gains new imports
# We will remove these when we modify AnsiBallZ to store its args in a separate file instead of in
# basic.py
MODULE_UTILS_BASIC_IMPORTS = frozenset((('_text',),
('basic',),
('common', '__init__'),
('common', '_collections_compat'),
('common', 'file'),
('common', 'process'),
('parsing', '__init__'),
('parsing', 'convert_bool'),
('pycompat24',),
('six', '__init__'),
))
MODULE_UTILS_BASIC_FILES = frozenset(('ansible/module_utils/parsing/__init__.py',
'ansible/module_utils/common/process.py',
'ansible/module_utils/basic.py',
'ansible/module_utils/six/__init__.py',
'ansible/module_utils/_text.py',
'ansible/module_utils/common/_collections_compat.py',
'ansible/module_utils/parsing/convert_bool.py',
'ansible/module_utils/common/__init__.py',
'ansible/module_utils/common/file.py',
'ansible/module_utils/pycompat24.py',
))
ONLY_BASIC_IMPORT = frozenset((('basic',),))
ONLY_BASIC_FILE = frozenset(('ansible/module_utils/basic.py',))
@pytest.fixture @pytest.fixture
def finder_containers(): def finder_containers():
@ -69,9 +100,9 @@ class TestRecursiveFinder(object):
name = 'ping' name = 'ping'
data = b'#!/usr/bin/python\nreturn \'{\"changed\": false}\'' data = b'#!/usr/bin/python\nreturn \'{\"changed\": false}\''
recursive_finder(name, data, *finder_containers) recursive_finder(name, data, *finder_containers)
assert finder_containers.py_module_names == set(()) assert finder_containers.py_module_names == set(()).union(MODULE_UTILS_BASIC_IMPORTS)
assert finder_containers.py_module_cache == {} assert finder_containers.py_module_cache == {}
assert frozenset(finder_containers.zf.namelist()) == frozenset() assert frozenset(finder_containers.zf.namelist()) == MODULE_UTILS_BASIC_FILES
def test_from_import_toplevel_package(self, finder_containers, mocker): def test_from_import_toplevel_package(self, finder_containers, mocker):
if PY2: if PY2:
@ -86,9 +117,9 @@ class TestRecursiveFinder(object):
recursive_finder(name, data, *finder_containers) recursive_finder(name, data, *finder_containers)
mocker.stopall() mocker.stopall()
assert finder_containers.py_module_names == set((('foo', '__init__'),)) assert finder_containers.py_module_names == set((('foo', '__init__'),)).union(ONLY_BASIC_IMPORT)
assert finder_containers.py_module_cache == {} assert finder_containers.py_module_cache == {}
assert frozenset(finder_containers.zf.namelist()) == frozenset(('ansible/module_utils/foo/__init__.py',)) assert frozenset(finder_containers.zf.namelist()) == frozenset(('ansible/module_utils/foo/__init__.py',)).union(ONLY_BASIC_FILE)
def test_from_import_toplevel_module(self, finder_containers, mocker): def test_from_import_toplevel_module(self, finder_containers, mocker):
if PY2: if PY2:
@ -102,9 +133,9 @@ class TestRecursiveFinder(object):
recursive_finder(name, data, *finder_containers) recursive_finder(name, data, *finder_containers)
mocker.stopall() mocker.stopall()
assert finder_containers.py_module_names == set((('foo',),)) assert finder_containers.py_module_names == set((('foo',),)).union(MODULE_UTILS_BASIC_IMPORTS)
assert finder_containers.py_module_cache == {} assert finder_containers.py_module_cache == {}
assert frozenset(finder_containers.zf.namelist()) == frozenset(('ansible/module_utils/foo.py',)) assert frozenset(finder_containers.zf.namelist()) == frozenset(('ansible/module_utils/foo.py',)).union(MODULE_UTILS_BASIC_FILES)
# #
# Test importing six with many permutations because it is not a normal module # Test importing six with many permutations because it is not a normal module
@ -113,22 +144,22 @@ class TestRecursiveFinder(object):
name = 'ping' name = 'ping'
data = b'#!/usr/bin/python\nfrom ansible.module_utils import six' data = b'#!/usr/bin/python\nfrom ansible.module_utils import six'
recursive_finder(name, data, *finder_containers) recursive_finder(name, data, *finder_containers)
assert finder_containers.py_module_names == set((('six', '__init__'),)) assert finder_containers.py_module_names == set((('six', '__init__'),)).union(MODULE_UTILS_BASIC_IMPORTS)
assert finder_containers.py_module_cache == {} assert finder_containers.py_module_cache == {}
assert frozenset(finder_containers.zf.namelist()) == frozenset(('ansible/module_utils/six/__init__.py', )) assert frozenset(finder_containers.zf.namelist()) == frozenset(('ansible/module_utils/six/__init__.py', )).union(MODULE_UTILS_BASIC_FILES)
def test_import_six(self, finder_containers): def test_import_six(self, finder_containers):
name = 'ping' name = 'ping'
data = b'#!/usr/bin/python\nimport ansible.module_utils.six' data = b'#!/usr/bin/python\nimport ansible.module_utils.six'
recursive_finder(name, data, *finder_containers) recursive_finder(name, data, *finder_containers)
assert finder_containers.py_module_names == set((('six', '__init__'),)) assert finder_containers.py_module_names == set((('six', '__init__'),)).union(MODULE_UTILS_BASIC_IMPORTS)
assert finder_containers.py_module_cache == {} assert finder_containers.py_module_cache == {}
assert frozenset(finder_containers.zf.namelist()) == frozenset(('ansible/module_utils/six/__init__.py', )) assert frozenset(finder_containers.zf.namelist()) == frozenset(('ansible/module_utils/six/__init__.py', )).union(MODULE_UTILS_BASIC_FILES)
def test_import_six_from_many_submodules(self, finder_containers): def test_import_six_from_many_submodules(self, finder_containers):
name = 'ping' name = 'ping'
data = b'#!/usr/bin/python\nfrom ansible.module_utils.six.moves.urllib.parse import urlparse' data = b'#!/usr/bin/python\nfrom ansible.module_utils.six.moves.urllib.parse import urlparse'
recursive_finder(name, data, *finder_containers) recursive_finder(name, data, *finder_containers)
assert finder_containers.py_module_names == set((('six', '__init__'),)) assert finder_containers.py_module_names == set((('six', '__init__'),)).union(MODULE_UTILS_BASIC_IMPORTS)
assert finder_containers.py_module_cache == {} assert finder_containers.py_module_cache == {}
assert frozenset(finder_containers.zf.namelist()) == frozenset(('ansible/module_utils/six/__init__.py',)) assert frozenset(finder_containers.zf.namelist()) == frozenset(('ansible/module_utils/six/__init__.py',)).union(MODULE_UTILS_BASIC_FILES)