mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
pip module: fix TypeError (#31395)
* pip: add test: an error occurs when pip not found * pip: fix TypeError exception when pip executable isn't found
This commit is contained in:
parent
5e9384300d
commit
1c9bffe248
6 changed files with 31 additions and 5 deletions
|
@ -286,7 +286,7 @@ def _get_pip(module, env=None, executable=None):
|
||||||
else:
|
else:
|
||||||
# For-else: Means that we did not break out of the loop
|
# For-else: Means that we did not break out of the loop
|
||||||
# (therefore, that pip was not found)
|
# (therefore, that pip was not found)
|
||||||
module.fail_json(msg='Unable to find any of %s to use. pip' +
|
module.fail_json(msg='Unable to find any of %s to use. pip'
|
||||||
' needs to be installed.' % ', '.join(candidate_pip_basenames))
|
' needs to be installed.' % ', '.join(candidate_pip_basenames))
|
||||||
else:
|
else:
|
||||||
# If we're using a virtualenv we must use the pip from the
|
# If we're using a virtualenv we must use the pip from the
|
||||||
|
|
0
test/units/modules/packaging/language/__init__.py
Normal file
0
test/units/modules/packaging/language/__init__.py
Normal file
26
test/units/modules/packaging/language/test_pip.py
Normal file
26
test/units/modules/packaging/language/test_pip.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
from ansible.compat.tests import unittest
|
||||||
|
from ansible.compat.tests.mock import patch
|
||||||
|
from ansible.module_utils import basic
|
||||||
|
|
||||||
|
from ansible.modules.packaging.language import pip
|
||||||
|
|
||||||
|
from ..utils import (set_module_args, AnsibleFailJson, exit_json, fail_json)
|
||||||
|
|
||||||
|
|
||||||
|
class TestPip(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.mock_ansible_module = patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
|
||||||
|
self.mock_ansible_module.start()
|
||||||
|
self.addCleanup(self.mock_ansible_module.stop)
|
||||||
|
|
||||||
|
@patch.object(basic.AnsibleModule, 'get_bin_path')
|
||||||
|
def test_failure_when_pip_absent(self, mock_get_bin_path):
|
||||||
|
|
||||||
|
mock_get_bin_path.return_value = None
|
||||||
|
|
||||||
|
with self.assertRaises(AnsibleFailJson):
|
||||||
|
set_module_args({'name': 'six'})
|
||||||
|
pip.main()
|
|
@ -7,8 +7,8 @@ from ansible.module_utils.six.moves import xmlrpc_client
|
||||||
from ansible.module_utils._text import to_bytes
|
from ansible.module_utils._text import to_bytes
|
||||||
from ansible.modules.packaging.os import rhn_channel
|
from ansible.modules.packaging.os import rhn_channel
|
||||||
|
|
||||||
from .rhn_utils import (set_module_args, AnsibleExitJson, AnsibleFailJson,
|
from ..utils import (set_module_args, AnsibleExitJson, AnsibleFailJson,
|
||||||
exit_json, fail_json, get_method_name, mock_request)
|
exit_json, fail_json, get_method_name, mock_request)
|
||||||
|
|
||||||
|
|
||||||
class TestRhnChannel(unittest.TestCase):
|
class TestRhnChannel(unittest.TestCase):
|
||||||
|
|
|
@ -7,8 +7,8 @@ from ansible.module_utils._text import to_native
|
||||||
from ansible.module_utils.six.moves import xmlrpc_client
|
from ansible.module_utils.six.moves import xmlrpc_client
|
||||||
from ansible.modules.packaging.os import rhn_register
|
from ansible.modules.packaging.os import rhn_register
|
||||||
|
|
||||||
from .rhn_utils import (set_module_args, AnsibleExitJson, AnsibleFailJson,
|
from ..utils import (set_module_args, AnsibleExitJson, AnsibleFailJson,
|
||||||
exit_json, fail_json, get_method_name, mock_request)
|
exit_json, fail_json, get_method_name, mock_request)
|
||||||
|
|
||||||
|
|
||||||
SYSTEMID = """<?xml version="1.0"?>
|
SYSTEMID = """<?xml version="1.0"?>
|
||||||
|
|
Loading…
Add table
Reference in a new issue