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

Side by Side Diff: pipa/py/test_utils/presubmit.py

Issue 2707493002: Presubmit checks for the Pipa repository (Closed)
Patch Set: Created 3 years, 10 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 | « pipa/py/test_utils/__init__.py ('k') | 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
(Empty)
1 # Copyright 2012 Google Inc. All Rights Reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15 """Contains functionality for integrating unit-tests with gcl presubmit
16 checks."""
17 import os
18 import sys
19
20
21 def MakeResult(output_api, message, committing, modified_files=None):
22 """Makes a gcl result. Makes a PresubmitError result if
23 |committing| is True, otherwise makes a PresubmitNotifyResult."""
24 if not modified_files:
25 modified_files = []
26 if committing:
27 return output_api.PresubmitError(message, modified_files)
28 else:
29 return output_api.PresubmitNotifyResult(message, modified_files)
30
31
32 def GetTestSuccessPath(build_path, configuration, testname):
33 """Returns the path to the success file for the given test and
34 configuration. |build_path| is the path to the "build" directory."""
35
36 return os.path.abspath(os.path.join(build_path,
37 configuration,
38 '%s_success.txt' % testname))
39
40
41 def GetModifiedFiles(input_api, since=0):
42 """Returns a list of files that have been modified since |since|.
43 If |since| is a file, uses its modification time."""
44 if isinstance(since, basestring):
45 try:
46 since = os.stat(since).st_mtime
47 # We don't specify the exception type here as it varies depending on the
48 # OS.
49 except: # pylint: disable=W0702
50 since = 0
51
52 modified_files = []
53 for f in input_api.AffectedFiles(include_deletes = False):
54 file_time = os.stat(f.AbsoluteLocalPath()).st_mtime
55 if file_time > since:
56 modified_files.append(f.LocalPath())
57 return modified_files
58
59
60 def CheckTestSuccess(input_api, output_api, committing, configuration,
61 test_name, message=None):
62 """Returns a list of files that have changed since the last time the
63 given test was run. If the test needs to be re-run and |message| is a
64 str, will also output the provided message."""
65 # By convention, a test called NAME will generate NAME_success.txt in the
66 # appropriate output directory.
67 test_utils_path = os.path.join(input_api.PresubmitLocalPath(), 'py',
68 'test_utils')
69 sys.path.append(test_utils_path)
70 import syzygy
71 build_path = syzygy.GetBuildDir()
72 success_path = GetTestSuccessPath(build_path,
73 configuration,
74 test_name)
75 modified_files = GetModifiedFiles(input_api, success_path)
76 if len(modified_files) == 0:
77 return []
78
79 results = []
80
81 if message:
82 results.append(MakeResult(output_api, message, committing))
83
84 results.append(MakeResult(output_api,
85 'These files have been modified since %s %s test ran last' %
86 (configuration, test_name),
87 committing,
88 modified_files=modified_files))
89
90 return results
OLDNEW
« no previous file with comments | « pipa/py/test_utils/__init__.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698