예제 #1
0
  def test_method_forwarding_windows(self, *unused_mocks):
    # Test that the correct calls are being forwarded to the subprocess module
    # and that the shell=True flag is added when we are on Windows.
    processes.force_shell = True

    processes.call(['subprocess', 'call'], shell=False, other_arg=True)
    processes.subprocess.call.assert_called_once_with(
        ['subprocess', 'call'],
        shell=True,
        other_arg=True)

    processes.check_call(
        ['subprocess', 'check_call'],
        shell=False,
        other_arg=True)
    processes.subprocess.check_call.assert_called_once_with(
        ['subprocess', 'check_call'],
        shell=True,
        other_arg=True)

    processes.check_output(
        ['subprocess', 'check_output'],
        shell=False,
        other_arg=True)
    processes.subprocess.check_output.assert_called_once_with(
        ['subprocess', 'check_output'],
        shell=True,
        other_arg=True)

    processes.Popen(['subprocess', 'Popen'], shell=False, other_arg=True)
    processes.subprocess.Popen.assert_called_once_with(
        ['subprocess', 'Popen'],
        shell=True,
        other_arg=True)
예제 #2
0
  def test_method_forwarding_windows(self, *unused_mocks):
    # Test that the correct calls are being forwarded to the subprocess module
    # and that the shell=True flag is added when we are on Windows.
    processes.force_shell = True

    processes.call(['subprocess', 'call'], shell=False, other_arg=True)
    processes.subprocess.call.assert_called_once_with(['subprocess', 'call'],
                                                      shell=True,
                                                      other_arg=True)

    processes.check_call(['subprocess', 'check_call'],
                         shell=False,
                         other_arg=True)
    processes.subprocess.check_call.assert_called_once_with(
        ['subprocess', 'check_call'], shell=True, other_arg=True)

    processes.check_output(['subprocess', 'check_output'],
                           shell=False,
                           other_arg=True)
    processes.subprocess.check_output.assert_called_once_with(
        ['subprocess', 'check_output'], shell=True, other_arg=True)

    processes.Popen(['subprocess', 'Popen'], shell=False, other_arg=True)
    processes.subprocess.Popen.assert_called_once_with(['subprocess', 'Popen'],
                                                       shell=True,
                                                       other_arg=True)
예제 #3
0
 def test_oserror_check_output_message(self):
     self.mock_get.side_effect = OSError()
     cmd = ["lls"]
     try:
         processes.call(cmd)
     except RuntimeError as error:
         self.assertIn('Executable {} not found'.format(str(cmd)),\
         error.args[0])
예제 #4
0
 def test_oserror_check_output_message(self):
   self.mock_get.side_effect = OSError()
   cmd = ["lls"]
   try:
     processes.call(cmd)
   except RuntimeError as error:
     self.assertIn('Executable {} not found'.format(str(cmd)),\
     error.args[0])
예제 #5
0
 def test_check_output_pip_install_non_existing_package(self):
     returncode = 1
     package = "non-exsisting-package"
     cmd = ['python', '-m', 'pip', 'download', '--dest', '/var',\
       '{}'.format(package),\
       '--no-deps', '--no-binary', ':all:']
     output = "Collecting {}".format(package)
     self.mock_get.side_effect = subprocess.CalledProcessError(returncode,\
          cmd, output=output)
     try:
         output = processes.call(cmd)
         self.fail("The test failed due to that\
     no error was raised when calling process.check_call")
     except RuntimeError as error:
         self.assertIn("Output from execution of subprocess: {}".format(output),\
           error.args[0])
         self.assertIn("Pip install failed for package: {}".format(package),\
           error.args[0])
예제 #6
0
 def test_check_output_pip_install_non_existing_package(self):
   returncode = 1
   package = "non-exsisting-package"
   cmd = ['python', '-m', 'pip', 'download', '--dest', '/var',\
     '{}'.format(package),\
     '--no-deps', '--no-binary', ':all:']
   output = "Collecting {}".format(package)
   self.mock_get.side_effect = subprocess.CalledProcessError(returncode,\
        cmd, output=output)
   try:
     output = processes.call(cmd)
     self.fail("The test failed due to that\
       no error was raised when calling process.check_call")
   except RuntimeError as error:
     self.assertIn("Output from execution of subprocess: {}".format(output),\
       error.args[0])
     self.assertIn("Pip install failed for package: {}".format(package),\
       error.args[0])