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

Unified Diff: tests/presubmit_unittest.py

Issue 6883050: presubmit checks: skip computing the diff if possible (Closed) Base URL: http://src.chromium.org/svn/trunk/tools/depot_tools/
Patch Set: Fixed O(n^2) issue. Created 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « presubmit_canned_checks.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/presubmit_unittest.py
===================================================================
--- tests/presubmit_unittest.py (revision 82663)
+++ tests/presubmit_unittest.py (working copy)
@@ -1374,27 +1374,45 @@
self.assertEquals(results2[0].__class__, error_type)
def ContentTest(self, check, content1, content2, error_type):
+ """Runs a test of a content-checking rule.
+
+ Args:
+ check: the check to run.
+ content1: content which is expected to pass the check.
+ content2: content which is expected to fail the check.
+ error_type: the type of the error expected for content2.
+ """
change1 = presubmit.Change(
'foo1', 'foo1\n', self.fake_root_dir, None, 0, 0, None)
input_api1 = self.MockInputApi(change1, False)
affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile)
- affected_file.LocalPath().AndReturn('foo.cc')
- # Format is (file, line number, line content)
- output1 = [
- (affected_file, 42, 'yo, ' + content1),
- (affected_file, 43, 'yer'),
- (affected_file, 23, 'ya'),
- ]
- input_api1.RightHandSideLines(mox.IgnoreArg()).AndReturn(output1)
+ input_api1.AffectedFiles(mox.IgnoreArg(), include_deletes=False).AndReturn(
+ [affected_file])
+ affected_file.NewContents().AndReturn([
+ 'ahoy',
+ 'yo' + content1,
+ 'hay',
+ 'yer',
+ 'ya'])
+
change2 = presubmit.Change(
'foo2', 'foo2\n', self.fake_root_dir, None, 0, 0, None)
input_api2 = self.MockInputApi(change2, False)
- output2 = [
- (affected_file, 42, 'yo, ' + content2),
- (affected_file, 43, 'yer'),
- (affected_file, 23, 'ya'),
- ]
- input_api2.RightHandSideLines(mox.IgnoreArg()).AndReturn(output2)
+
+ input_api2.AffectedFiles(mox.IgnoreArg(), include_deletes=False).AndReturn(
+ [affected_file])
+ affected_file.NewContents().AndReturn([
+ 'ahoy',
+ 'yo' + content2,
+ 'hay',
+ 'yer',
+ 'ya'])
+ affected_file.ChangedContents().AndReturn([
+ (42, 'yo, ' + content2),
+ (43, 'yer'),
+ (23, 'ya')])
+ affected_file.LocalPath().AndReturn('foo.cc')
+
self.mox.ReplayAll()
results1 = check(input_api1, presubmit.OutputApi, None)
@@ -1565,20 +1583,21 @@
# Only this one will trigger.
affected_file4 = self.mox.CreateMock(presubmit.SvnAffectedFile)
affected_file4.LocalPath().AndReturn('makefile.foo')
+ affected_file1.NewContents().AndReturn(['yo, '])
+ affected_file4.NewContents().AndReturn(['ye\t'])
+ affected_file4.ChangedContents().AndReturn([(46, 'ye\t')])
affected_file4.LocalPath().AndReturn('makefile.foo')
- output1 = [
- (affected_file1, 42, 'yo, '),
- (affected_file2, 43, 'yer\t'),
- (affected_file3, 45, 'yr\t'),
- (affected_file4, 46, 'ye\t'),
- ]
- def test(source_filter):
- for i in output1:
- if source_filter(i[0]):
- yield i
+ affected_files = (affected_file1, affected_file2,
+ affected_file3, affected_file4)
+
+ def test(source_filter, include_deletes):
+ self.assertFalse(include_deletes)
+ for x in affected_files:
+ if source_filter(x):
+ yield x
# Override the mock of these functions.
input_api1.FilterSourceFile = lambda x: x
- input_api1.RightHandSideLines = test
+ input_api1.AffectedFiles = test
self.mox.ReplayAll()
results1 = presubmit_canned_checks.CheckChangeHasNoTabs(input_api1,
« no previous file with comments | « presubmit_canned_checks.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698