コード例 #1
0
 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")
コード例 #2
0
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])
コード例 #3
0
 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
コード例 #4
0
 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
コード例 #5
0
 def test_return_code(self):
   commander = Commander()
   assert commander.run_command(["echo", "Hello World!"]) == 0
   assert commander.run_command(["ls", "eaeuohtnuoeahtnouahtn"]) == 1
コード例 #6
0
 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"