3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
19 from rpmbuilder.executor import Executor
22 @pytest.mark.parametrize('input_cmd, expected_output', [
24 (['echo', 'foo'], 'foo\n'),
26 def test_run_cmd(input_cmd, expected_output):
27 assert Executor().run(input_cmd) == expected_output
30 @mock.patch('logging.Logger.debug')
31 @mock.patch('subprocess.Popen')
32 def test_stderr_is_logged(mock_popen, mock_log):
33 process_mock = mock.Mock()
34 process_mock.configure_mock(**{
35 'communicate.return_value': ('some ouput', 'some errput'),
38 mock_popen.return_value = process_mock
39 Executor().run(['ls'])
40 assert re.match('.*exit status 0 but stderr not empty.*', mock_log.call_args[0][0])
43 def test_run_cmd_fail():
44 err_regexp = 'Command .* returned non-zero exit status 2: stdout="", ' \
45 'stderr="ls: .* No such file or directory'
46 with pytest.raises(Exception,
48 Executor().run(['ls', 'bar'])