def check_output(*args, **kwargs): kwargs["stderr"] = subprocess.STDOUT try: output = costilius.sp_check_output(*args, **kwargs) except subprocess.CalledProcessError as e: LOG.error("Failed cmd: '%s'" % e.cmd) LOG.error("Error output: '%s'" % encodeutils.safe_decode(e.output)) raise LOG.debug("subprocess output: '%s'" % encodeutils.safe_decode(output)) return output
def check_output(*args, **kwargs): kwargs["stderr"] = subprocess.STDOUT try: output = costilius.sp_check_output(*args, **kwargs) except subprocess.CalledProcessError as e: LOG.debug("failed cmd: '%s'" % e.cmd) LOG.debug("error output: '%s'" % encodeutils.safe_decode(e.output)) raise LOG.debug("subprocess output: '%s'" % encodeutils.safe_decode(output)) return output
def test_simulation_of_any_not_py26_env(self, mock_is_py26, mock_subprocess): output = "output" mock_subprocess.check_output.return_value = output some_args = (1, 2) some_kwargs = {"a": 2} self.assertEqual(output, costilius.sp_check_output(*some_args, **some_kwargs)) mock_subprocess.check_output.assert_called_once_with(*some_args, **some_kwargs) self.assertFalse(mock_subprocess.Popen.called)
def test_simulation_of_any_not_py26_env(self, mock_is_py26, mock_sp): output = "output" mock_sp.check_output.return_value = output some_args = (1, 2) some_kwargs = {"a": 2} self.assertEqual(output, costilius.sp_check_output(*some_args, **some_kwargs)) mock_sp.check_output.assert_called_once_with(*some_args, **some_kwargs) self.assertFalse(mock_sp.Popen.called)
def test_simulation_of_py26_env(self, mock_is_py26, mock_subprocess): output = "output" process = mock.MagicMock() process.communicate.return_value = (output, "unused_err") process.poll.return_value = None mock_subprocess.Popen.return_value = process some_args = (1, 2) some_kwargs = {"a": 2} self.assertEqual(output, costilius.sp_check_output(*some_args, **some_kwargs)) mock_subprocess.Popen.assert_called_once_with(stdout=mock_subprocess.PIPE, *some_args, **some_kwargs) self.assertFalse(mock_subprocess.check_output.called)
def test_simulation_of_py26_env(self, mock_is_py26, mock_subprocess): output = "output" process = mock.MagicMock() process.communicate.return_value = (output, "unused_err") process.poll.return_value = None mock_subprocess.Popen.return_value = process some_args = (1, 2) some_kwargs = {"a": 2} self.assertEqual(output, costilius.sp_check_output(*some_args, **some_kwargs)) mock_subprocess.Popen.assert_called_once_with( stdout=mock_subprocess.PIPE, *some_args, **some_kwargs) self.assertFalse(mock_subprocess.check_output.called)