Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1874 'CheckChangeSvnEolStyle', | 1874 'CheckChangeSvnEolStyle', |
| 1875 'CheckChangeWasUploaded', | 1875 'CheckChangeWasUploaded', |
| 1876 'CheckDoNotSubmit', | 1876 'CheckDoNotSubmit', |
| 1877 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', | 1877 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', |
| 1878 'CheckLongLines', 'CheckTreeIsOpen', 'PanProjectChecks', | 1878 'CheckLongLines', 'CheckTreeIsOpen', 'PanProjectChecks', |
| 1879 'CheckLicense', | 1879 'CheckLicense', |
| 1880 'CheckOwners', | 1880 'CheckOwners', |
| 1881 'CheckPatchFormatted', | 1881 'CheckPatchFormatted', |
| 1882 'CheckGNFormatted', | 1882 'CheckGNFormatted', |
| 1883 'CheckRietveldTryJobExecution', | 1883 'CheckRietveldTryJobExecution', |
| 1884 'CheckSingletonInHeaders', | |
| 1885 'CheckSvnModifiedDirectories', | 1884 'CheckSvnModifiedDirectories', |
| 1886 'CheckSvnForCommonMimeTypes', 'CheckSvnProperty', | 1885 'CheckSvnForCommonMimeTypes', 'CheckSvnProperty', |
| 1887 'RunPythonUnitTests', 'RunPylint', | 1886 'RunPythonUnitTests', 'RunPylint', |
| 1888 'RunUnitTests', 'RunUnitTestsInDirectory', | 1887 'RunUnitTests', 'RunUnitTestsInDirectory', |
| 1889 'GetPythonUnitTests', 'GetPylint', | 1888 'GetPythonUnitTests', 'GetPylint', |
| 1890 'GetUnitTests', 'GetUnitTestsInDirectory', 'GetUnitTestsRecursively', | 1889 'GetUnitTests', 'GetUnitTestsInDirectory', 'GetUnitTestsRecursively', |
| 1891 ] | 1890 ] |
| 1892 # If this test fails, you should add the relevant test. | 1891 # If this test fails, you should add the relevant test. |
| 1893 self.compareMembers(presubmit_canned_checks, members) | 1892 self.compareMembers(presubmit_canned_checks, members) |
| 1894 | 1893 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2080 'DO NOTSUBMIT', None, 'DO NOT ' + 'SUBMIT', None, | 2079 'DO NOTSUBMIT', None, 'DO NOT ' + 'SUBMIT', None, |
| 2081 presubmit.OutputApi.PresubmitError) | 2080 presubmit.OutputApi.PresubmitError) |
| 2082 | 2081 |
| 2083 def testCheckChangeHasNoStrayWhitespace(self): | 2082 def testCheckChangeHasNoStrayWhitespace(self): |
| 2084 self.ContentTest( | 2083 self.ContentTest( |
| 2085 lambda x,y,z: | 2084 lambda x,y,z: |
| 2086 presubmit_canned_checks.CheckChangeHasNoStrayWhitespace(x, y), | 2085 presubmit_canned_checks.CheckChangeHasNoStrayWhitespace(x, y), |
| 2087 'Foo', None, 'Foo ', None, | 2086 'Foo', None, 'Foo ', None, |
| 2088 presubmit.OutputApi.PresubmitPromptWarning) | 2087 presubmit.OutputApi.PresubmitPromptWarning) |
| 2089 | 2088 |
| 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): | 2089 def testCheckChangeHasOnlyOneEol(self): |
| 2126 self.ReadFileTest(presubmit_canned_checks.CheckChangeHasOnlyOneEol, | 2090 self.ReadFileTest(presubmit_canned_checks.CheckChangeHasOnlyOneEol, |
| 2127 "Hey!\nHo!\n", "Hey!\nHo!\n\n", | 2091 "Hey!\nHo!\n", "Hey!\nHo!\n\n", |
| 2128 presubmit.OutputApi.PresubmitPromptWarning) | 2092 presubmit.OutputApi.PresubmitPromptWarning) |
| 2129 | 2093 |
| 2130 def testCheckChangeHasNoCR(self): | 2094 def testCheckChangeHasNoCR(self): |
| 2131 self.ReadFileTest(presubmit_canned_checks.CheckChangeHasNoCR, | 2095 self.ReadFileTest(presubmit_canned_checks.CheckChangeHasNoCR, |
| 2132 "Hey!\nHo!\n", "Hey!\r\nHo!\r\n", | 2096 "Hey!\nHo!\n", "Hey!\r\nHo!\r\n", |
| 2133 presubmit.OutputApi.PresubmitPromptWarning) | 2097 presubmit.OutputApi.PresubmitPromptWarning) |
| 2134 | 2098 |
| (...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2867 self.assertEqual( | 2831 self.assertEqual( |
| 2868 presubmit.OutputApi.PresubmitNotifyResult, results[0].__class__) | 2832 presubmit.OutputApi.PresubmitNotifyResult, results[0].__class__) |
| 2869 self.checkstdout('') | 2833 self.checkstdout('') |
| 2870 | 2834 |
| 2871 def testPanProjectChecks(self): | 2835 def testPanProjectChecks(self): |
| 2872 # Make sure it accepts both list and tuples. | 2836 # Make sure it accepts both list and tuples. |
| 2873 change = presubmit.Change( | 2837 change = presubmit.Change( |
| 2874 'foo1', 'description1', self.fake_root_dir, None, 0, 0, None) | 2838 'foo1', 'description1', self.fake_root_dir, None, 0, 0, None) |
| 2875 input_api = self.MockInputApi(change, False) | 2839 input_api = self.MockInputApi(change, False) |
| 2876 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) | 2840 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) |
| 2877 for _ in range(3): | 2841 for _ in range(3): |
|
M-A Ruel
2015/02/18 13:49:40
change 3 to 2.
pymox is such a bag of hurt.
| |
| 2878 input_api.AffectedFiles(file_filter=mox.IgnoreArg(), include_deletes=False | 2842 input_api.AffectedFiles(file_filter=mox.IgnoreArg(), include_deletes=False |
| 2879 ).AndReturn([affected_file]) | 2843 ).AndReturn([affected_file]) |
| 2880 affected_file.LocalPath() | 2844 affected_file.LocalPath() |
| 2881 affected_file.NewContents().AndReturn('Hey!\nHo!\nHey!\nHo!\n\n') | 2845 affected_file.NewContents().AndReturn('Hey!\nHo!\nHey!\nHo!\n\n') |
| 2882 affected_file.ChangedContents().AndReturn([ | 2846 affected_file.ChangedContents().AndReturn([ |
| 2883 (0, 'Hey!\n'), | 2847 (0, 'Hey!\n'), |
| 2884 (1, 'Ho!\n'), | 2848 (1, 'Ho!\n'), |
| 2885 (2, 'Hey!\n'), | 2849 (2, 'Hey!\n'), |
| 2886 (3, 'Ho!\n'), | 2850 (3, 'Ho!\n'), |
| 2887 (4, '\n')]) | 2851 (4, '\n')]) |
| 2888 for _ in range(5): | 2852 for _ in range(5): |
| 2889 affected_file.LocalPath().AndReturn('hello.py') | 2853 affected_file.LocalPath().AndReturn('hello.py') |
| 2890 input_api.AffectedSourceFiles(mox.IgnoreArg()).AndReturn([affected_file]) | 2854 input_api.AffectedSourceFiles(mox.IgnoreArg()).AndReturn([affected_file]) |
|
M-A Ruel
2015/02/18 14:06:46
It was this one in fact, since it's an extraneous
| |
| 2891 input_api.ReadFile(affected_file).AndReturn('Hey!\nHo!\nHey!\nHo!\n\n') | 2855 input_api.ReadFile(affected_file).AndReturn('Hey!\nHo!\nHey!\nHo!\n\n') |
|
M-A Ruel
2015/02/18 16:08:15
Then you need to remove this one too. Basically yo
| |
| 2892 input_api.AffectedSourceFiles(mox.IgnoreArg()).AndReturn([affected_file]) | 2856 input_api.AffectedSourceFiles(mox.IgnoreArg()).AndReturn([affected_file]) |
| 2893 for _ in range(4): | 2857 for _ in range(4): |
| 2894 affected_file.LocalPath().AndReturn('hello.py') | 2858 affected_file.LocalPath().AndReturn('hello.py') |
| 2895 | 2859 |
| 2896 self.mox.ReplayAll() | 2860 self.mox.ReplayAll() |
| 2897 results = presubmit_canned_checks.PanProjectChecks( | 2861 results = presubmit_canned_checks.PanProjectChecks( |
| 2898 input_api, | 2862 input_api, |
| 2899 presubmit.OutputApi, | 2863 presubmit.OutputApi, |
| 2900 excluded_paths=None, | 2864 excluded_paths=None, |
| 2901 text_files=None, | 2865 text_files=None, |
| 2902 license_header=None, | 2866 license_header=None, |
| 2903 project_name=None, | 2867 project_name=None, |
| 2904 owners_check=False) | 2868 owners_check=False) |
| 2905 self.assertEqual(1, len(results)) | 2869 self.assertEqual(1, len(results)) |
| 2906 self.assertEqual( | 2870 self.assertEqual( |
| 2907 'Found line ending with white spaces in:', results[0]._message) | 2871 'Found line ending with white spaces in:', results[0]._message) |
| 2908 self.checkstdout('') | 2872 self.checkstdout('') |
| 2909 | 2873 |
| 2910 | 2874 |
| 2911 if __name__ == '__main__': | 2875 if __name__ == '__main__': |
| 2912 import unittest | 2876 import unittest |
| 2913 unittest.main() | 2877 unittest.main() |
| OLD | NEW |