def test_cmd(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") if sys.platform.startswith("win"): cmd = "dir" else: cmd = "ls" out, err = run_cmd(cmd, shell=True, wait=True) assert len(out) > 0 out, err = run_cmd(cmd + " *.pyc", shell=True, wait=True) assert len(out) > 0
def test_run_cmd_1(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") cmd = "set" if sys.platform.startswith("win") else "env" fLOG("##########") out1, err = run_cmd(cmd, wait=True, fLOG=fLOG) fLOG("##########") out2, err = run_cmd(cmd, wait=True, communicate=False, fLOG=fLOG) fLOG("##########") self.maxDiff = None self.assertEqual(out1.strip(), out2.strip())
def test_cmd_communicate2(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") if sys.platform.startswith("win"): out, err = run_cmd("dir *.py", shell=True, wait=True, communicate=True) else: out, err = run_cmd("ls *.py", shell=True, wait=True, communicate=True) self.assertNotEmpty(out)
def test_run_cmd_exc(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") cmd = "unexpectedcommand" ex = "not affected" try: out, err = run_cmd(cmd, wait=True, log_error=False, catch_exit=True, communicate=False, tell_if_no_output=120, fLOG=fLOG) no_exception = True ex = None except Exception as e: no_exception = False out, err = parse_exception_message(e) ex = e self.assertTrue(not no_exception) if sys.platform.startswith("win"): if out is None or err is None: raise Exception("A\n" + str(ex)) if len(out) > 0: raise Exception("B\n" + str(ex)) if len(err) == 0: raise Exception("C\n" + str(ex)) else: self.assertTrue(out is None) self.assertTrue(err is None) self.assertTrue(isinstance(ex, Exception))
def test_run_cmd_more(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") cmd = "more " + os.path.abspath(__file__) try: run_cmd(cmd, wait=True, communicate=False, tell_if_no_output=600, fLOG=fLOG, sin="\n\n\n" * 100) except Exception: pass out, err = run_cmd(cmd, wait=True, communicate=True, fLOG=fLOG, sin="\n\n\n" * 100) assert len(out) > 10 assert len(err) == 0
def test_run_cmd_simple(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") if sys.platform.startswith("win"): cmd = "dir ." else: cmd = "ls ." out1, err = run_cmd(cmd, wait=True, fLOG=fLOG) out2, err = run_cmd(cmd, wait=True, communicate=False, fLOG=fLOG) fLOG("***", out1) fLOG("***", out2) out3, err = run_cmd(cmd, wait=True, communicate=True, fLOG=fLOG) fLOG("***", out3) out, err = skip_run_cmd(cmd, wait=True) assert len(out) == 0 assert len(err) == 0
def test_run_cmd_simple(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") if sys.platform.startswith("win"): cmd = "dir ." else: cmd = "ls ." out1, err = run_cmd(cmd, wait=True, fLOG=fLOG) out2, err = run_cmd(cmd, wait=True, communicate=False, fLOG=fLOG) fLOG("***", out1) fLOG("***", out2) out3, err = run_cmd( cmd, wait=True, communicate=True, fLOG=fLOG) fLOG("***", out3) out, err = skip_run_cmd(cmd, wait=True) assert len(out) == 0 assert len(err) == 0
def test_run_cmd_2(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") cmd = "set" if sys.platform.startswith("win") else "env" out3, err = run_cmd( cmd, wait=True, communicate=False, tell_if_no_output=600, fLOG=fLOG) fLOG("***", out3) out, err = skip_run_cmd(cmd, wait=True) assert len(out) == 0 assert len(err) == 0 counts = dict(out=[], err=[]) def stop_running_if(out, err, counts=counts): if out: counts["out"].append(out) if err: counts["err"].append(err) out4, err = run_cmd( cmd, wait=True, communicate=False, tell_if_no_output=600, stop_running_if=stop_running_if, fLOG=fLOG) fLOG("***", out3) out, err = skip_run_cmd(cmd, wait=True) assert len(out) == 0 assert len(err) == 0 self.maxDiff = None self.assertEqual(out3.strip(), out4.strip()) assert len(counts["out"]) > 0 if len(counts["err"]) > 0: raise Exception(counts["err"])
def test_run_cmd_timeout(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") if __name__ == "__main__": cmd = "more" out, err = run_cmd(cmd, wait=True, fLOG=fLOG, tell_if_no_output=1, communicate=False, timeout=3) fLOG(out) fLOG(err) assert "Process killed" in err