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 1997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2008 | 2008 |
2009 def testCannedRunUnitTests(self): | 2009 def testCannedRunUnitTests(self): |
2010 change = presubmit.Change( | 2010 change = presubmit.Change( |
2011 'foo1', 'description1', self.fake_root_dir, None, 0, 0) | 2011 'foo1', 'description1', self.fake_root_dir, None, 0, 0) |
2012 input_api = self.MockInputApi(change, False) | 2012 input_api = self.MockInputApi(change, False) |
2013 input_api.verbose = True | 2013 input_api.verbose = True |
2014 unit_tests = ['allo', 'bar.py'] | 2014 unit_tests = ['allo', 'bar.py'] |
2015 input_api.PresubmitLocalPath().AndReturn(self.fake_root_dir) | 2015 input_api.PresubmitLocalPath().AndReturn(self.fake_root_dir) |
2016 input_api.PresubmitLocalPath().AndReturn(self.fake_root_dir) | 2016 input_api.PresubmitLocalPath().AndReturn(self.fake_root_dir) |
2017 input_api.subprocess.check_call( | 2017 input_api.subprocess.check_call( |
2018 ['allo'], cwd=self.fake_root_dir) | 2018 ['allo', '--verbose'], cwd=self.fake_root_dir) |
2019 cmd = ['bar.py'] | 2019 cmd = ['bar.py', '--verbose'] |
2020 if input_api.platform == 'win32': | 2020 if input_api.platform == 'win32': |
2021 cmd.insert(0, input_api.python_executable) | 2021 cmd.insert(0, input_api.python_executable) |
2022 input_api.subprocess.check_call( | 2022 input_api.subprocess.check_call( |
2023 cmd, cwd=self.fake_root_dir).AndRaise( | 2023 cmd, cwd=self.fake_root_dir).AndRaise( |
2024 input_api.subprocess.CalledProcessError()) | 2024 input_api.subprocess.CalledProcessError()) |
2025 | 2025 |
2026 self.mox.ReplayAll() | 2026 self.mox.ReplayAll() |
2027 results = presubmit_canned_checks.RunUnitTests( | 2027 results = presubmit_canned_checks.RunUnitTests( |
2028 input_api, | 2028 input_api, |
2029 presubmit.OutputApi, | 2029 presubmit.OutputApi, |
2030 unit_tests) | 2030 unit_tests) |
2031 self.assertEqual(1, len(results)) | 2031 self.assertEqual(1, len(results)) |
2032 self.assertEqual( | 2032 self.assertEqual( |
2033 presubmit.OutputApi.PresubmitPromptWarning, results[0].__class__) | 2033 presubmit.OutputApi.PresubmitPromptWarning, results[0].__class__) |
2034 self.checkstdout('Running allo\nRunning bar.py\n') | 2034 self.checkstdout('Running allo\nRunning bar.py\n') |
2035 | 2035 |
2036 def testCannedRunUnitTestsInDirectory(self): | 2036 def testCannedRunUnitTestsInDirectory(self): |
2037 change = presubmit.Change( | 2037 change = presubmit.Change( |
2038 'foo1', 'description1', self.fake_root_dir, None, 0, 0) | 2038 'foo1', 'description1', self.fake_root_dir, None, 0, 0) |
2039 input_api = self.MockInputApi(change, False) | 2039 input_api = self.MockInputApi(change, False) |
2040 input_api.verbose = True | 2040 input_api.verbose = True |
2041 input_api.PresubmitLocalPath().AndReturn(self.fake_root_dir) | 2041 input_api.PresubmitLocalPath().AndReturn(self.fake_root_dir) |
2042 input_api.PresubmitLocalPath().AndReturn(self.fake_root_dir) | 2042 input_api.PresubmitLocalPath().AndReturn(self.fake_root_dir) |
2043 path = presubmit.os.path.join(self.fake_root_dir, 'random_directory') | 2043 path = presubmit.os.path.join(self.fake_root_dir, 'random_directory') |
2044 input_api.os_listdir(path).AndReturn(['.', '..', 'a', 'b', 'c']) | 2044 input_api.os_listdir(path).AndReturn(['.', '..', 'a', 'b', 'c']) |
2045 input_api.os_path.isfile = lambda x: not x.endswith('.') | 2045 input_api.os_path.isfile = lambda x: not x.endswith('.') |
2046 input_api.subprocess.check_call( | 2046 input_api.subprocess.check_call( |
2047 [presubmit.os.path.join('random_directory', 'b')], | 2047 [presubmit.os.path.join('random_directory', 'b'), '--verbose'], |
2048 cwd=self.fake_root_dir) | 2048 cwd=self.fake_root_dir) |
2049 | 2049 |
2050 self.mox.ReplayAll() | 2050 self.mox.ReplayAll() |
2051 results = presubmit_canned_checks.RunUnitTestsInDirectory( | 2051 results = presubmit_canned_checks.RunUnitTestsInDirectory( |
2052 input_api, | 2052 input_api, |
2053 presubmit.OutputApi, | 2053 presubmit.OutputApi, |
2054 'random_directory', | 2054 'random_directory', |
2055 whitelist=['^a$', '^b$'], | 2055 whitelist=['^a$', '^b$'], |
2056 blacklist=['a']) | 2056 blacklist=['a']) |
2057 self.assertEqual(results, []) | 2057 self.assertEqual(results, []) |
2058 self.checkstdout( | 2058 self.checkstdout( |
2059 'Running %s\n' % presubmit.os.path.join('random_directory', 'b')) | 2059 'Running %s\n' % presubmit.os.path.join('random_directory', 'b')) |
2060 | 2060 |
2061 | 2061 |
2062 if __name__ == '__main__': | 2062 if __name__ == '__main__': |
2063 import unittest | 2063 import unittest |
2064 unittest.main() | 2064 unittest.main() |
OLD | NEW |