提交 b2cf2f2f 编写于 作者: C Cleber Rosa

Python 3 port: adjust mock import on test_utils_process.py

Mock is slightly lighter than MagicMock, which is only necessary
when mocking "magic" methods.  So, let's revert to the lighter
Mock class.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 a72a8ab5
......@@ -81,126 +81,126 @@ def mock_fail_find_cmd(cmd, default=None):
class TestProcessRun(unittest.TestCase):
@mock.patch.object(path, 'find_command',
mock.MagicMock(return_value=TRUE_CMD))
mock.Mock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid',
mock.MagicMock(return_value=1000))
mock.Mock(return_value=1000))
def test_subprocess_nosudo(self):
expected_command = 'ls -l'
p = process.SubProcess(cmd='ls -l')
self.assertEqual(p.cmd, expected_command)
@mock.patch.object(path, 'find_command',
mock.MagicMock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid', mock.MagicMock(return_value=0))
mock.Mock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid', mock.Mock(return_value=0))
def test_subprocess_nosudo_uid_0(self):
expected_command = 'ls -l'
p = process.SubProcess(cmd='ls -l')
self.assertEqual(p.cmd, expected_command)
@mock.patch.object(path, 'find_command',
mock.MagicMock(return_value=TRUE_CMD))
mock.Mock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid',
mock.MagicMock(return_value=1000))
mock.Mock(return_value=1000))
def test_subprocess_sudo(self):
expected_command = '%s -n ls -l' % TRUE_CMD
p = process.SubProcess(cmd='ls -l', sudo=True)
self.assertEqual(p.cmd, expected_command)
@mock.patch.object(path, 'find_command', mock_fail_find_cmd)
@mock.patch.object(os, 'getuid', mock.MagicMock(return_value=1000))
@mock.patch.object(os, 'getuid', mock.Mock(return_value=1000))
def test_subprocess_sudo_no_sudo_installed(self):
expected_command = 'ls -l'
p = process.SubProcess(cmd='ls -l', sudo=True)
self.assertEqual(p.cmd, expected_command)
@mock.patch.object(path, 'find_command',
mock.MagicMock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid', mock.MagicMock(return_value=0))
mock.Mock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid', mock.Mock(return_value=0))
def test_subprocess_sudo_uid_0(self):
expected_command = 'ls -l'
p = process.SubProcess(cmd='ls -l', sudo=True)
self.assertEqual(p.cmd, expected_command)
@mock.patch.object(path, 'find_command',
mock.MagicMock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid', mock.MagicMock(return_value=1000))
mock.Mock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid', mock.Mock(return_value=1000))
def test_subprocess_sudo_shell(self):
expected_command = '%s -n -s ls -l' % TRUE_CMD
p = process.SubProcess(cmd='ls -l', sudo=True, shell=True)
self.assertEqual(p.cmd, expected_command)
@mock.patch.object(path, 'find_command', mock_fail_find_cmd)
@mock.patch.object(os, 'getuid', mock.MagicMock(return_value=1000))
@mock.patch.object(os, 'getuid', mock.Mock(return_value=1000))
def test_subprocess_sudo_shell_no_sudo_installed(self):
expected_command = 'ls -l'
p = process.SubProcess(cmd='ls -l', sudo=True, shell=True)
self.assertEqual(p.cmd, expected_command)
@mock.patch.object(path, 'find_command',
mock.MagicMock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid', mock.MagicMock(return_value=0))
mock.Mock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid', mock.Mock(return_value=0))
def test_subprocess_sudo_shell_uid_0(self):
expected_command = 'ls -l'
p = process.SubProcess(cmd='ls -l', sudo=True, shell=True)
self.assertEqual(p.cmd, expected_command)
@mock.patch.object(path, 'find_command',
mock.MagicMock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid', mock.MagicMock(return_value=1000))
mock.Mock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid', mock.Mock(return_value=1000))
def test_run_nosudo(self):
expected_command = 'ls -l'
p = process.run(cmd='ls -l', ignore_status=True)
self.assertEqual(p.command, expected_command)
@mock.patch.object(path, 'find_command',
mock.MagicMock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid', mock.MagicMock(return_value=0))
mock.Mock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid', mock.Mock(return_value=0))
def test_run_nosudo_uid_0(self):
expected_command = 'ls -l'
p = process.run(cmd='ls -l', ignore_status=True)
self.assertEqual(p.command, expected_command)
@mock.patch.object(path, 'find_command',
mock.MagicMock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid', mock.MagicMock(return_value=1000))
mock.Mock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid', mock.Mock(return_value=1000))
def test_run_sudo(self):
expected_command = '%s -n ls -l' % TRUE_CMD
p = process.run(cmd='ls -l', sudo=True, ignore_status=True)
self.assertEqual(p.command, expected_command)
@mock.patch.object(path, 'find_command', mock_fail_find_cmd)
@mock.patch.object(os, 'getuid', mock.MagicMock(return_value=1000))
@mock.patch.object(os, 'getuid', mock.Mock(return_value=1000))
def test_run_sudo_no_sudo_installed(self):
expected_command = 'ls -l'
p = process.run(cmd='ls -l', sudo=True, ignore_status=True)
self.assertEqual(p.command, expected_command)
@mock.patch.object(path, 'find_command',
mock.MagicMock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid', mock.MagicMock(return_value=0))
mock.Mock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid', mock.Mock(return_value=0))
def test_run_sudo_uid_0(self):
expected_command = 'ls -l'
p = process.run(cmd='ls -l', sudo=True, ignore_status=True)
self.assertEqual(p.command, expected_command)
@mock.patch.object(path, 'find_command',
mock.MagicMock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid', mock.MagicMock(return_value=1000))
mock.Mock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid', mock.Mock(return_value=1000))
def test_run_sudo_shell(self):
expected_command = '%s -n -s ls -l' % TRUE_CMD
p = process.run(cmd='ls -l', sudo=True, shell=True, ignore_status=True)
self.assertEqual(p.command, expected_command)
@mock.patch.object(path, 'find_command', mock_fail_find_cmd)
@mock.patch.object(os, 'getuid', mock.MagicMock(return_value=1000))
@mock.patch.object(os, 'getuid', mock.Mock(return_value=1000))
def test_run_sudo_shell_no_sudo_installed(self):
expected_command = 'ls -l'
p = process.run(cmd='ls -l', sudo=True, shell=True, ignore_status=True)
self.assertEqual(p.command, expected_command)
@mock.patch.object(path, 'find_command',
mock.MagicMock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid', mock.MagicMock(return_value=0))
mock.Mock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid', mock.Mock(return_value=0))
def test_run_sudo_shell_uid_0(self):
expected_command = 'ls -l'
p = process.run(cmd='ls -l', sudo=True, shell=True, ignore_status=True)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册