def testTimeoutingSubSubProcesses(self): cmd = command.Command('echo "sleep 3;exit 5"|bash', 0.1, 1000) # There should be a timeout self.failUnlessRaises(command.SoftTimeoutException, cmd.execute_in_shell) # If command is killed properly it should not return 5: self.assertNotEquals(cmd.return_value, 5) # If sub process was killed properly, execution time should be much # less than 3 seconds. self.assert_(cmd.execution_time < 2.5)
def testHardTimeout(self): cmd = command.Command("sleep 5", 100, 0.5) self.failUnlessRaises(command.HardTimeoutException, cmd.execute_in_shell)
def testGetExecutionTime(self): cmd = command.Command("sleep 0.5") cmd.execute_in_shell() self.assertAlmostEquals(cmd.execution_time, 0.5, 1)
def testGetReturnValue(self): cmd = command.Command("echo 0", DUMMY_TIMEOUT_VALUE) self.assertEquals(cmd.return_value, None) cmd.execute_in_shell() self.assertEquals(cmd.return_value, 0)
def testGetStdout(self): cmd = command.Command("echo jee", DUMMY_TIMEOUT_VALUE) cmd.execute_in_shell() self._assertStdout(cmd, "jee\n")
def testGetStderr(self): cmd = command.Command("echo jee >&2", DUMMY_TIMEOUT_VALUE) cmd.execute_in_shell() self.assertEquals(cmd.stderr, "jee\n")
def testWrappedCommandWithEmptyWrapper(self): wrapper = "" cmd = "command" cmd_object = command.Command(cmd, wrapper=wrapper) expected = 'command' self.assertEquals(cmd_object.command, expected)
def testAlreadyExecuted(self): cmd = command.Command("", DUMMY_TIMEOUT_VALUE) self.assertFalse(cmd.already_executed()) cmd.execute_in_shell() self.assertTrue(cmd.already_executed())
def test_str(self): cmd_object = command.Command("echo x") self.assertTrue(str(cmd_object))
def testWrappedCommand(self): wrapper = 'wrapper "%s"' cmd = "command" cmd_object = command.Command(cmd, wrapper=wrapper) expected = 'wrapper "command"' self.assertEquals(cmd_object.command, expected)
def testThisIsParentOfCommandWhenWithoutShell(self): cmd = command.Command("ps -o ppid= -C ps", DUMMY_TIMEOUT_VALUE) cmd.execute() self._assertStdout(cmd, "%s\n" % os.getpid())
def testThisIsParentOfShellWithExecuteInShell(self): cmd = command.Command("echo $PPID", DUMMY_TIMEOUT_VALUE) cmd.execute_in_shell() self._assertStdout(cmd, "%s\n" % os.getpid())
def testExecuteWithRetriesSuccessfulCommand(self): cmd = command.Command("echo jee") self.assertAlmostEquals(cmd.execute_with_retries(5, 0), 1)
def testExecuteWithRetriesTimeoutingCommand(self): cmd = command.Command("sleep 5", 0.2) self.failUnlessRaises(command.FailedAfterRetries, cmd.execute_with_retries, 5, 5)
def testExecuteWithRetriesFailingCommand(self): cmd = command.Command("echo jee") self.failUnlessRaises(command.FailedAfterRetries, cmd.execute_with_retries, 5, 5)