From dac422f5d3d7681f914680a0606bf46b95f5a68f Mon Sep 17 00:00:00 2001 From: Mirko Bonadei Date: Tue, 5 Jun 2018 09:12:34 +0200 Subject: [PATCH] Fixing gtest_parallel_wrapper_test on Windows. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using tempfile is probably overkill in this case, but it is good to have a meaningful path printed out in case of error (instead of something like "/tmp" and then a Windows path). Bug: None Change-Id: I90b939d7b2a082f4c04f995b602942efe1e671bc Reviewed-on: https://webrtc-review.googlesource.com/81180 Reviewed-by: Patrik Höglund Commit-Queue: Mirko Bonadei Cr-Commit-Position: refs/heads/master@{#23516} --- tools_webrtc/gtest_parallel_wrapper_test.py | 61 +++++++++++++-------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/tools_webrtc/gtest_parallel_wrapper_test.py b/tools_webrtc/gtest_parallel_wrapper_test.py index 486ec09ddc..e731d92243 100755 --- a/tools_webrtc/gtest_parallel_wrapper_test.py +++ b/tools_webrtc/gtest_parallel_wrapper_test.py @@ -8,11 +8,22 @@ # in the file PATENTS. All contributing project authors may # be found in the AUTHORS file in the root of the source tree. +from contextlib import contextmanager + +import os +import tempfile import unittest script = __import__('gtest-parallel-wrapper') # pylint: disable=invalid-name +@contextmanager +def TemporaryDirectory(): + tmp_dir = tempfile.mkdtemp() + yield tmp_dir + os.rmdir(tmp_dir) + + class GtestParallelWrapperTest(unittest.TestCase): @classmethod def _Expected(cls, gtest_parallel_args): @@ -50,14 +61,17 @@ class GtestParallelWrapperTest(unittest.TestCase): self.assertEqual(result.gtest_parallel_args, expected) def testArtifacts(self): - result = script.ParseArgs(['exec', '--store-test-artifacts', - '--output_dir', '/tmp/foo']) - expected = self._Expected(['--output_dir=/tmp/foo', 'exec', '--', - '--test_artifacts_dir=/tmp/foo/test_artifacts']) - self.assertEqual(result.gtest_parallel_args, expected) - self.assertEqual(result.output_dir, '/tmp/foo') - self.assertRegexpMatches(result.test_artifacts_dir, - '/tmp/foo.test_artifacts') + with TemporaryDirectory() as tmp_dir: + output_dir = os.path.join(tmp_dir, 'foo') + result = script.ParseArgs(['exec', '--store-test-artifacts', + '--output_dir', output_dir]) + exp_artifacts_dir = os.path.join(output_dir, 'test_artifacts') + exp = self._Expected(['--output_dir=' + output_dir, 'exec', '--', + '--test_artifacts_dir=' + exp_artifacts_dir]) + self.assertEqual(result.gtest_parallel_args, exp) + self.assertEqual(result.output_dir, output_dir) + self.assertRegexpMatches(result.test_artifacts_dir, + output_dir + '.test_artifacts') def testNoDirsSpecified(self): result = script.ParseArgs(['exec']) @@ -92,20 +106,23 @@ class GtestParallelWrapperTest(unittest.TestCase): self.assertEqual(result.gtest_parallel_args, expected) def testDocExample(self): - result = script.ParseArgs([ - 'some_test', '--some_flag=some_value', '--another_flag', - '--output_dir=SOME_OUTPUT_DIR', '--store-test-artifacts', - '--isolated-script-test-output=SOME_DIR', - '--isolated-script-test-perf-output=SOME_OTHER_DIR', - '--foo=bar', '--baz']) - expected = self._Expected([ - '--output_dir=SOME_OUTPUT_DIR', '--dump_json_test_results=SOME_DIR', - 'some_test', '--', - '--test_artifacts_dir=SOME_OUTPUT_DIR/test_artifacts', - '--some_flag=some_value', '--another_flag', - '--isolated-script-test-perf-output=SOME_OTHER_DIR', - '--foo=bar', '--baz']) - self.assertEqual(result.gtest_parallel_args, expected) + with TemporaryDirectory() as tmp_dir: + output_dir = os.path.join(tmp_dir, 'foo') + result = script.ParseArgs([ + 'some_test', '--some_flag=some_value', '--another_flag', + '--output_dir=' + output_dir, '--store-test-artifacts', + '--isolated-script-test-output=SOME_DIR', + '--isolated-script-test-perf-output=SOME_OTHER_DIR', + '--foo=bar', '--baz']) + expected_artifacts_dir = os.path.join(output_dir, 'test_artifacts') + expected = self._Expected([ + '--output_dir=' + output_dir, '--dump_json_test_results=SOME_DIR', + 'some_test', '--', + '--test_artifacts_dir=' + expected_artifacts_dir, + '--some_flag=some_value', '--another_flag', + '--isolated-script-test-perf-output=SOME_OTHER_DIR', + '--foo=bar', '--baz']) + self.assertEqual(result.gtest_parallel_args, expected) if __name__ == '__main__':