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

Side by Side Diff: tests/presubmit_unittest.py

Issue 924863002: Remove the Singleton<T> presubmit check from presubmit_canned_checks.py (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Add a deprecation warning Created 5 years, 10 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/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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: disable=E1101,E1103 8 # pylint: disable=E1101,E1103
9 9
10 import functools 10 import functools
(...skipping 2069 matching lines...) Expand 10 before | Expand all | Expand 10 after
2080 'DO NOTSUBMIT', None, 'DO NOT ' + 'SUBMIT', None, 2080 'DO NOTSUBMIT', None, 'DO NOT ' + 'SUBMIT', None,
2081 presubmit.OutputApi.PresubmitError) 2081 presubmit.OutputApi.PresubmitError)
2082 2082
2083 def testCheckChangeHasNoStrayWhitespace(self): 2083 def testCheckChangeHasNoStrayWhitespace(self):
2084 self.ContentTest( 2084 self.ContentTest(
2085 lambda x,y,z: 2085 lambda x,y,z:
2086 presubmit_canned_checks.CheckChangeHasNoStrayWhitespace(x, y), 2086 presubmit_canned_checks.CheckChangeHasNoStrayWhitespace(x, y),
2087 'Foo', None, 'Foo ', None, 2087 'Foo', None, 'Foo ', None,
2088 presubmit.OutputApi.PresubmitPromptWarning) 2088 presubmit.OutputApi.PresubmitPromptWarning)
2089 2089
2090 def testCheckSingletonInHeaders(self):
2091 change1 = presubmit.Change(
2092 'foo1', 'foo1\n', self.fake_root_dir, None, 0, 0, None)
2093 input_api1 = self.MockInputApi(change1, False)
2094 affected_file1 = self.mox.CreateMock(presubmit.SvnAffectedFile)
2095 affected_file2 = self.mox.CreateMock(presubmit.SvnAffectedFile)
2096 input_api1.AffectedSourceFiles(None).AndReturn(
2097 [affected_file1, affected_file2])
2098 affected_file1.LocalPath().AndReturn('foo.h')
2099 input_api1.ReadFile(affected_file1).AndReturn(
2100 '// Comment mentioning Singleton<Foo>.\n' +
2101 'friend class Singleton<Foo>;')
2102 for _ in range(4):
2103 affected_file2.LocalPath().AndReturn('foo.cc')
2104
2105 change2 = presubmit.Change(
2106 'foo2', 'foo2\n', self.fake_root_dir, None, 0, 0, None)
2107 input_api2 = self.MockInputApi(change2, False)
2108
2109 affected_file3 = self.mox.CreateMock(presubmit.SvnAffectedFile)
2110 input_api2.AffectedSourceFiles(None).AndReturn([affected_file3])
2111 affected_file3.LocalPath().AndReturn('foo.h')
2112 input_api2.ReadFile(affected_file3).AndReturn(
2113 'Foo* foo = Singleton<Foo>::get();')
2114
2115 self.mox.ReplayAll()
2116
2117 results1 = presubmit_canned_checks.CheckSingletonInHeaders(
2118 input_api1, presubmit.OutputApi)
2119 self.assertEquals(results1, [])
2120 results2 = presubmit_canned_checks.CheckSingletonInHeaders(
2121 input_api2, presubmit.OutputApi)
2122 self.assertEquals(len(results2), 1)
2123 self.assertEquals(results2[0].__class__, presubmit.OutputApi.PresubmitError)
2124
2125 def testCheckChangeHasOnlyOneEol(self): 2090 def testCheckChangeHasOnlyOneEol(self):
2126 self.ReadFileTest(presubmit_canned_checks.CheckChangeHasOnlyOneEol, 2091 self.ReadFileTest(presubmit_canned_checks.CheckChangeHasOnlyOneEol,
2127 "Hey!\nHo!\n", "Hey!\nHo!\n\n", 2092 "Hey!\nHo!\n", "Hey!\nHo!\n\n",
2128 presubmit.OutputApi.PresubmitPromptWarning) 2093 presubmit.OutputApi.PresubmitPromptWarning)
2129 2094
2130 def testCheckChangeHasNoCR(self): 2095 def testCheckChangeHasNoCR(self):
2131 self.ReadFileTest(presubmit_canned_checks.CheckChangeHasNoCR, 2096 self.ReadFileTest(presubmit_canned_checks.CheckChangeHasNoCR,
2132 "Hey!\nHo!\n", "Hey!\r\nHo!\r\n", 2097 "Hey!\nHo!\n", "Hey!\r\nHo!\r\n",
2133 presubmit.OutputApi.PresubmitPromptWarning) 2098 presubmit.OutputApi.PresubmitPromptWarning)
2134 2099
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
2882 affected_file.ChangedContents().AndReturn([ 2847 affected_file.ChangedContents().AndReturn([
2883 (0, 'Hey!\n'), 2848 (0, 'Hey!\n'),
2884 (1, 'Ho!\n'), 2849 (1, 'Ho!\n'),
2885 (2, 'Hey!\n'), 2850 (2, 'Hey!\n'),
2886 (3, 'Ho!\n'), 2851 (3, 'Ho!\n'),
2887 (4, '\n')]) 2852 (4, '\n')])
2888 for _ in range(5): 2853 for _ in range(5):
2889 affected_file.LocalPath().AndReturn('hello.py') 2854 affected_file.LocalPath().AndReturn('hello.py')
2890 input_api.AffectedSourceFiles(mox.IgnoreArg()).AndReturn([affected_file]) 2855 input_api.AffectedSourceFiles(mox.IgnoreArg()).AndReturn([affected_file])
2891 input_api.ReadFile(affected_file).AndReturn('Hey!\nHo!\nHey!\nHo!\n\n') 2856 input_api.ReadFile(affected_file).AndReturn('Hey!\nHo!\nHey!\nHo!\n\n')
2892 input_api.AffectedSourceFiles(mox.IgnoreArg()).AndReturn([affected_file])
2893 for _ in range(4):
2894 affected_file.LocalPath().AndReturn('hello.py')
2895 2857
2896 self.mox.ReplayAll() 2858 self.mox.ReplayAll()
2897 results = presubmit_canned_checks.PanProjectChecks( 2859 results = presubmit_canned_checks.PanProjectChecks(
2898 input_api, 2860 input_api,
2899 presubmit.OutputApi, 2861 presubmit.OutputApi,
2900 excluded_paths=None, 2862 excluded_paths=None,
2901 text_files=None, 2863 text_files=None,
2902 license_header=None, 2864 license_header=None,
2903 project_name=None, 2865 project_name=None,
2904 owners_check=False) 2866 owners_check=False)
2905 self.assertEqual(1, len(results)) 2867 self.assertEqual(1, len(results))
2906 self.assertEqual( 2868 self.assertEqual(
2907 'Found line ending with white spaces in:', results[0]._message) 2869 'Found line ending with white spaces in:', results[0]._message)
2908 self.checkstdout('') 2870 self.checkstdout('')
2909 2871
2910 2872
2911 if __name__ == '__main__': 2873 if __name__ == '__main__':
2912 import unittest 2874 import unittest
2913 unittest.main() 2875 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