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

Side by Side Diff: tests/presubmit_unittest.py

Issue 6932060: Remove presubmit warning for long lines in .grd files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: '' Created 9 years, 7 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 | « presubmit_support.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
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 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 """Unit tests for presubmit_support.py and presubmit_canned_checks.py.""" 6 """Unit tests for presubmit_support.py and presubmit_canned_checks.py."""
7 7
8 # pylint is too confused. 8 # pylint is too confused.
9 # pylint: disable=E1101,E1103,R0201,W0212,W0403 9 # pylint: disable=E1101,E1103,R0201,W0212,W0403
10 10
(...skipping 1374 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 Args: 1385 Args:
1386 check: the check to run. 1386 check: the check to run.
1387 content1: content which is expected to pass the check. 1387 content1: content which is expected to pass the check.
1388 content2: content which is expected to fail the check. 1388 content2: content which is expected to fail the check.
1389 error_type: the type of the error expected for content2. 1389 error_type: the type of the error expected for content2.
1390 """ 1390 """
1391 change1 = presubmit.Change( 1391 change1 = presubmit.Change(
1392 'foo1', 'foo1\n', self.fake_root_dir, None, 0, 0, None) 1392 'foo1', 'foo1\n', self.fake_root_dir, None, 0, 0, None)
1393 input_api1 = self.MockInputApi(change1, False) 1393 input_api1 = self.MockInputApi(change1, False)
1394 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) 1394 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile)
1395 input_api1.AffectedFiles(mox.IgnoreArg(), include_deletes=False).AndReturn( 1395 input_api1.AffectedFiles(
1396 [affected_file]) 1396 include_deletes=False,
1397 file_filter=mox.IgnoreArg()).AndReturn([affected_file])
1397 affected_file.NewContents().AndReturn([ 1398 affected_file.NewContents().AndReturn([
1398 'ahoy', 1399 'ahoy',
1399 'yo' + content1, 1400 'yo' + content1,
1400 'hay', 1401 'hay',
1401 'yer', 1402 'yer',
1402 'ya']) 1403 'ya'])
1403 1404
1404 change2 = presubmit.Change( 1405 change2 = presubmit.Change(
1405 'foo2', 'foo2\n', self.fake_root_dir, None, 0, 0, None) 1406 'foo2', 'foo2\n', self.fake_root_dir, None, 0, 0, None)
1406 input_api2 = self.MockInputApi(change2, False) 1407 input_api2 = self.MockInputApi(change2, False)
1407 1408
1408 input_api2.AffectedFiles(mox.IgnoreArg(), include_deletes=False).AndReturn( 1409 input_api2.AffectedFiles(
1409 [affected_file]) 1410 include_deletes=False,
1411 file_filter=mox.IgnoreArg()).AndReturn([affected_file])
1410 affected_file.NewContents().AndReturn([ 1412 affected_file.NewContents().AndReturn([
1411 'ahoy', 1413 'ahoy',
1412 'yo' + content2, 1414 'yo' + content2,
1413 'hay', 1415 'hay',
1414 'yer', 1416 'yer',
1415 'ya']) 1417 'ya'])
1416 affected_file.ChangedContents().AndReturn([ 1418 affected_file.ChangedContents().AndReturn([
1417 (42, 'yo, ' + content2), 1419 (42, 'yo, ' + content2),
1418 (43, 'yer'), 1420 (43, 'yer'),
1419 (23, 'ya')]) 1421 (23, 'ya')])
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 # Only this one will trigger. 1591 # Only this one will trigger.
1590 affected_file4 = self.mox.CreateMock(presubmit.SvnAffectedFile) 1592 affected_file4 = self.mox.CreateMock(presubmit.SvnAffectedFile)
1591 affected_file4.LocalPath().AndReturn('makefile.foo') 1593 affected_file4.LocalPath().AndReturn('makefile.foo')
1592 affected_file1.NewContents().AndReturn(['yo, ']) 1594 affected_file1.NewContents().AndReturn(['yo, '])
1593 affected_file4.NewContents().AndReturn(['ye\t']) 1595 affected_file4.NewContents().AndReturn(['ye\t'])
1594 affected_file4.ChangedContents().AndReturn([(46, 'ye\t')]) 1596 affected_file4.ChangedContents().AndReturn([(46, 'ye\t')])
1595 affected_file4.LocalPath().AndReturn('makefile.foo') 1597 affected_file4.LocalPath().AndReturn('makefile.foo')
1596 affected_files = (affected_file1, affected_file2, 1598 affected_files = (affected_file1, affected_file2,
1597 affected_file3, affected_file4) 1599 affected_file3, affected_file4)
1598 1600
1599 def test(source_filter, include_deletes): 1601 def test(file_filter, include_deletes):
1600 self.assertFalse(include_deletes) 1602 self.assertFalse(include_deletes)
1601 for x in affected_files: 1603 for x in affected_files:
1602 if source_filter(x): 1604 if file_filter(x):
1603 yield x 1605 yield x
1604 # Override the mock of these functions. 1606 # Override the mock of these functions.
1605 input_api1.FilterSourceFile = lambda x: x 1607 input_api1.FilterSourceFile = lambda x: x
1606 input_api1.AffectedFiles = test 1608 input_api1.AffectedFiles = test
1607 self.mox.ReplayAll() 1609 self.mox.ReplayAll()
1608 1610
1609 results1 = presubmit_canned_checks.CheckChangeHasNoTabs(input_api1, 1611 results1 = presubmit_canned_checks.CheckChangeHasNoTabs(input_api1,
1610 presubmit.OutputApi, None) 1612 presubmit.OutputApi, None)
1611 self.assertEquals(len(results1), 1) 1613 self.assertEquals(len(results1), 1)
1612 self.assertEquals(results1[0].__class__, 1614 self.assertEquals(results1[0].__class__,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1711 change.GetModifiedFiles().AndReturn([modified_dir_file]) 1713 change.GetModifiedFiles().AndReturn([modified_dir_file])
1712 change.GetAllModifiedFiles().AndReturn([modified_dir_file, 1714 change.GetAllModifiedFiles().AndReturn([modified_dir_file,
1713 accidental_submssion_file]) 1715 accidental_submssion_file])
1714 input_api = self.MockInputApi(change, True) 1716 input_api = self.MockInputApi(change, True)
1715 1717
1716 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) 1718 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile)
1717 affected_file.Action().AndReturn('M') 1719 affected_file.Action().AndReturn('M')
1718 affected_file.IsDirectory().AndReturn(True) 1720 affected_file.IsDirectory().AndReturn(True)
1719 affected_file.AbsoluteLocalPath().AndReturn(accidental_submssion_file) 1721 affected_file.AbsoluteLocalPath().AndReturn(accidental_submssion_file)
1720 affected_file.LocalPath().AndReturn(accidental_submssion_file) 1722 affected_file.LocalPath().AndReturn(accidental_submssion_file)
1721 input_api.AffectedFiles(None).AndReturn([affected_file]) 1723 input_api.AffectedFiles(file_filter=None).AndReturn([affected_file])
1722 1724
1723 self.mox.ReplayAll() 1725 self.mox.ReplayAll()
1724 1726
1725 check = presubmit_canned_checks.CheckSvnModifiedDirectories 1727 check = presubmit_canned_checks.CheckSvnModifiedDirectories
1726 results = check(input_api, presubmit.OutputApi, None) 1728 results = check(input_api, presubmit.OutputApi, None)
1727 self.assertEquals(len(results), 1) 1729 self.assertEquals(len(results), 1)
1728 self.assertEquals(results[0].__class__, 1730 self.assertEquals(results[0].__class__,
1729 presubmit.OutputApi.PresubmitPromptWarning) 1731 presubmit.OutputApi.PresubmitPromptWarning)
1730 1732
1731 def testCheckSvnForCommonMimeTypes(self): 1733 def testCheckSvnForCommonMimeTypes(self):
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1989 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) 1991 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile)
1990 input_api = self.MockInputApi(change, False) 1992 input_api = self.MockInputApi(change, False)
1991 fake_db = self.mox.CreateMock(owners.Database) 1993 fake_db = self.mox.CreateMock(owners.Database)
1992 fake_db.email_regexp = input_api.re.compile(owners.BASIC_EMAIL_REGEXP) 1994 fake_db.email_regexp = input_api.re.compile(owners.BASIC_EMAIL_REGEXP)
1993 input_api.owners_db = fake_db 1995 input_api.owners_db = fake_db
1994 input_api.is_committing = True 1996 input_api.is_committing = True
1995 input_api.tbr = tbr 1997 input_api.tbr = tbr
1996 1998
1997 if not tbr and issue: 1999 if not tbr and issue:
1998 affected_file.LocalPath().AndReturn('foo.cc') 2000 affected_file.LocalPath().AndReturn('foo.cc')
1999 change.AffectedFiles(None).AndReturn([affected_file]) 2001 change.AffectedFiles(file_filter=None).AndReturn([affected_file])
2000 2002
2001 expected_host = 'http://localhost' 2003 expected_host = 'http://localhost'
2002 if host_url: 2004 if host_url:
2003 input_api.host_url = host_url 2005 input_api.host_url = host_url
2004 if host_url.startswith('https'): 2006 if host_url.startswith('https'):
2005 expected_host = host_url 2007 expected_host = host_url
2006 2008
2007 owner_email = 'john@example.com' 2009 owner_email = 'john@example.com'
2008 messages = list('{"sender": "' + a + '","text": "lgtm"}' for 2010 messages = list('{"sender": "' + a + '","text": "lgtm"}' for
2009 a in approvers) 2011 a in approvers)
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
2144 whitelist=['^a$', '^b$'], 2146 whitelist=['^a$', '^b$'],
2145 blacklist=['a']) 2147 blacklist=['a'])
2146 self.assertEqual(results, []) 2148 self.assertEqual(results, [])
2147 self.checkstdout( 2149 self.checkstdout(
2148 'Running %s\n' % presubmit.os.path.join('random_directory', 'b')) 2150 'Running %s\n' % presubmit.os.path.join('random_directory', 'b'))
2149 2151
2150 2152
2151 if __name__ == '__main__': 2153 if __name__ == '__main__':
2152 import unittest 2154 import unittest
2153 unittest.main() 2155 unittest.main()
OLDNEW
« no previous file with comments | « presubmit_support.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698