Add stdout and stderr to debug output for shell_command (#14465)
This commit is contained in:
1 parent
25dcddfeef
commit
1053473111
2 files changed
+51
-5
No files matched your search
@@ -148,3 +148,41 @@ class TestShellCommand(unittest.TestCase):
|
||||
self.assertEqual(1, mock_call.call_count)
|
||||
self.assertEqual(1, mock_error.call_count)
|
||||
self.assertFalse(os.path.isfile(path))
|
||||
|
||||
@patch('homeassistant.components.shell_command._LOGGER.debug')
|
||||
def test_stdout_captured(self, mock_output):
|
||||
"""Test subprocess that has stdout."""
|
||||
test_phrase = "I have output"
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, shell_command.DOMAIN, {
|
||||
shell_command.DOMAIN: {
|
||||
'test_service': "echo {}".format(test_phrase)
|
||||
}
|
||||
}))
|
||||
|
||||
self.hass.services.call('shell_command', 'test_service',
|
||||
blocking=True)
|
||||
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, mock_output.call_count)
|
||||
self.assertEqual(test_phrase.encode() + b'\n',
|
||||
mock_output.call_args_list[0][0][-1])
|
||||
|
||||
@patch('homeassistant.components.shell_command._LOGGER.debug')
|
||||
def test_stderr_captured(self, mock_output):
|
||||
"""Test subprocess that has stderr."""
|
||||
test_phrase = "I have error"
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, shell_command.DOMAIN, {
|
||||
shell_command.DOMAIN: {
|
||||
'test_service': ">&2 echo {}".format(test_phrase)
|
||||
}
|
||||
}))
|
||||
|
||||
self.hass.services.call('shell_command', 'test_service',
|
||||
blocking=True)
|
||||
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, mock_output.call_count)
|
||||
self.assertEqual(test_phrase.encode() + b'\n',
|
||||
mock_output.call_args_list[0][0][-1])
|
||||
Reference in new issue
Block a user