diff options
Diffstat (limited to 'googletest/test/gtest_test_utils.py')
-rwxr-xr-x | googletest/test/gtest_test_utils.py | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/googletest/test/gtest_test_utils.py b/googletest/test/gtest_test_utils.py index 6fc39b5..964fa9f 100755 --- a/googletest/test/gtest_test_utils.py +++ b/googletest/test/gtest_test_utils.py @@ -68,8 +68,10 @@ TestCase = _test_module.TestCase # Initially maps a flag to its default value. After # _ParseAndStripGTestFlags() is called, maps a flag to its actual value. -_flag_map = {'source_dir': os.path.dirname(sys.argv[0]), - 'build_dir': os.path.dirname(sys.argv[0])} +_flag_map = { + 'source_dir': os.path.dirname(sys.argv[0]), + 'build_dir': os.path.dirname(sys.argv[0]), +} _gtest_flags_are_parsed = False @@ -91,7 +93,7 @@ def _ParseAndStripGTestFlags(argv): while i < len(argv): prefix = '--' + flag + '=' if argv[i].startswith(prefix): - _flag_map[flag] = argv[i][len(prefix):] + _flag_map[flag] = argv[i][len(prefix) :] del argv[i] break else: @@ -147,15 +149,16 @@ def GetTestExecutablePath(executable_name, build_dir=None): Args: executable_name: name of the test binary that the test script runs. - build_dir: directory where to look for executables, by default - the result of GetBuildDir(). + build_dir: directory where to look for executables, by default the + result of GetBuildDir(). Returns: The absolute path of the test binary. """ - path = os.path.abspath(os.path.join(build_dir or GetBuildDir(), - executable_name)) + path = os.path.abspath( + os.path.join(build_dir or GetBuildDir(), executable_name) + ) if (IS_WINDOWS or IS_CYGWIN or IS_OS2) and not path.endswith('.exe'): path += '.exe' @@ -163,7 +166,8 @@ def GetTestExecutablePath(executable_name, build_dir=None): message = ( 'Unable to find the test binary "%s". Please make sure to provide\n' 'a path to the binary via the --build_dir flag or the BUILD_DIR\n' - 'environment variable.' % path) + 'environment variable.' % path + ) print(message, file=sys.stderr) sys.exit(1) @@ -191,6 +195,7 @@ def GetExitStatus(exit_code): class Subprocess: + def __init__(self, command, working_dir=None, capture_stderr=True, env=None): """Changes into a specified directory, if provided, and executes a command. @@ -200,7 +205,7 @@ class Subprocess: command: The command to run, in the form of sys.argv. working_dir: The directory to change into. capture_stderr: Determines whether to capture stderr in the output member - or to discard it. + or to discard it. env: Dictionary with environment to pass to the subprocess. Returns: @@ -220,9 +225,14 @@ class Subprocess: else: stderr = subprocess.PIPE - p = subprocess.Popen(command, - stdout=subprocess.PIPE, stderr=stderr, - cwd=working_dir, universal_newlines=True, env=env) + 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] |