def test_acceptable_output(self): out = CommandOutputPipeBase(False, ["unacceptable"]) commander = Commander(out) try: commander.run_command(["echo", "some", "highly", "acceptable", "message"]) except: self.fail("run_command shouldn't have thrown an exception")
def test_run_cmd(sleep_cmd): out = ProgressOutputPipe() commander = Commander(out) commander.run_command( ["sh", "-c", "for x in {1..10}; do echo $x; %s done" % sleep_cmd]) for i in range(1, 10): assert i == int(out.stdout[i - 1])
def test_silent_output_no_out(self): saved_stdout = sys.stdout try: out = StringIO() sys.stdout = out commander = Commander(None) commander.run_command(["echo", "Hello", "World!"]) output = out.getvalue().strip() assert output == '' finally: sys.stdout = saved_stdout
def test_silent_output_nonverbose_out(self): saved_stdout = sys.stdout try: out = StringIO() sys.stdout = out pipe = CommandOutputPipeBase(False) commander = Commander(pipe) commander.run_command(["echo", "Hello", "World!"]) output = out.getvalue().strip() assert output == '' finally: sys.stdout = saved_stdout
def test_return_code(self): commander = Commander() assert commander.run_command(["echo", "Hello World!"]) == 0 assert commander.run_command(["ls", "eaeuohtnuoeahtnouahtn"]) == 1
def test_get_lines(self): out = CommandOutputPipeBase(False) commander = Commander(out) commander.run_command(["echo", "Hello\nWorld"]) assert out.stdout[0] == "Hello\n" and out.stdout[1] == "World\n"