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

Side by Side Diff: tests/presubmit_unittest.py

Issue 1119003: Add new canned checks: CheckRietveldTryJobExecution and CheckBuildbotPendingBuilds (Closed)
Patch Set: Standardize strings Created 10 years, 9 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 | « presubmit_canned_checks.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/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 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 import StringIO 8 import StringIO
9 9
10 # Fixes include path. 10 # Fixes include path.
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 'CheckChangeHasQaField', 'CheckChangeHasTestedField', 1071 'CheckChangeHasQaField', 'CheckChangeHasTestedField',
1072 'CheckChangeHasTestField', 1072 'CheckChangeHasTestField',
1073 'CheckChangeLintsClean', 1073 'CheckChangeLintsClean',
1074 'CheckChangeSvnEolStyle', 1074 'CheckChangeSvnEolStyle',
1075 'CheckLicense', 1075 'CheckLicense',
1076 'CheckSvnModifiedDirectories', 1076 'CheckSvnModifiedDirectories',
1077 'CheckSvnForCommonMimeTypes', 'CheckSvnProperty', 1077 'CheckSvnForCommonMimeTypes', 'CheckSvnProperty',
1078 'CheckDoNotSubmit', 1078 'CheckDoNotSubmit',
1079 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', 1079 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles',
1080 'CheckLongLines', 'CheckTreeIsOpen', 'RunPythonUnitTests', 1080 'CheckLongLines', 'CheckTreeIsOpen', 'RunPythonUnitTests',
1081 'CheckBuildbotPendingBuilds', 'CheckRietveldTryJobExecution',
1081 ] 1082 ]
1082 # If this test fails, you should add the relevant test. 1083 # If this test fails, you should add the relevant test.
1083 self.compareMembers(presubmit_canned_checks, members) 1084 self.compareMembers(presubmit_canned_checks, members)
1084 1085
1085 def DescriptionTest(self, check, description1, description2, error_type, 1086 def DescriptionTest(self, check, description1, description2, error_type,
1086 committing): 1087 committing):
1087 change1 = presubmit.Change('foo1', description1, self.fake_root_dir, None, 1088 change1 = presubmit.Change('foo1', description1, self.fake_root_dir, None,
1088 0, 0) 1089 0, 0)
1089 input_api1 = self.MockInputApi(change1, committing) 1090 input_api1 = self.MockInputApi(change1, committing)
1090 change2 = presubmit.Change('foo2', description2, self.fake_root_dir, None, 1091 change2 = presubmit.Change('foo2', description2, self.fake_root_dir, None,
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 ['pyyyyython', '-m', 'test_module'], cwd=None, env=None, 1522 ['pyyyyython', '-m', 'test_module'], cwd=None, env=None,
1522 stderr=presubmit.subprocess.PIPE, stdin=presubmit.subprocess.PIPE, 1523 stderr=presubmit.subprocess.PIPE, stdin=presubmit.subprocess.PIPE,
1523 stdout=presubmit.subprocess.PIPE).AndReturn(process) 1524 stdout=presubmit.subprocess.PIPE).AndReturn(process)
1524 process.communicate().AndReturn(('', '')) 1525 process.communicate().AndReturn(('', ''))
1525 self.mox.ReplayAll() 1526 self.mox.ReplayAll()
1526 1527
1527 results = presubmit_canned_checks.RunPythonUnitTests( 1528 results = presubmit_canned_checks.RunPythonUnitTests(
1528 input_api, presubmit.OutputApi, ['test_module']) 1529 input_api, presubmit.OutputApi, ['test_module'])
1529 self.assertEquals(len(results), 0) 1530 self.assertEquals(len(results), 0)
1530 1531
1532 def testCheckRietveldTryJobExecutionBad(self):
1533 change = self.mox.CreateMock(presubmit.SvnChange)
1534 change.scm = 'svn'
1535 change.issue = 2
1536 change.patchset = 5
1537 input_api = self.MockInputApi(change, True)
1538 connection = self.mox.CreateMockAnything()
1539 input_api.urllib2.urlopen('uurl/2/get_build_results/5').AndReturn(
1540 connection)
1541 connection.read().AndReturn('foo')
1542 connection.close()
1543 self.mox.ReplayAll()
1544
1545 results = presubmit_canned_checks.CheckRietveldTryJobExecution(
1546 input_api, presubmit.OutputApi, 'uurl', ('mac', 'linux'), 'georges')
1547 self.assertEquals(len(results), 1)
1548 self.assertEquals(results[0].__class__,
1549 presubmit.OutputApi.PresubmitNotifyResult)
1550
1551 def testCheckRietveldTryJobExecutionGood(self):
1552 change = self.mox.CreateMock(presubmit.SvnChange)
1553 change.scm = 'svn'
1554 change.issue = 2
1555 change.patchset = 5
1556 input_api = self.MockInputApi(change, True)
1557 connection = self.mox.CreateMockAnything()
1558 input_api.urllib2.urlopen('uurl/2/get_build_results/5').AndReturn(
1559 connection)
1560 connection.read().AndReturn("""amiga|Foo|blah
1561 linux|failure|bleh
1562 mac|success|blew
1563 """)
1564 connection.close()
1565 self.mox.ReplayAll()
1566
1567 results = presubmit_canned_checks.CheckRietveldTryJobExecution(
1568 input_api, presubmit.OutputApi, 'uurl', ('mac', 'linux', 'amiga'),
1569 'georges')
1570 self.assertEquals(len(results), 1)
1571 self.assertEquals(results[0].__class__,
1572 presubmit.OutputApi.PresubmitPromptWarning)
1573
1574 def testCheckBuildbotPendingBuildsBad(self):
1575 input_api = self.MockInputApi(None, True)
1576 input_api.json = presubmit.json
1577 connection = self.mox.CreateMockAnything()
1578 input_api.urllib2.urlopen('uurl').AndReturn(connection)
1579 connection.read().AndReturn('foo')
1580 connection.close()
1581 self.mox.ReplayAll()
1582
1583 results = presubmit_canned_checks.CheckBuildbotPendingBuilds(
1584 input_api, presubmit.OutputApi, 'uurl', 2, ('foo'))
1585 self.assertEquals(len(results), 1)
1586 self.assertEquals(results[0].__class__,
1587 presubmit.OutputApi.PresubmitNotifyResult)
1588
1589 def testCheckBuildbotPendingBuildsGood(self):
1590 input_api = self.MockInputApi(None, True)
1591 input_api.json = presubmit.json
1592 connection = self.mox.CreateMockAnything()
1593 input_api.urllib2.urlopen('uurl').AndReturn(connection)
1594 connection.read().AndReturn("""
1595 {
1596 'b1': { 'pending_builds': [0, 1, 2, 3, 4, 5, 6, 7] },
1597 'foo': { 'pending_builds': [0, 1, 2, 3, 4, 5, 6, 7] },
1598 'b2': { 'pending_builds': [0] }
1599 }""")
1600 connection.close()
1601 self.mox.ReplayAll()
1602
1603 results = presubmit_canned_checks.CheckBuildbotPendingBuilds(
1604 input_api, presubmit.OutputApi, 'uurl', 2, ('foo'))
1605 self.assertEquals(len(results), 1)
1606 self.assertEquals(results[0].__class__,
1607 presubmit.OutputApi.PresubmitNotifyResult)
1608
1531 1609
1532 if __name__ == '__main__': 1610 if __name__ == '__main__':
1533 import unittest 1611 import unittest
1534 unittest.main() 1612 unittest.main()
OLDNEW
« 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