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

Side by Side Diff: presubmit_canned_checks.py

Issue 250693002: Adding custom environment variable support to presubmit_canned_checks.GetUnitTestsInDirectory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Generic presubmit checks that can be reused by other presubmit checks.""" 5 """Generic presubmit checks that can be reused by other presubmit checks."""
6 6
7 import os as _os 7 import os as _os
8 _HERE = _os.path.dirname(_os.path.abspath(__file__)) 8 _HERE = _os.path.dirname(_os.path.abspath(__file__))
9 9
10 10
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 if input_api.re.match(closed, status): 489 if input_api.re.match(closed, status):
490 long_text = status + '\n' + url 490 long_text = status + '\n' + url
491 return [output_api.PresubmitError('The tree is closed.', 491 return [output_api.PresubmitError('The tree is closed.',
492 long_text=long_text)] 492 long_text=long_text)]
493 except IOError as e: 493 except IOError as e:
494 return [output_api.PresubmitError('Error fetching tree status.', 494 return [output_api.PresubmitError('Error fetching tree status.',
495 long_text=str(e))] 495 long_text=str(e))]
496 return [] 496 return []
497 497
498 def GetUnitTestsInDirectory( 498 def GetUnitTestsInDirectory(
499 input_api, output_api, directory, whitelist=None, blacklist=None): 499 input_api, output_api, directory, whitelist=None, blacklist=None, env=None):
500 """Lists all files in a directory and runs them. Doesn't recurse. 500 """Lists all files in a directory and runs them. Doesn't recurse.
501 501
502 It's mainly a wrapper for RunUnitTests. Use whitelist and blacklist to filter 502 It's mainly a wrapper for RunUnitTests. Use whitelist and blacklist to filter
503 tests accordingly. 503 tests accordingly.
504 """ 504 """
505 unit_tests = [] 505 unit_tests = []
506 test_path = input_api.os_path.abspath( 506 test_path = input_api.os_path.abspath(
507 input_api.os_path.join(input_api.PresubmitLocalPath(), directory)) 507 input_api.os_path.join(input_api.PresubmitLocalPath(), directory))
508 508
509 def check(filename, filters): 509 def check(filename, filters):
(...skipping 11 matching lines...) Expand all
521 continue 521 continue
522 unit_tests.append(input_api.os_path.join(directory, filename)) 522 unit_tests.append(input_api.os_path.join(directory, filename))
523 to_run += 1 523 to_run += 1
524 input_api.logging.debug('Found %d files, running %d' % (found, to_run)) 524 input_api.logging.debug('Found %d files, running %d' % (found, to_run))
525 if not to_run: 525 if not to_run:
526 return [ 526 return [
527 output_api.PresubmitPromptWarning( 527 output_api.PresubmitPromptWarning(
528 'Out of %d files, found none that matched w=%r, b=%r in directory %s' 528 'Out of %d files, found none that matched w=%r, b=%r in directory %s'
529 % (found, whitelist, blacklist, directory)) 529 % (found, whitelist, blacklist, directory))
530 ] 530 ]
531 return GetUnitTests(input_api, output_api, unit_tests) 531 return GetUnitTests(input_api, output_api, unit_tests, env)
532 532
533 533
534 def GetUnitTests(input_api, output_api, unit_tests): 534 def GetUnitTests(input_api, output_api, unit_tests, env=None):
535 """Runs all unit tests in a directory. 535 """Runs all unit tests in a directory.
536 536
537 On Windows, sys.executable is used for unit tests ending with ".py". 537 On Windows, sys.executable is used for unit tests ending with ".py".
538 """ 538 """
539 # We don't want to hinder users from uploading incomplete patches. 539 # We don't want to hinder users from uploading incomplete patches.
540 if input_api.is_committing: 540 if input_api.is_committing:
541 message_type = output_api.PresubmitError 541 message_type = output_api.PresubmitError
542 else: 542 else:
543 message_type = output_api.PresubmitPromptWarning 543 message_type = output_api.PresubmitPromptWarning
544 544
545 results = [] 545 results = []
546 for unit_test in unit_tests: 546 for unit_test in unit_tests:
547 cmd = [] 547 cmd = []
548 if input_api.platform == 'win32' and unit_test.endswith('.py'): 548 if input_api.platform == 'win32' and unit_test.endswith('.py'):
549 # Windows needs some help. 549 # Windows needs some help.
550 cmd = [input_api.python_executable] 550 cmd = [input_api.python_executable]
551 cmd.append(unit_test) 551 cmd.append(unit_test)
552 if input_api.verbose: 552 if input_api.verbose:
553 cmd.append('--verbose') 553 cmd.append('--verbose')
554 kwargs = {'cwd': input_api.PresubmitLocalPath()}
555 if env:
556 kwargs['env'] = env
554 results.append(input_api.Command( 557 results.append(input_api.Command(
555 name=unit_test, 558 name=unit_test,
556 cmd=cmd, 559 cmd=cmd,
557 kwargs={'cwd': input_api.PresubmitLocalPath()}, 560 kwargs=kwargs,
558 message=message_type)) 561 message=message_type))
559 return results 562 return results
560 563
561 564
562 def GetPythonUnitTests(input_api, output_api, unit_tests): 565 def GetPythonUnitTests(input_api, output_api, unit_tests):
563 """Run the unit tests out of process, capture the output and use the result 566 """Run the unit tests out of process, capture the output and use the result
564 code to determine success. 567 code to determine success.
565 568
566 DEPRECATED. 569 DEPRECATED.
567 """ 570 """
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 def CheckPatchFormatted(input_api, output_api): 1064 def CheckPatchFormatted(input_api, output_api):
1062 import git_cl 1065 import git_cl
1063 cmd = ['cl', 'format', '--dry-run', input_api.PresubmitLocalPath()] 1066 cmd = ['cl', 'format', '--dry-run', input_api.PresubmitLocalPath()]
1064 code, _ = git_cl.RunGitWithCode(cmd, suppress_stderr=True) 1067 code, _ = git_cl.RunGitWithCode(cmd, suppress_stderr=True)
1065 if code == 2: 1068 if code == 2:
1066 return [output_api.PresubmitPromptWarning( 1069 return [output_api.PresubmitPromptWarning(
1067 'Your patch is not formatted, please run git cl format.')] 1070 'Your patch is not formatted, please run git cl format.')]
1068 # As this is just a warning, ignore all other errors if the user 1071 # As this is just a warning, ignore all other errors if the user
1069 # happens to have a broken clang-format, doesn't use git, etc etc. 1072 # happens to have a broken clang-format, doesn't use git, etc etc.
1070 return [] 1073 return []
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698