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

selftests/unit/test_utils_process.py: remove decorators to skip tests

On the basis of the non-existence of the "true" command on the system
running tests.  Most of the tests do not even reference the "true"
command, and those that do, do not require the binary to exist, but
only a valid command line to be given.

In that aspect, a fictional command is used where needed.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 63f9ea12
......@@ -25,15 +25,15 @@ def probe_binary(binary):
return None
TRUE_CMD = probe_binary('true')
ECHO_CMD = probe_binary('echo')
FICTIONAL_CMD = '/usr/bin/fictional_cmd'
class TestSubProcess(unittest.TestCase):
def test_allow_output_check_parameter(self):
self.assertRaises(ValueError, process.SubProcess,
TRUE_CMD, False, "invalid")
FICTIONAL_CMD, False, "invalid")
class TestGDBProcess(unittest.TestCase):
......@@ -67,11 +67,9 @@ class TestGDBProcess(unittest.TestCase):
self.assertFalse(process.should_run_inside_gdb("foo bar baz"))
self.assertFalse(process.should_run_inside_gdb("foo ' "))
@unittest.skipUnless(TRUE_CMD,
'"true" binary not available')
def test_get_sub_process_klass(self):
gdb.GDB_RUN_BINARY_NAMES_EXPR = []
self.assertIs(process.get_sub_process_klass(TRUE_CMD),
self.assertIs(process.get_sub_process_klass(FICTIONAL_CMD),
process.SubProcess)
gdb.GDB_RUN_BINARY_NAMES_EXPR.append('/bin/false')
......@@ -79,7 +77,7 @@ class TestGDBProcess(unittest.TestCase):
process.GDBSubProcess)
self.assertIs(process.get_sub_process_klass('false'),
process.GDBSubProcess)
self.assertIs(process.get_sub_process_klass('true'),
self.assertIs(process.get_sub_process_klass(FICTIONAL_CMD),
process.SubProcess)
def test_split_gdb_expr(self):
......@@ -104,10 +102,6 @@ def mock_fail_find_cmd(cmd, default=None):
class TestProcessRun(unittest.TestCase):
@unittest.skipUnless(TRUE_CMD,
'"true" binary not available')
@mock.patch.object(path, 'find_command',
mock.Mock(return_value=TRUE_CMD))
@mock.patch.object(os, 'getuid',
mock.Mock(return_value=1000))
def test_subprocess_nosudo(self):
......@@ -115,10 +109,6 @@ class TestProcessRun(unittest.TestCase):
p = process.SubProcess(cmd='ls -l')
self.assertEqual(p.cmd, expected_command)
@unittest.skipUnless(TRUE_CMD,
'"true" binary not available')
@mock.patch.object(path, 'find_command',
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'
......@@ -142,10 +132,6 @@ class TestProcessRun(unittest.TestCase):
p = process.SubProcess(cmd='ls -l', sudo=True)
self.assertEqual(p.cmd, expected_command)
@unittest.skipUnless(TRUE_CMD,
'"true" binary not available')
@mock.patch.object(path, 'find_command',
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'
......@@ -168,30 +154,18 @@ class TestProcessRun(unittest.TestCase):
p = process.SubProcess(cmd='ls -l', sudo=True, shell=True)
self.assertEqual(p.cmd, expected_command)
@unittest.skipUnless(TRUE_CMD,
'"true" binary not available')
@mock.patch.object(path, 'find_command',
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)
@unittest.skipUnless(TRUE_CMD,
'"true" binary not available')
@mock.patch.object(path, 'find_command',
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)
@unittest.skipUnless(TRUE_CMD,
'"true" binary not available')
@mock.patch.object(path, 'find_command',
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'
......@@ -214,10 +188,6 @@ class TestProcessRun(unittest.TestCase):
p = process.run(cmd='ls -l', sudo=True, ignore_status=True)
self.assertEqual(p.command, expected_command)
@unittest.skipUnless(TRUE_CMD,
'"true" binary not available')
@mock.patch.object(path, 'find_command',
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'
......@@ -240,10 +210,6 @@ class TestProcessRun(unittest.TestCase):
p = process.run(cmd='ls -l', sudo=True, shell=True, ignore_status=True)
self.assertEqual(p.command, expected_command)
@unittest.skipUnless(TRUE_CMD,
'"true" binary not available')
@mock.patch.object(path, 'find_command',
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'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册