From ea54e40726fb55cd819a95e2edac80e6b9da13b4 Mon Sep 17 00:00:00 2001 From: Cleber Rosa Date: Wed, 11 Apr 2018 17:08:06 -0400 Subject: [PATCH] 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: Cleber Rosa --- selftests/unit/test_utils_process.py | 42 +++------------------------- 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/selftests/unit/test_utils_process.py b/selftests/unit/test_utils_process.py index 41df6a76..c84a2d7d 100644 --- a/selftests/unit/test_utils_process.py +++ b/selftests/unit/test_utils_process.py @@ -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' -- GitLab