Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: googletest/tests/trace_test_cases_smoke_test.py

Issue 24813003: Move file path functions into utils/file_path.py. (Closed) Base URL: https://chromium.googlesource.com/a/chromium/tools/swarm_client@master
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | isolate.py » ('j') | utils/file_path.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import json 6 import json
7 import logging 7 import logging
8 import os 8 import os
9 import re 9 import re
10 import subprocess 10 import subprocess
11 import sys 11 import sys
12 import tempfile 12 import tempfile
13 import unittest 13 import unittest
14 14
15 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) 15 BASE_DIR = os.path.dirname(os.path.abspath(__file__))
16 GOOGLETEST_DIR = os.path.dirname(BASE_DIR) 16 GOOGLETEST_DIR = os.path.dirname(BASE_DIR)
17 ROOT_DIR = os.path.dirname(GOOGLETEST_DIR) 17 ROOT_DIR = os.path.dirname(GOOGLETEST_DIR)
18 sys.path.insert(0, ROOT_DIR) 18 sys.path.insert(0, ROOT_DIR)
19 sys.path.insert(0, os.path.join(BASE_DIR, 'gtest_fake')) 19 sys.path.insert(0, os.path.join(BASE_DIR, 'gtest_fake'))
20 20
21 import trace_inputs
22 import gtest_fake_base 21 import gtest_fake_base
22 from utils import file_path
23 23
24 FILE_PATH = os.path.realpath(unicode(os.path.abspath(__file__))) 24 FILE_PATH = os.path.realpath(unicode(os.path.abspath(__file__)))
25 TARGET_UTIL_PATH = os.path.join(BASE_DIR, 'gtest_fake', 'gtest_fake_base.py') 25 TARGET_UTIL_PATH = os.path.join(BASE_DIR, 'gtest_fake', 'gtest_fake_base.py')
26 TARGET_PATH = os.path.join(BASE_DIR, 'gtest_fake', 'gtest_fake_fail.py') 26 TARGET_PATH = os.path.join(BASE_DIR, 'gtest_fake', 'gtest_fake_fail.py')
27 27
28 28
29 class TraceTestCases(unittest.TestCase): 29 class TraceTestCases(unittest.TestCase):
30 def setUp(self): 30 def setUp(self):
31 self.temp_file = None 31 self.temp_file = None
32 32
33 self.initial_cwd = GOOGLETEST_DIR 33 self.initial_cwd = GOOGLETEST_DIR
34 if sys.platform == 'win32': 34 if sys.platform == 'win32':
35 # Windows has no kernel mode concept of current working directory. 35 # Windows has no kernel mode concept of current working directory.
36 self.initial_cwd = None 36 self.initial_cwd = None
37 37
38 # There's 2 kinds of references to python, self.executable, 38 # There's 2 kinds of references to python, self.executable,
39 # self.real_executable. It depends how python was started and on which OS. 39 # self.real_executable. It depends how python was started and on which OS.
40 self.executable = unicode(sys.executable) 40 self.executable = unicode(sys.executable)
41 if sys.platform == 'darwin': 41 if sys.platform == 'darwin':
42 # /usr/bin/python is a thunk executable that decides which version of 42 # /usr/bin/python is a thunk executable that decides which version of
43 # python gets executed. 43 # python gets executed.
44 suffix = '.'.join(map(str, sys.version_info[0:2])) 44 suffix = '.'.join(map(str, sys.version_info[0:2]))
45 if os.access(self.executable + suffix, os.X_OK): 45 if os.access(self.executable + suffix, os.X_OK):
46 # So it'll look like /usr/bin/python2.7 46 # So it'll look like /usr/bin/python2.7
47 self.executable += suffix 47 self.executable += suffix
48 48
49 self.real_executable = trace_inputs.get_native_path_case(self.executable) 49 self.real_executable = file_path.get_native_path_case(self.executable)
50 # Make sure there's no environment variable that could do side effects. 50 # Make sure there's no environment variable that could do side effects.
51 os.environ.pop('GTEST_SHARD_INDEX', '') 51 os.environ.pop('GTEST_SHARD_INDEX', '')
52 os.environ.pop('GTEST_TOTAL_SHARDS', '') 52 os.environ.pop('GTEST_TOTAL_SHARDS', '')
53 53
54 def tearDown(self): 54 def tearDown(self):
55 if self.temp_file: 55 if self.temp_file:
56 os.remove(self.temp_file) 56 os.remove(self.temp_file)
57 57
58 def assertGreater(self, a, b, msg=None): 58 def assertGreater(self, a, b, msg=None):
59 """Just like self.assertTrue(a > b), but with a nicer default message. 59 """Just like self.assertTrue(a > b), but with a nicer default message.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 if sys.platform == 'win32': 141 if sys.platform == 'win32':
142 output = output.replace('\r\n', '\n') 142 output = output.replace('\r\n', '\n')
143 self.assertEqual(expected_output, output, repr(output)) 143 self.assertEqual(expected_output, output, repr(output))
144 144
145 expected_trace = { 145 expected_trace = {
146 u'root': { 146 u'root': {
147 u'children': [], 147 u'children': [],
148 u'command': [ 148 u'command': [
149 self.executable, TARGET_PATH, '--gtest_filter=' + test_case, 149 self.executable, TARGET_PATH, '--gtest_filter=' + test_case,
150 ], 150 ],
151 u'executable': trace_inputs.get_native_path_case( 151 u'executable': file_path.get_native_path_case(
152 unicode(self.executable)), 152 unicode(self.executable)),
153 u'initial_cwd': GOOGLETEST_DIR, 153 u'initial_cwd': GOOGLETEST_DIR,
154 }, 154 },
155 } 155 }
156 if sys.platform == 'win32': 156 if sys.platform == 'win32':
157 expected_trace['root']['initial_cwd'] = None 157 expected_trace['root']['initial_cwd'] = None
158 self.assertGreater(actual['trace']['root'].pop('pid'), 1) 158 self.assertGreater(actual['trace']['root'].pop('pid'), 1)
159 self.assertGreater(len(actual['trace']['root'].pop('files')), 10) 159 self.assertGreater(len(actual['trace']['root'].pop('files')), 10)
160 self.assertEqual(expected_trace, actual['trace']) 160 self.assertEqual(expected_trace, actual['trace'])
161 161
162 162
163 if __name__ == '__main__': 163 if __name__ == '__main__':
164 VERBOSE = '-v' in sys.argv 164 VERBOSE = '-v' in sys.argv
165 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) 165 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR)
166 # Necessary for the dtrace logger to work around execve() hook. See 166 # Necessary for the dtrace logger to work around execve() hook. See
167 # trace_inputs.py for more details. 167 # trace_inputs.py for more details.
168 os.environ['TRACE_INPUTS_DTRACE_ENABLE_EXECVE'] = '1' 168 os.environ['TRACE_INPUTS_DTRACE_ENABLE_EXECVE'] = '1'
169 unittest.main() 169 unittest.main()
OLDNEW
« no previous file with comments | « no previous file | isolate.py » ('j') | utils/file_path.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698