Skip to content

Commit

Permalink
Fix unittests for always adding basic to the AnsiBallZ zips
Browse files Browse the repository at this point in the history
  • Loading branch information
abadger committed Aug 24, 2018
1 parent 5550300 commit 8ec973b
Showing 1 changed file with 43 additions and 12 deletions.
55 changes: 43 additions & 12 deletions test/units/executor/module_common/test_recursive_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,37 @@

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
def finder_containers():
Expand Down Expand Up @@ -69,9 +100,9 @@ def test_no_module_utils(self, finder_containers):
name = 'ping'
data = b'#!/usr/bin/python\nreturn \'{\"changed\": false}\''
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 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):
if PY2:
Expand All @@ -86,9 +117,9 @@ def test_from_import_toplevel_package(self, finder_containers, mocker):
recursive_finder(name, data, *finder_containers)
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 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):
if PY2:
Expand All @@ -102,9 +133,9 @@ def test_from_import_toplevel_module(self, finder_containers, mocker):
recursive_finder(name, data, *finder_containers)
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 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
Expand All @@ -113,22 +144,22 @@ def test_from_import_six(self, finder_containers):
name = 'ping'
data = b'#!/usr/bin/python\nfrom ansible.module_utils import six'
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 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):
name = 'ping'
data = b'#!/usr/bin/python\nimport ansible.module_utils.six'
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 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):
name = 'ping'
data = b'#!/usr/bin/python\nfrom ansible.module_utils.six.moves.urllib.parse import urlparse'
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 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)

0 comments on commit 8ec973b

Please sign in to comment.