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', 'fix_encoding', 'fnmatch', 'gclient_utils', 'glob', 'json', | 145 'exceptions', 'fix_encoding', 'fnmatch', 'gclient_utils', 'glob', 'json', |
145 'load_files', | 146 'load_files', |
146 'logging', 'marshal', 'normpath', 'optparse', 'os', 'owners', 'pickle', | 147 'logging', 'marshal', 'normpath', 'optparse', 'os', 'owners', 'pickle', |
147 'presubmit_canned_checks', 'random', 're', 'scm', 'subprocess', | 148 'presubmit_canned_checks', 'random', 're', 'scm', 'subprocess', |
148 'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2', | 149 'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2', |
149 'warn', | 150 'warn', |
(...skipping 1847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1997 def testCannedCheckOwners_WithoutOwnerLGTM(self): | 1998 def testCannedCheckOwners_WithoutOwnerLGTM(self): |
1998 self.AssertOwnersWorks(uncovered_files=set(['foo.cc']), | 1999 self.AssertOwnersWorks(uncovered_files=set(['foo.cc']), |
1999 expected_output='Missing LGTM from an OWNER for: foo.cc\n') | 2000 expected_output='Missing LGTM from an OWNER for: foo.cc\n') |
2000 | 2001 |
2001 def testCannedCheckOwners_WithLGTMs(self): | 2002 def testCannedCheckOwners_WithLGTMs(self): |
2002 self.AssertOwnersWorks(approvers=set(['ben@example.com']), | 2003 self.AssertOwnersWorks(approvers=set(['ben@example.com']), |
2003 uncovered_files=set()) | 2004 uncovered_files=set()) |
2004 | 2005 |
2005 | 2006 |
2006 | 2007 |
| 2008 def change_desc(editor=None, **kwargs): |
| 2009 if editor is None: |
| 2010 editor = lambda x: x |
| 2011 return presubmit.ChangeDescription(editor=editor, **kwargs) |
| 2012 |
| 2013 |
| 2014 class ChangeDescriptionTests(unittest.TestCase): |
| 2015 def setUp(self): |
| 2016 self.editor_input = None |
| 2017 self.editor_output = None |
| 2018 |
| 2019 def tearDown(self): |
| 2020 self.editor_input = None |
| 2021 self.editor_output = None |
| 2022 |
| 2023 def editor(self, text): |
| 2024 if self.editor_input: |
| 2025 self.assertTrue(self.editor_input in text) |
| 2026 if self.editor_output is not None: |
| 2027 return self.editor_output |
| 2028 return text |
| 2029 |
| 2030 def test_empty(self): |
| 2031 desc = change_desc() |
| 2032 self.assertTrue(desc.IsEmpty()) |
| 2033 desc.UserEdit() |
| 2034 self.assertTrue(desc.IsEmpty()) |
| 2035 |
| 2036 def test_basic(self): |
| 2037 desc = change_desc(subject='foo', description='desc', |
| 2038 reviewers=['joe@example.com']) |
| 2039 desc.UserEdit() |
| 2040 self.assertFalse(desc.IsEmpty()) |
| 2041 self.assertEqual(desc.subject, 'foo') |
| 2042 self.assertEquals(desc.description, |
| 2043 'foo\n' |
| 2044 '\n' |
| 2045 'desc\n' |
| 2046 '\n' |
| 2047 'R=joe@example.com') |
| 2048 self.assertEquals(desc.reviewers, ['joe@example.com']) |
| 2049 self.assertFalse(desc.tbr) |
| 2050 |
| 2051 def test_subject_only(self): |
| 2052 self.editor_input = 'foo\n\nR=\nBUG=\nTEST=\n' |
| 2053 desc = change_desc(subject='foo', editor=self.editor) |
| 2054 desc.UserEdit() |
| 2055 self.assertEquals(desc.description, 'foo') |
| 2056 |
| 2057 def test_tbr_with_reviewer(self): |
| 2058 self.editor_input = 'TBR=\nBUG=\nTEST=\n' |
| 2059 self.editor_output = 'foo\n\nTBR=joe@example.com' |
| 2060 desc = change_desc(tbr=True, editor=self.editor) |
| 2061 self.assertFalse(desc.tbr) |
| 2062 self.assertEquals(desc.reviewers, []) |
| 2063 desc.UserEdit() |
| 2064 self.assertTrue(desc.tbr) |
| 2065 self.assertEquals(desc.reviewers, ['joe@example.com']) |
| 2066 self.assertEquals(desc.description, |
| 2067 'foo\n' |
| 2068 '\n' |
| 2069 'TBR=joe@example.com') |
| 2070 |
| 2071 def test_tbr_without_reviewer(self): |
| 2072 desc = change_desc(subject='foo', tbr=True) |
| 2073 desc.UserEdit() |
| 2074 self.assertEquals(desc.description, 'foo\n\nTBR=') |
| 2075 |
| 2076 def test_really_long_subject(self): |
| 2077 subject = 'foo' * 40 |
| 2078 desc = change_desc(subject=subject) |
| 2079 self.assertEquals(desc.description, subject) |
| 2080 self.assertEquals(desc.subject, subject[:97] + '...') |
| 2081 |
| 2082 |
2007 if __name__ == '__main__': | 2083 if __name__ == '__main__': |
2008 import unittest | 2084 import unittest |
2009 unittest.main() | 2085 unittest.main() |
OLD | NEW |