mirror of
https://github.com/ansible/ansible.git
synced 2026-08-02 16:12:06 +02:00
Remove unused/unreachable unit test code (#82160)
This commit is contained in:
@@ -49,8 +49,6 @@ class TestOtherFilesystem(ModuleTestCase):
|
|||||||
def _mock_ismount(path):
|
def _mock_ismount(path):
|
||||||
if path == b'/subdir/mount':
|
if path == b'/subdir/mount':
|
||||||
return True
|
return True
|
||||||
if path == b'/':
|
|
||||||
return True
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
with patch('os.path.ismount', side_effect=_mock_ismount):
|
with patch('os.path.ismount', side_effect=_mock_ismount):
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ class TestRemoveValues(unittest.TestCase):
|
|||||||
|
|
||||||
levels = 0
|
levels = 0
|
||||||
inner_list = actual_data_list
|
inner_list = actual_data_list
|
||||||
while inner_list:
|
while True:
|
||||||
if isinstance(inner_list, list):
|
if isinstance(inner_list, list):
|
||||||
self.assertEqual(len(inner_list), 1)
|
self.assertEqual(len(inner_list), 1)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import errno
|
|
||||||
import selectors
|
import selectors
|
||||||
from itertools import product
|
from itertools import product
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
@@ -26,10 +25,6 @@ class OpenBytesIO(BytesIO):
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_os(mocker):
|
def mock_os(mocker):
|
||||||
def mock_os_chdir(path):
|
|
||||||
if path == '/inaccessible':
|
|
||||||
raise OSError(errno.EPERM, "Permission denied: '/inaccessible'")
|
|
||||||
|
|
||||||
def mock_os_abspath(path):
|
def mock_os_abspath(path):
|
||||||
if path.startswith('/'):
|
if path.startswith('/'):
|
||||||
return path
|
return path
|
||||||
@@ -43,17 +38,11 @@ def mock_os(mocker):
|
|||||||
os.environ = {'PATH': '/bin'}
|
os.environ = {'PATH': '/bin'}
|
||||||
os.getcwd.return_value = '/home/foo'
|
os.getcwd.return_value = '/home/foo'
|
||||||
os.path.isdir.return_value = True
|
os.path.isdir.return_value = True
|
||||||
os.chdir.side_effect = mock_os_chdir
|
|
||||||
os.path.abspath.side_effect = mock_os_abspath
|
os.path.abspath.side_effect = mock_os_abspath
|
||||||
|
|
||||||
yield os
|
yield os
|
||||||
|
|
||||||
|
|
||||||
class DummyFileObj():
|
|
||||||
def __init__(self, fileobj):
|
|
||||||
self.fileobj = fileobj
|
|
||||||
|
|
||||||
|
|
||||||
class SpecialBytesIO(BytesIO):
|
class SpecialBytesIO(BytesIO):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
fh = kwargs.pop('fh', None)
|
fh = kwargs.pop('fh', None)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import shutil
|
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -76,7 +75,6 @@ class TestAnsibleModuleTmpDir:
|
|||||||
monkeypatch.setattr(tempfile, 'mkdtemp', mock_mkdtemp)
|
monkeypatch.setattr(tempfile, 'mkdtemp', mock_mkdtemp)
|
||||||
monkeypatch.setattr(os.path, 'exists', lambda x: stat_exists)
|
monkeypatch.setattr(os.path, 'exists', lambda x: stat_exists)
|
||||||
monkeypatch.setattr(os, 'makedirs', mock_makedirs)
|
monkeypatch.setattr(os, 'makedirs', mock_makedirs)
|
||||||
monkeypatch.setattr(shutil, 'rmtree', lambda x: None)
|
|
||||||
monkeypatch.setattr(basic, '_ANSIBLE_ARGS', to_bytes(json.dumps({'ANSIBLE_MODULE_ARGS': args})))
|
monkeypatch.setattr(basic, '_ANSIBLE_ARGS', to_bytes(json.dumps({'ANSIBLE_MODULE_ARGS': args})))
|
||||||
|
|
||||||
with patch('time.time', return_value=42):
|
with patch('time.time', return_value=42):
|
||||||
|
|||||||
@@ -29,9 +29,3 @@ class TestDistro():
|
|||||||
def test_id(self):
|
def test_id(self):
|
||||||
id = distro.id()
|
id = distro.id()
|
||||||
assert isinstance(id, str), 'distro.id() returned %s (%s) which is not a string' % (id, type(id))
|
assert isinstance(id, str), 'distro.id() returned %s (%s) which is not a string' % (id, type(id))
|
||||||
|
|
||||||
def test_opensuse_leap_id(self):
|
|
||||||
name = distro.name()
|
|
||||||
if name == 'openSUSE Leap':
|
|
||||||
id = distro.id()
|
|
||||||
assert id == 'opensuse', "OpenSUSE Leap did not return 'opensuse' as id"
|
|
||||||
|
|||||||
@@ -185,8 +185,7 @@ def test_root_loader():
|
|||||||
name = 'ansible_collections'
|
name = 'ansible_collections'
|
||||||
# ensure this works even when ansible_collections doesn't exist on disk
|
# ensure this works even when ansible_collections doesn't exist on disk
|
||||||
for paths in [], default_test_collection_paths:
|
for paths in [], default_test_collection_paths:
|
||||||
if name in sys.modules:
|
sys.modules.pop(name, None)
|
||||||
del sys.modules[name]
|
|
||||||
loader = _AnsibleCollectionRootPkgLoader(name, paths)
|
loader = _AnsibleCollectionRootPkgLoader(name, paths)
|
||||||
assert repr(loader).startswith('_AnsibleCollectionRootPkgLoader(path=')
|
assert repr(loader).startswith('_AnsibleCollectionRootPkgLoader(path=')
|
||||||
module = loader.load_module(name)
|
module = loader.load_module(name)
|
||||||
@@ -213,8 +212,7 @@ def test_nspkg_loader_load_module():
|
|||||||
module_to_load = name.rpartition('.')[2]
|
module_to_load = name.rpartition('.')[2]
|
||||||
paths = extend_paths(default_test_collection_paths, parent_pkg)
|
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)]
|
existing_child_paths = [p for p in extend_paths(paths, module_to_load) if os.path.exists(p)]
|
||||||
if name in sys.modules:
|
sys.modules.pop(name, None)
|
||||||
del sys.modules[name]
|
|
||||||
loader = _AnsibleCollectionNSPkgLoader(name, path_list=paths)
|
loader = _AnsibleCollectionNSPkgLoader(name, path_list=paths)
|
||||||
assert repr(loader).startswith('_AnsibleCollectionNSPkgLoader(path=')
|
assert repr(loader).startswith('_AnsibleCollectionNSPkgLoader(path=')
|
||||||
module = loader.load_module(name)
|
module = loader.load_module(name)
|
||||||
@@ -243,8 +241,7 @@ def test_collpkg_loader_load_module():
|
|||||||
paths = extend_paths(default_test_collection_paths, parent_pkg)
|
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)]
|
existing_child_paths = [p for p in extend_paths(paths, module_to_load) if os.path.exists(p)]
|
||||||
is_builtin = 'ansible.builtin' in name
|
is_builtin = 'ansible.builtin' in name
|
||||||
if name in sys.modules:
|
sys.modules.pop(name, None)
|
||||||
del sys.modules[name]
|
|
||||||
loader = _AnsibleCollectionPkgLoader(name, path_list=paths)
|
loader = _AnsibleCollectionPkgLoader(name, path_list=paths)
|
||||||
assert repr(loader).startswith('_AnsibleCollectionPkgLoader(path=')
|
assert repr(loader).startswith('_AnsibleCollectionPkgLoader(path=')
|
||||||
module = loader.load_module(name)
|
module = loader.load_module(name)
|
||||||
@@ -266,13 +263,16 @@ def test_collpkg_loader_load_module():
|
|||||||
|
|
||||||
# FIXME: validate _collection_meta contents match what's on disk (or not)
|
# FIXME: validate _collection_meta contents match what's on disk (or not)
|
||||||
|
|
||||||
# if the module has metadata, try loading it with busted metadata
|
# verify the module has metadata, then try loading it with busted metadata
|
||||||
if module._collection_meta:
|
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')):
|
_collection_finder = import_module('ansible.utils.collection_loader._collection_finder')
|
||||||
with pytest.raises(Exception) as ex:
|
|
||||||
_AnsibleCollectionPkgLoader(name, path_list=paths).load_module(name)
|
with patch.object(_collection_finder, '_meta_yml_to_dict', side_effect=Exception('bang')):
|
||||||
assert 'error parsing collection metadata' in str(ex.value)
|
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():
|
def test_coll_loader():
|
||||||
|
|||||||
Reference in New Issue
Block a user