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