Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/google/googletest.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordmauro <dmauro@google.com>2021-10-27 23:28:25 +0300
committerCJ Johnson <johnsoncj@google.com>2021-11-03 20:45:56 +0300
commit5a93ce124714287ab78c92da6db986be7fdb791c (patch)
tree0e58b684d6526c7d85f285a36568c50b5290c80c
parent7cf37a18d18a5bb7dc07e5e8382e622fe5c89321 (diff)
Googletest export
Remove the subprocess fallback code for older versions of Python PiperOrigin-RevId: 405967578
-rwxr-xr-xgoogletest/test/gtest_test_utils.py81
1 files changed, 12 insertions, 69 deletions
diff --git a/googletest/test/gtest_test_utils.py b/googletest/test/gtest_test_utils.py
index 13fc6f59..eecc5334 100755
--- a/googletest/test/gtest_test_utils.py
+++ b/googletest/test/gtest_test_utils.py
@@ -32,6 +32,7 @@
# pylint: disable-msg=C6204
import os
+import subprocess
import sys
IS_WINDOWS = os.name == 'nt'
@@ -42,13 +43,6 @@ import atexit
import shutil
import tempfile
import unittest as _test_module
-
-try:
- import subprocess
- _SUBPROCESS_MODULE_AVAILABLE = True
-except:
- import popen2
- _SUBPROCESS_MODULE_AVAILABLE = False
# pylint: enable-msg=C6204
GTEST_OUTPUT_VAR_NAME = 'GTEST_OUTPUT'
@@ -224,69 +218,18 @@ class Subprocess:
combined in a string.
"""
- # The subprocess module is the preferable way of running programs
- # since it is available and behaves consistently on all platforms,
- # including Windows. But it is only available starting in python 2.4.
- # In earlier python versions, we revert to the popen2 module, which is
- # available in python 2.0 and later but doesn't provide required
- # functionality (Popen4) under Windows. This allows us to support Mac
- # OS X 10.4 Tiger, which has python 2.3 installed.
- if _SUBPROCESS_MODULE_AVAILABLE:
- if capture_stderr:
- stderr = subprocess.STDOUT
- else:
- stderr = subprocess.PIPE
-
- p = subprocess.Popen(command,
- stdout=subprocess.PIPE, stderr=stderr,
- cwd=working_dir, universal_newlines=True, env=env)
- # communicate returns a tuple with the file object for the child's
- # output.
- self.output = p.communicate()[0]
- self._return_code = p.returncode
+ if capture_stderr:
+ stderr = subprocess.STDOUT
else:
- old_dir = os.getcwd()
-
- def _ReplaceEnvDict(dest, src):
- # Changes made by os.environ.clear are not inheritable by child
- # processes until Python 2.6. To produce inheritable changes we have
- # to delete environment items with the del statement.
- for key in dest.keys():
- del dest[key]
- dest.update(src)
-
- # When 'env' is not None, backup the environment variables and replace
- # them with the passed 'env'. When 'env' is None, we simply use the
- # current 'os.environ' for compatibility with the subprocess.Popen
- # semantics used above.
- if env is not None:
- old_environ = os.environ.copy()
- _ReplaceEnvDict(os.environ, env)
-
- try:
- if working_dir is not None:
- os.chdir(working_dir)
- if capture_stderr:
- p = popen2.Popen4(command)
- else:
- p = popen2.Popen3(command)
- p.tochild.close()
- self.output = p.fromchild.read()
- ret_code = p.wait()
- finally:
- os.chdir(old_dir)
-
- # Restore the old environment variables
- # if they were replaced.
- if env is not None:
- _ReplaceEnvDict(os.environ, old_environ)
-
- # Converts ret_code to match the semantics of
- # subprocess.Popen.returncode.
- if os.WIFSIGNALED(ret_code):
- self._return_code = -os.WTERMSIG(ret_code)
- else: # os.WIFEXITED(ret_code) should return True here.
- self._return_code = os.WEXITSTATUS(ret_code)
+ stderr = subprocess.PIPE
+
+ p = subprocess.Popen(command,
+ stdout=subprocess.PIPE, stderr=stderr,
+ cwd=working_dir, universal_newlines=True, env=env)
+ # communicate returns a tuple with the file object for the child's
+ # output.
+ self.output = p.communicate()[0]
+ self._return_code = p.returncode
if bool(self._return_code & 0x80000000):
self.terminated_by_signal = True