@@ -25,13 +25,16 @@ def test_run_command_failed(self):
2525 """ Test run_command() with basic failed command. """
2626 proc = run_command (["/bin/false" ])
2727 self .assertEqual (proc .returncode , 1 )
28+ self .assertIsNone (proc .out )
29+ self .assertIsNone (proc .err )
2830
2931 @patch ('sys.stdout' , new_callable = StringIO )
3032 def test_run_command_capture_stdout (self , mock_stdout ):
3133 """ Test run_command() with captured standard output. """
3234 proc = run_command (["/bin/echo" , "output_data" ], capture_output = True )
3335 # Standard output must be available in out attribute of RunResult named
3436 # tuple.
37+ self .assertEqual (proc .returncode , 0 )
3538 self .assertEqual (proc .out , "output_data\n " )
3639 self .assertEqual (proc .err , "" )
3740 # Standard output must also be streamed into current process stdout.
@@ -43,26 +46,42 @@ def test_run_command_capture_stderr(self, mock_stderr):
4346 proc = run_command ("/bin/echo error_data 1>&2" , capture_output = True , shell = True )
4447 # Standard err must be available in err attribute of RunResult named
4548 # tuple.
49+ self .assertEqual (proc .returncode , 0 )
4650 self .assertEqual (proc .out , "" )
4751 self .assertEqual (proc .err , "error_data\n " )
4852 # Standard error must also be streamed into current process stderr.
4953 self .assertEqual (mock_stderr .getvalue (), "error_data\n " )
5054
5155 @patch ('sys.stderr' , new_callable = StringIO )
52- def test_run_command_capture_merged (self , mock_stderr ):
53- """ Test run_command() with merged output capture. """
54- proc = run_command ("/bin/echo error_data 1>&2" , capture_output = True , merged_capture = True , shell = True )
56+ def test_run_command_capture_stderr_merged (self , mock_stderr ):
57+ """ Test run_command() with merged error output capture. """
58+ proc = run_command ("/bin/echo error_data 1>&2" , capture_output = True ,
59+ merge_out_err = True , shell = True )
5560 # With merged_capture, standard err must be available in out attribute
5661 # of RunResult named tuple, and err attribute must be None.
5762 self .assertEqual (proc .out , "error_data\n " )
5863 self .assertIsNone (proc .err )
5964 # Standard error must also be streamed into current process stderr.
6065 self .assertEqual (mock_stderr .getvalue (), "error_data\n " )
6166
67+ @patch ('sys.stderr' , new_callable = StringIO )
68+ def test_run_command_capture_both_merged (self , mock_stderr ):
69+ """ Test run_command() with merged error and standard output capture. """
70+ proc = run_command ("/bin/echo error_data 1>&2 && /bin/echo output_data" ,
71+ capture_output = True , merge_out_err = True , shell = True )
72+ # With merge_out_err, standard err must be available in out attribute
73+ # of RunResult named tuple, and err attribute must be None.
74+ self .assertEqual (proc .out , "error_data\n output_data\n " )
75+ self .assertIsNone (proc .err )
76+ # Standard error must also be streamed into current process stderr.
77+ self .assertEqual (mock_stderr .getvalue (), "error_data\n " )
78+
79+ @patch ('sys.stderr' , new_callable = StringIO )
6280 @patch ('sys.stdout' , new_callable = StringIO )
63- def test_run_command_no_output (self , mock_stdout ):
81+ def test_run_command_no_output (self , mock_stdout , mock_stderr ):
6482 """ Test run_command() without live output. """
65- # With live_output disabled, standard output must not be streamed into
66- # current process stdout.
83+ # With live_output disabled, standard output and standard error must not
84+ # be redirected in current process stdout.
6785 proc = run_command (["/bin/echo" , "output_data" ], live_output = False )
6886 self .assertEqual (mock_stdout .getvalue (), "" )
87+ self .assertEqual (mock_stderr .getvalue (), "" )
0 commit comments