def test_10_do_task__w_permission_denied_error(self): if os.getuid() == 0: print("Skip this test because you're root.") return # It seems that neighther 'subprocess.Popen("true", # cwd="/root").wait()' nor 'subprocess.Popen("cd /root && true", # shell=True).wait()' does not raise any exceptions these days: # task = SH.Task("true", workdir="/root", timeout=10) # task = SH.Task("cd /root && true", workdir="/root", timeout=10) task = SH.Task("touch /root/.bashrc", timeout=10) with self.assertRaises(SH.TaskError): SH.do_task(task, stop_on_error=True)
def test_20_do_task__ignore_permission_denied_error(self): if os.getuid() == 0: print("Skip this test because you're root.") return task = SH.Task("touch /root/.bashrc", workdir="/root", timeout=10) self.assertNotEquals(SH.do_task(task, stop_on_error=False), 0)
def test_31_do_task__timeout__w_rc(self): task = SH.Task("sleep 10", timeout=1) self.assertNotEquals(SH.do_task(task, stop_on_error=False), 0)
def test_30_do_task__timeout(self): task = SH.Task("sleep 10", timeout=1) with self.assertRaises(SH.TaskError): SH.do_task(task)
def test_02_do_task__no_errors_but_not_return_0(self): task = SH.Task("false", timeout=10) self.assertNotEquals(SH.do_task(task, stop_on_error=False), 0)
def test_01_do_task__no_errors_but_not_return_0_and_exception_raised(self): task = SH.Task("false", timeout=10) with self.assertRaises(SH.TaskError): SH.do_task(task)
def test_00_do_task__no_errors(self): task = SH.Task("true", timeout=10) self.assertEquals(SH.do_task(task), 0)