OLD | NEW |
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 1982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1993 input_api.unittest = self.mox.CreateMock(unittest) | 1993 input_api.unittest = self.mox.CreateMock(unittest) |
1994 input_api.subprocess.check_output( | 1994 input_api.subprocess.check_output( |
1995 ['pyyyyython', '-m', 'test_module'], cwd=None, env=None, | 1995 ['pyyyyython', '-m', 'test_module'], cwd=None, env=None, |
1996 stderr=input_api.subprocess.STDOUT) | 1996 stderr=input_api.subprocess.STDOUT) |
1997 self.mox.ReplayAll() | 1997 self.mox.ReplayAll() |
1998 | 1998 |
1999 results = presubmit_canned_checks.RunPythonUnitTests( | 1999 results = presubmit_canned_checks.RunPythonUnitTests( |
2000 input_api, presubmit.OutputApi, ['test_module']) | 2000 input_api, presubmit.OutputApi, ['test_module']) |
2001 self.assertEquals(len(results), 0) | 2001 self.assertEquals(len(results), 0) |
2002 | 2002 |
2003 def testCheckRietveldTryJobExecutionBad(self): | |
2004 change = self.mox.CreateMock(presubmit.SvnChange) | |
2005 change.scm = 'svn' | |
2006 change.issue = 2 | |
2007 change.patchset = 5 | |
2008 input_api = self.MockInputApi(change, True) | |
2009 connection = self.mox.CreateMockAnything() | |
2010 input_api.urllib2.urlopen('uurl/2/get_build_results/5').AndReturn( | |
2011 connection) | |
2012 connection.read().AndReturn('foo') | |
2013 connection.close() | |
2014 self.mox.ReplayAll() | |
2015 | |
2016 results = presubmit_canned_checks.CheckRietveldTryJobExecution( | |
2017 input_api, presubmit.OutputApi, 'uurl', ('mac', 'linux'), 'georges') | |
2018 self.assertEquals(len(results), 1) | |
2019 self.assertEquals(results[0].__class__, | |
2020 presubmit.OutputApi.PresubmitNotifyResult) | |
2021 | |
2022 def testCheckRietveldTryJobExecutionGood(self): | |
2023 change = self.mox.CreateMock(presubmit.SvnChange) | |
2024 change.scm = 'svn' | |
2025 change.issue = 2 | |
2026 change.patchset = 5 | |
2027 input_api = self.MockInputApi(change, True) | |
2028 connection = self.mox.CreateMockAnything() | |
2029 input_api.urllib2.urlopen('uurl/2/get_build_results/5').AndReturn( | |
2030 connection) | |
2031 connection.read().AndReturn("""amiga|Foo|blah | |
2032 linux|failure|bleh | |
2033 mac|success|blew | |
2034 """) | |
2035 connection.close() | |
2036 self.mox.ReplayAll() | |
2037 | |
2038 results = presubmit_canned_checks.CheckRietveldTryJobExecution( | |
2039 input_api, presubmit.OutputApi, 'uurl', ('mac', 'linux', 'amiga'), | |
2040 'georges') | |
2041 self.assertEquals(len(results), 1) | |
2042 self.assertEquals(results[0].__class__, | |
2043 presubmit.OutputApi.PresubmitPromptWarning) | |
2044 | |
2045 def testCheckBuildbotPendingBuildsBad(self): | 2003 def testCheckBuildbotPendingBuildsBad(self): |
2046 input_api = self.MockInputApi(None, True) | 2004 input_api = self.MockInputApi(None, True) |
2047 connection = self.mox.CreateMockAnything() | 2005 connection = self.mox.CreateMockAnything() |
2048 input_api.urllib2.urlopen('uurl').AndReturn(connection) | 2006 input_api.urllib2.urlopen('uurl').AndReturn(connection) |
2049 connection.read().AndReturn('foo') | 2007 connection.read().AndReturn('foo') |
2050 connection.close() | 2008 connection.close() |
2051 self.mox.ReplayAll() | 2009 self.mox.ReplayAll() |
2052 | 2010 |
2053 results = presubmit_canned_checks.CheckBuildbotPendingBuilds( | 2011 results = presubmit_canned_checks.CheckBuildbotPendingBuilds( |
2054 input_api, presubmit.OutputApi, 'uurl', 2, ('foo')) | 2012 input_api, presubmit.OutputApi, 'uurl', 2, ('foo')) |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2268 owners_check=True) | 2226 owners_check=True) |
2269 self.assertEqual(1, len(results)) | 2227 self.assertEqual(1, len(results)) |
2270 self.assertEqual( | 2228 self.assertEqual( |
2271 'Found line ending with white spaces in:', results[0]._message) | 2229 'Found line ending with white spaces in:', results[0]._message) |
2272 self.checkstdout('') | 2230 self.checkstdout('') |
2273 | 2231 |
2274 | 2232 |
2275 if __name__ == '__main__': | 2233 if __name__ == '__main__': |
2276 import unittest | 2234 import unittest |
2277 unittest.main() | 2235 unittest.main() |
OLD | NEW |