Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 # pylint is too confused. | 8 # pylint is too confused. |
| 9 # pylint: disable=E1101,E1103,W0212,W0403 | 9 # pylint: disable=E1101,E1103,W0212,W0403 |
| 10 | 10 |
| 11 import StringIO | 11 import StringIO |
| 12 import unittest | |
| 12 | 13 |
| 13 # Fixes include path. | 14 # Fixes include path. |
| 14 from super_mox import mox, SuperMoxTestBase | 15 from super_mox import mox, SuperMoxTestBase |
| 15 | 16 |
| 16 import owners | 17 import owners |
| 17 import presubmit_support as presubmit | 18 import presubmit_support as presubmit |
| 18 # Shortcut. | 19 # Shortcut. |
| 19 presubmit_canned_checks = presubmit.presubmit_canned_checks | 20 presubmit_canned_checks = presubmit.presubmit_canned_checks |
| 20 | 21 |
| 21 | 22 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 | 129 |
| 129 | 130 |
| 130 class PresubmitUnittest(PresubmitTestsBase): | 131 class PresubmitUnittest(PresubmitTestsBase): |
| 131 """General presubmit_support.py tests (excluding InputApi and OutputApi).""" | 132 """General presubmit_support.py tests (excluding InputApi and OutputApi).""" |
| 132 | 133 |
| 133 _INHERIT_SETTINGS = 'inherit-review-settings-ok' | 134 _INHERIT_SETTINGS = 'inherit-review-settings-ok' |
| 134 | 135 |
| 135 def testMembersChanged(self): | 136 def testMembersChanged(self): |
| 136 self.mox.ReplayAll() | 137 self.mox.ReplayAll() |
| 137 members = [ | 138 members = [ |
| 138 'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks', | 139 'AffectedFile', 'Change', 'ChangeDescription', 'DoGetTrySlaves', |
| 139 'GetTrySlavesExecuter', 'GitAffectedFile', | 140 'DoPresubmitChecks', 'GetTrySlavesExecuter', 'GitAffectedFile', |
| 140 'GitChange', 'InputApi', 'ListRelevantPresubmitFiles', 'Main', | 141 'GitChange', 'InputApi', 'ListRelevantPresubmitFiles', 'Main', |
| 141 'NotImplementedException', 'OutputApi', 'ParseFiles', | 142 'NotImplementedException', 'OutputApi', 'ParseFiles', |
| 142 'PresubmitExecuter', 'PresubmitOutput', 'ScanSubDirs', | 143 'PresubmitExecuter', 'PresubmitOutput', 'ScanSubDirs', |
| 143 'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO', | 144 'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO', |
| 144 'exceptions', 'fnmatch', 'gclient_utils', 'glob', 'json', 'load_files', | 145 'exceptions', 'fnmatch', 'gclient_utils', 'glob', 'json', 'load_files', |
| 145 'logging', 'marshal', 'normpath', 'optparse', 'os', 'owners', 'pickle', | 146 'logging', 'marshal', 'normpath', 'optparse', 'os', 'owners', 'pickle', |
| 146 'presubmit_canned_checks', 'random', 're', 'scm', 'subprocess', | 147 'presubmit_canned_checks', 'random', 're', 'scm', 'subprocess', |
| 147 'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2', | 148 'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2', |
| 148 'warn', | 149 'warn', |
| 149 ] | 150 ] |
| (...skipping 1813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1963 def testCannedCheckOwners_MissingSchemeInHostURL(self): | 1964 def testCannedCheckOwners_MissingSchemeInHostURL(self): |
| 1964 self.OwnersTest(is_committing=True, | 1965 self.OwnersTest(is_committing=True, |
| 1965 approvers=set(['ben@example.com']), | 1966 approvers=set(['ben@example.com']), |
| 1966 uncovered_files=set(), host_url='localhost') | 1967 uncovered_files=set(), host_url='localhost') |
| 1967 | 1968 |
| 1968 def testCannedCheckOwners_HTTPS_HostURL(self): | 1969 def testCannedCheckOwners_HTTPS_HostURL(self): |
| 1969 self.OwnersTest(is_committing=True, | 1970 self.OwnersTest(is_committing=True, |
| 1970 approvers=set(['ben@example.com']), | 1971 approvers=set(['ben@example.com']), |
| 1971 uncovered_files=set(), host_url='https://localhost') | 1972 uncovered_files=set(), host_url='https://localhost') |
| 1972 | 1973 |
| 1973 | 1974 |
|
M-A Ruel
2011/03/22 17:24:16
only 2 lines.
| |
| 1975 | |
| 1976 class ChangeDescriptionTests(unittest.TestCase): | |
| 1977 def setUp(self): | |
| 1978 self.editor_input = None | |
| 1979 self.editor_output = None | |
| 1980 | |
| 1981 def tearDown(self): | |
| 1982 self.editor_input = None | |
| 1983 self.editor_output = None | |
| 1984 | |
| 1985 def change_desc(self, editor=None, **kwargs): | |
| 1986 if editor is None: | |
| 1987 editor = lambda x: x | |
| 1988 return presubmit.ChangeDescription(editor=editor, **kwargs) | |
| 1989 | |
| 1990 def editor(self, text): | |
| 1991 if self.editor_input: | |
| 1992 self.assertTrue(self.editor_input in text) | |
| 1993 if self.editor_output is not None: | |
| 1994 return self.editor_output | |
| 1995 return text | |
| 1996 | |
| 1997 def test_empty(self): | |
| 1998 desc = self.change_desc() | |
| 1999 self.assertTrue(desc.IsEmpty()) | |
| 2000 desc.UserEdit() | |
| 2001 self.assertTrue(desc.IsEmpty()) | |
| 2002 | |
| 2003 def test_basic(self): | |
| 2004 desc = self.change_desc(subject='foo', description='desc', | |
| 2005 reviewers=['joe@example.com']) | |
| 2006 desc.UserEdit() | |
| 2007 self.assertFalse(desc.IsEmpty()) | |
| 2008 self.assertEqual(desc.subject, 'foo') | |
| 2009 self.assertEquals(desc.description, | |
| 2010 'foo\n' | |
| 2011 '\n' | |
| 2012 'desc\n' | |
| 2013 '\n' | |
| 2014 'R=joe@example.com') | |
| 2015 self.assertEquals(desc.reviewers, ['joe@example.com']) | |
| 2016 self.assertFalse(desc.tbr) | |
| 2017 | |
| 2018 def test_subject_only(self): | |
| 2019 self.editor_input = 'foo\n\nR=\nBUG=\nTEST=\n' | |
| 2020 desc = self.change_desc(subject='foo', editor=self.editor) | |
| 2021 desc.UserEdit() | |
| 2022 self.assertEquals(desc.description, 'foo') | |
| 2023 | |
| 2024 def test_tbr_with_reviewer(self): | |
| 2025 self.editor_input = 'TBR=\nBUG=\nTEST=\n' | |
| 2026 self.editor_output = 'foo\n\nTBR=joe@example.com' | |
| 2027 desc = self.change_desc(tbr=True, editor=self.editor) | |
| 2028 self.assertFalse(desc.tbr) | |
| 2029 self.assertEquals(desc.reviewers, []) | |
| 2030 desc.UserEdit() | |
| 2031 self.assertTrue(desc.tbr) | |
| 2032 self.assertEquals(desc.reviewers, ['joe@example.com']) | |
| 2033 self.assertEquals(desc.description, | |
| 2034 'foo\n' | |
| 2035 '\n' | |
| 2036 'TBR=joe@example.com') | |
| 2037 | |
| 2038 def test_tbr_without_reviewer(self): | |
| 2039 desc = self.change_desc(subject='foo', tbr=True) | |
| 2040 desc.UserEdit() | |
| 2041 self.assertEquals(desc.description, 'foo\n\nTBR=') | |
| 2042 | |
| 2043 def test_really_long_subject(self): | |
| 2044 subject = 'foo' * 40 | |
| 2045 desc = self.change_desc(subject=subject) | |
| 2046 self.assertEquals(desc.description, subject) | |
| 2047 self.assertEquals(desc.subject, subject[:97] + '...') | |
| 2048 | |
| 2049 | |
| 1974 if __name__ == '__main__': | 2050 if __name__ == '__main__': |
| 1975 import unittest | 2051 import unittest |
| 1976 unittest.main() | 2052 unittest.main() |
| OLD | NEW |