mirror of
https://github.com/ansible/ansible.git
synced 2026-07-31 16:24:36 +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):
|
||||
if path == b'/subdir/mount':
|
||||
return True
|
||||
if path == b'/':
|
||||
return True
|
||||
return False
|
||||
|
||||
with patch('os.path.ismount', side_effect=_mock_ismount):
|
||||
|
||||
@@ -146,7 +146,7 @@ class TestRemoveValues(unittest.TestCase):
|
||||
|
||||
levels = 0
|
||||
inner_list = actual_data_list
|
||||
while inner_list:
|
||||
while True:
|
||||
if isinstance(inner_list, list):
|
||||
self.assertEqual(len(inner_list), 1)
|
||||
else:
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import errno
|
||||
import selectors
|
||||
from itertools import product
|
||||
from io import BytesIO
|
||||
@@ -26,10 +25,6 @@ class OpenBytesIO(BytesIO):
|
||||
|
||||
@pytest.fixture
|
||||
def mock_os(mocker):
|
||||
def mock_os_chdir(path):
|
||||
if path == '/inaccessible':
|
||||
raise OSError(errno.EPERM, "Permission denied: '/inaccessible'")
|
||||
|
||||
def mock_os_abspath(path):
|
||||
if path.startswith('/'):
|
||||
return path
|
||||
@@ -43,17 +38,11 @@ def mock_os(mocker):
|
||||
os.environ = {'PATH': '/bin'}
|
||||
os.getcwd.return_value = '/home/foo'
|
||||
os.path.isdir.return_value = True
|
||||
os.chdir.side_effect = mock_os_chdir
|
||||
os.path.abspath.side_effect = mock_os_abspath
|
||||
|
||||
yield os
|
||||
|
||||
|
||||
class DummyFileObj():
|
||||
def __init__(self, fileobj):
|
||||
self.fileobj = fileobj
|
||||
|
||||
|
||||
class SpecialBytesIO(BytesIO):
|
||||
def __init__(self, *args, **kwargs):
|
||||
fh = kwargs.pop('fh', None)
|
||||
|
||||
@@ -6,7 +6,6 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
import pytest
|
||||
@@ -76,7 +75,6 @@ class TestAnsibleModuleTmpDir:
|
||||
monkeypatch.setattr(tempfile, 'mkdtemp', mock_mkdtemp)
|
||||
monkeypatch.setattr(os.path, 'exists', lambda x: stat_exists)
|
||||
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})))
|
||||
|
||||
with patch('time.time', return_value=42):
|
||||
|
||||
@@ -29,9 +29,3 @@ class TestDistro():
|
||||
def test_id(self):
|
||||
id = distro.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'
|
||||
# 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)
|
||||
@@ -213,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)
|
||||
@@ -243,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)
|
||||
@@ -266,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():
|
||||
|
||||
Reference in New Issue
Block a user