OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2009 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 """Generic presubmit checks that can be reused by other presubmit checks.""" | 6 """Generic presubmit checks that can be reused by other presubmit checks.""" |
7 | 7 |
8 | 8 |
9 ### Description checks | 9 ### Description checks |
10 | 10 |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 unit_test_name = unit_test | 277 unit_test_name = unit_test |
278 # "python -m test.unit_test" doesn't work. We need to change to the right | 278 # "python -m test.unit_test" doesn't work. We need to change to the right |
279 # directory instead. | 279 # directory instead. |
280 if '.' in unit_test: | 280 if '.' in unit_test: |
281 # Tests imported in submodules (subdirectories) assume that the current | 281 # Tests imported in submodules (subdirectories) assume that the current |
282 # directory is in the PYTHONPATH. Manually fix that. | 282 # directory is in the PYTHONPATH. Manually fix that. |
283 unit_test = unit_test.replace('.', '/') | 283 unit_test = unit_test.replace('.', '/') |
284 cwd = input_api.os_path.dirname(unit_test) | 284 cwd = input_api.os_path.dirname(unit_test) |
285 unit_test = input_api.os_path.basename(unit_test) | 285 unit_test = input_api.os_path.basename(unit_test) |
286 env = input_api.environ.copy() | 286 env = input_api.environ.copy() |
287 backpath = [';'.join(['..'] * (cwd.count('/') + 1))] | 287 backpath = [input_api.os_path.pathsep.join(['..'] * (cwd.count('/') + 1))] |
288 if env.get('PYTHONPATH'): | 288 if env.get('PYTHONPATH'): |
289 backpath.append(env.get('PYTHONPATH')) | 289 backpath.append(env.get('PYTHONPATH')) |
290 env['PYTHONPATH'] = ';'.join((backpath)) | 290 env['PYTHONPATH'] = input_api.os_path.pathsep.join((backpath)) |
291 subproc = input_api.subprocess.Popen( | 291 subproc = input_api.subprocess.Popen( |
292 [ | 292 [ |
293 input_api.python_executable, | 293 input_api.python_executable, |
294 "-m", | 294 "-m", |
295 "%s" % unit_test | 295 "%s" % unit_test |
296 ], | 296 ], |
297 cwd=cwd, | 297 cwd=cwd, |
298 env=env, | 298 env=env, |
299 stdin=input_api.subprocess.PIPE, | 299 stdin=input_api.subprocess.PIPE, |
300 stdout=input_api.subprocess.PIPE, | 300 stdout=input_api.subprocess.PIPE, |
301 stderr=input_api.subprocess.PIPE) | 301 stderr=input_api.subprocess.PIPE) |
302 stdoutdata, stderrdata = subproc.communicate() | 302 stdoutdata, stderrdata = subproc.communicate() |
303 # Discard the output if returncode == 0 | 303 # Discard the output if returncode == 0 |
304 if subproc.returncode: | 304 if subproc.returncode: |
305 outputs.append("Test '%s' failed with code %d\n%s\n%s\n" % ( | 305 outputs.append("Test '%s' failed with code %d\n%s\n%s\n" % ( |
306 unit_test_name, subproc.returncode, stdoutdata, stderrdata)) | 306 unit_test_name, subproc.returncode, stdoutdata, stderrdata)) |
307 if outputs: | 307 if outputs: |
308 return [message_type("%d unit tests failed." % len(outputs), | 308 return [message_type("%d unit tests failed." % len(outputs), |
309 long_text='\n'.join(outputs))] | 309 long_text='\n'.join(outputs))] |
310 return [] | 310 return [] |
OLD | NEW |