# Path: gslib/exception.py
# NO_URLS_MATCHED_PREFIX = 'No URLs matched'
# NO_URLS_MATCHED_GENERIC = (NO_URLS_MATCHED_PREFIX +
#                            '. Do the files you\'re operating on exist?')
# NO_URLS_MATCHED_TARGET = NO_URLS_MATCHED_PREFIX + ': %s'
# class AbortException(StandardError):
# class CommandException(StandardError):
# class ControlCException(Exception):
# class GcloudStorageTranslationError(Exception):
# class HashMismatchException(Exception):
# class IamChOnResourceWithConditionsException(Exception):
# class InvalidUrlError(Exception):
# class ExternalBinaryError(Exception):
#   def __init__(self, reason):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, reason, informational=False):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
# 
# Path: gslib/utils/execution_util.py
# def ExecuteExternalCommand(command_and_flags):


import subprocess
from unittest import mock
from gslib import exception
from gslib.tests import testcase
from gslib.utils import execution_util
    self.assertEqual(stdout, 'a')
    self.assertEqual(stderr, 'b')

    mock_Popen.assert_called_once_with(['fake-command'],
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE)

  @mock.patch.object(subprocess, 'Popen')
  def testExternalCommandReturnsBytesOutput(self, mock_Popen):
    mock_command_process = mock.Mock()
    mock_command_process.returncode = 0
    mock_command_process.communicate.return_value = (b'a', b'b')
    mock_Popen.return_value = mock_command_process

    stdout, stderr = execution_util.ExecuteExternalCommand(['fake-command'])
    self.assertEqual(stdout, 'a')
    self.assertEqual(stderr, 'b')

    mock_Popen.assert_called_once_with(['fake-command'],
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE)

  @mock.patch.object(subprocess, 'Popen')
  def testExternalCommandReturnsNoOutput(self, mock_Popen):
    mock_command_process = mock.Mock()
    mock_command_process.returncode = 1
    mock_command_process.communicate.return_value = (None, b'error')
    mock_Popen.return_value = mock_command_process

    with self.assertRaises(exception.ExternalBinaryError):

# Path: gslib/exception.py
# NO_URLS_MATCHED_PREFIX = 'No URLs matched'
# NO_URLS_MATCHED_GENERIC = (NO_URLS_MATCHED_PREFIX +
#                            '. Do the files you\'re operating on exist?')
# NO_URLS_MATCHED_TARGET = NO_URLS_MATCHED_PREFIX + ': %s'
# class AbortException(StandardError):
# class CommandException(StandardError):
# class ControlCException(Exception):
# class GcloudStorageTranslationError(Exception):
# class HashMismatchException(Exception):
# class IamChOnResourceWithConditionsException(Exception):
# class InvalidUrlError(Exception):
# class ExternalBinaryError(Exception):
#   def __init__(self, reason):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, reason, informational=False):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
# 
# Path: gslib/utils/execution_util.py
# def ExecuteExternalCommand(command_and_flags):


# Path: gslib/tests/test_execution_util.py
import subprocess
from unittest import mock
from gslib import exception
from gslib.tests import testcase
from gslib.utils import execution_util

    self.assertEqual(stdout, 'a')
    self.assertEqual(stderr, 'b')

    mock_Popen.assert_called_once_with(['fake-command'],
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE)

  @mock.patch.object(subprocess, 'Popen')
  def testExternalCommandReturnsBytesOutput(self, mock_Popen):
    mock_command_process = mock.Mock()
    mock_command_process.returncode = 0
    mock_command_process.communicate.return_value = (b'a', b'b')
    mock_Popen.return_value = mock_command_process

    stdout, stderr = execution_util.ExecuteExternalCommand(['fake-command'])
    self.assertEqual(stdout, 'a')
    self.assertEqual(stderr, 'b')

    mock_Popen.assert_called_once_with(['fake-command'],
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE)

  @mock.patch.object(subprocess, 'Popen')
  def testExternalCommandReturnsNoOutput(self, mock_Popen):
    mock_command_process = mock.Mock()
    mock_command_process.returncode = 1
    mock_command_process.communicate.return_value = (None, b'error')
    mock_Popen.return_value = mock_command_process

    with self.assertRaises(exception.ExternalBinaryError):

      execution_util.ExecuteExternalCommand(['fake-command'])