diff options
Diffstat (limited to 'test/units/plugins')
-rw-r--r-- | test/units/plugins/action/test_action.py | 6 | ||||
-rw-r--r-- | test/units/plugins/connection/test_ssh.py | 18 | ||||
-rw-r--r-- | test/units/plugins/inventory/test_inventory.py | 5 | ||||
-rw-r--r-- | test/units/plugins/lookup/test_password.py | 13 |
4 files changed, 20 insertions, 22 deletions
diff --git a/test/units/plugins/action/test_action.py b/test/units/plugins/action/test_action.py index 5f3acf2c95..7d9c2915dd 100644 --- a/test/units/plugins/action/test_action.py +++ b/test/units/plugins/action/test_action.py @@ -27,8 +27,8 @@ import unittest from unittest.mock import patch, MagicMock, mock_open from ansible.errors import AnsibleError, AnsibleAuthenticationFailure -from ansible.module_utils.six import text_type -from ansible.module_utils.six.moves import shlex_quote, builtins +import builtins +import shlex from ansible.module_utils.common.text.converters import to_bytes from ansible.playbook.play_context import PlayContext from ansible.plugins.action import ActionBase @@ -195,7 +195,7 @@ class TestActionBase(unittest.TestCase): # create a mock connection, so we don't actually try and connect to things def env_prefix(**args): - return ' '.join(['%s=%s' % (k, shlex_quote(text_type(v))) for k, v in args.items()]) + return ' '.join(['%s=%s' % (k, shlex.quote(str(v))) for k, v in args.items()]) mock_connection = MagicMock() mock_connection._shell.env_prefix.side_effect = env_prefix diff --git a/test/units/plugins/connection/test_ssh.py b/test/units/plugins/connection/test_ssh.py index 943778a3ac..3ea02d050f 100644 --- a/test/units/plugins/connection/test_ssh.py +++ b/test/units/plugins/connection/test_ssh.py @@ -27,7 +27,7 @@ from ansible.errors import AnsibleAuthenticationFailure import unittest from unittest.mock import patch, MagicMock, PropertyMock from ansible.errors import AnsibleError, AnsibleConnectionFailure, AnsibleFileNotFound -from ansible.module_utils.six.moves import shlex_quote +import shlex from ansible.module_utils.common.text.converters import to_bytes from ansible.playbook.play_context import PlayContext from ansible.plugins.connection import ssh @@ -246,7 +246,7 @@ class TestConnectionBaseClass(unittest.TestCase): # Test with SCP_IF_SSH set to smart # Test when SFTP works conn.set_option('scp_if_ssh', 'smart') - expected_in_data = b' '.join((b'put', to_bytes(shlex_quote('/path/to/in/file')), to_bytes(shlex_quote('/path/to/dest/file')))) + b'\n' + expected_in_data = b' '.join((b'put', to_bytes(shlex.quote('/path/to/in/file')), to_bytes(shlex.quote('/path/to/dest/file')))) + b'\n' conn.put_file('/path/to/in/file', '/path/to/dest/file') conn._bare_run.assert_called_with('some command to run', expected_in_data, checkrc=False) @@ -266,13 +266,13 @@ class TestConnectionBaseClass(unittest.TestCase): # test with SCPP_IF_SSH disabled conn.set_option('scp_if_ssh', False) - expected_in_data = b' '.join((b'put', to_bytes(shlex_quote('/path/to/in/file')), to_bytes(shlex_quote('/path/to/dest/file')))) + b'\n' + expected_in_data = b' '.join((b'put', to_bytes(shlex.quote('/path/to/in/file')), to_bytes(shlex.quote('/path/to/dest/file')))) + b'\n' conn.put_file('/path/to/in/file', '/path/to/dest/file') conn._bare_run.assert_called_with('some command to run', expected_in_data, checkrc=False) expected_in_data = b' '.join((b'put', - to_bytes(shlex_quote('/path/to/in/file/with/unicode-fö〩')), - to_bytes(shlex_quote('/path/to/dest/file/with/unicode-fö〩')))) + b'\n' + to_bytes(shlex.quote('/path/to/in/file/with/unicode-fö〩')), + to_bytes(shlex.quote('/path/to/dest/file/with/unicode-fö〩')))) + b'\n' conn.put_file(u'/path/to/in/file/with/unicode-fö〩', u'/path/to/dest/file/with/unicode-fö〩') conn._bare_run.assert_called_with('some command to run', expected_in_data, checkrc=False) @@ -304,7 +304,7 @@ class TestConnectionBaseClass(unittest.TestCase): # Test with SCP_IF_SSH set to smart # Test when SFTP works conn.set_option('scp_if_ssh', 'smart') - expected_in_data = b' '.join((b'get', to_bytes(shlex_quote('/path/to/in/file')), to_bytes(shlex_quote('/path/to/dest/file')))) + b'\n' + expected_in_data = b' '.join((b'get', to_bytes(shlex.quote('/path/to/in/file')), to_bytes(shlex.quote('/path/to/dest/file')))) + b'\n' conn.set_options({}) conn.fetch_file('/path/to/in/file', '/path/to/dest/file') conn._bare_run.assert_called_with('some command to run', expected_in_data, checkrc=False) @@ -326,13 +326,13 @@ class TestConnectionBaseClass(unittest.TestCase): # test with SCP_IF_SSH disabled conn.set_option('scp_if_ssh', False) - expected_in_data = b' '.join((b'get', to_bytes(shlex_quote('/path/to/in/file')), to_bytes(shlex_quote('/path/to/dest/file')))) + b'\n' + expected_in_data = b' '.join((b'get', to_bytes(shlex.quote('/path/to/in/file')), to_bytes(shlex.quote('/path/to/dest/file')))) + b'\n' conn.fetch_file('/path/to/in/file', '/path/to/dest/file') conn._bare_run.assert_called_with('some command to run', expected_in_data, checkrc=False) expected_in_data = b' '.join((b'get', - to_bytes(shlex_quote('/path/to/in/file/with/unicode-fö〩')), - to_bytes(shlex_quote('/path/to/dest/file/with/unicode-fö〩')))) + b'\n' + to_bytes(shlex.quote('/path/to/in/file/with/unicode-fö〩')), + to_bytes(shlex.quote('/path/to/dest/file/with/unicode-fö〩')))) + b'\n' conn.fetch_file(u'/path/to/in/file/with/unicode-fö〩', u'/path/to/dest/file/with/unicode-fö〩') conn._bare_run.assert_called_with('some command to run', expected_in_data, checkrc=False) diff --git a/test/units/plugins/inventory/test_inventory.py b/test/units/plugins/inventory/test_inventory.py index 3d704cabf7..ee9811c89b 100644 --- a/test/units/plugins/inventory/test_inventory.py +++ b/test/units/plugins/inventory/test_inventory.py @@ -24,7 +24,6 @@ from unittest import mock from ansible import constants as C import unittest -from ansible.module_utils.six import string_types from ansible.module_utils.common.text.converters import to_text from units.mock.path import mock_unfrackpath_noop @@ -158,8 +157,8 @@ class TestInventoryPlugins(unittest.TestCase): variables = inventory.get_host('host1').vars for i in range(len(values)): - if isinstance(values[i], string_types): - self.assertIsInstance(variables['var%s' % i], string_types) + if isinstance(values[i], str): + self.assertIsInstance(variables['var%s' % i], str) else: self.assertIsInstance(variables['var%s' % i], type(values[i])) diff --git a/test/units/plugins/lookup/test_password.py b/test/units/plugins/lookup/test_password.py index 93524f39f4..d615be998e 100644 --- a/test/units/plugins/lookup/test_password.py +++ b/test/units/plugins/lookup/test_password.py @@ -32,8 +32,7 @@ from units.mock.loader import DictDataLoader import unittest from unittest.mock import mock_open, patch from ansible.errors import AnsibleError -from ansible.module_utils.six import text_type -from ansible.module_utils.six.moves import builtins +import builtins from ansible.module_utils.common.text.converters import to_bytes from ansible.plugins.loader import PluginLoader, lookup_loader from ansible.plugins.lookup import password @@ -274,13 +273,13 @@ class TestRandomPassword(unittest.TestCase): def test_default(self): res = password.random_password() self.assertEqual(len(res), DEFAULT_LENGTH) - self.assertTrue(isinstance(res, text_type)) + self.assertTrue(isinstance(res, str)) self._assert_valid_chars(res, DEFAULT_CANDIDATE_CHARS) def test_zero_length(self): res = password.random_password(length=0) self.assertEqual(len(res), 0) - self.assertTrue(isinstance(res, text_type)) + self.assertTrue(isinstance(res, str)) self._assert_valid_chars(res, u',') def test_just_a_common(self): @@ -435,7 +434,7 @@ class TestLookupModuleWithoutPasslib(BaseTestLookupModule): # FIXME: assert something useful for result in results: assert len(result) == DEFAULT_LENGTH - assert isinstance(result, text_type) + assert isinstance(result, str) @patch.object(PluginLoader, '_get_paths') @patch('ansible.plugins.lookup.password._write_password_file') @@ -518,7 +517,7 @@ class TestLookupModuleWithPasslib(BaseTestLookupModule): # verify the string and parsehash agree on the number of rounds self.assertEqual(int(str_parts[2]), crypt_parts['rounds']) - self.assertIsInstance(result, text_type) + self.assertIsInstance(result, str) @patch('ansible.plugins.lookup.password._write_password_file') def test_password_already_created_encrypt(self, mock_write_file): @@ -554,7 +553,7 @@ class TestLookupModuleWithPasslibWrappedAlgo(BaseTestLookupModule): self.assertEqual(len(results), 1) result = results[0] - self.assertIsInstance(result, text_type) + self.assertIsInstance(result, str) expected_password_length = 76 self.assertEqual(len(result), expected_password_length) |