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

Side by Side Diff: tests/presubmit_unittest.py

Issue 115881: warnings.catch_warnings() is only available on python 2.5 (Closed)
Patch Set: Created 11 years, 6 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 | « no previous file | 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/python 1 #!/usr/bin/python
2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2006-2009 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 import os 8 import os
9 import StringIO 9 import StringIO
10 import sys 10 import sys
11 import unittest 11 import unittest
12 import warnings 12 import warnings
13 13
14 # Local imports 14 # Local imports
15 import gcl 15 import gcl
16 import gclient 16 import gclient
17 import presubmit_support as presubmit 17 import presubmit_support as presubmit
18 import presubmit_canned_checks 18 import presubmit_canned_checks
19 19
20 20
21 class PresubmitTestsBase(unittest.TestCase): 21 class PresubmitTestsBase(unittest.TestCase):
22 """Setups and tear downs the mocks but doesn't test anything as-is.""" 22 """Setups and tear downs the mocks but doesn't test anything as-is."""
23 def setUp(self): 23 def setUp(self):
24 self._warnings_stack = warnings.catch_warnings() 24 if hasattr(warnings, 'catch_warnings'):
25 self._warnings_stack = warnings.catch_warnings()
26 else:
27 self._warnings_stack = None
28
25 warnings.simplefilter("ignore", DeprecationWarning) 29 warnings.simplefilter("ignore", DeprecationWarning)
26 self.original_IsFile = os.path.isfile 30 self.original_IsFile = os.path.isfile
27 def MockIsFile(f): 31 def MockIsFile(f):
28 dir = os.path.dirname(f) 32 dir = os.path.dirname(f)
29 return dir.endswith('haspresubmit') or dir == '' 33 return dir.endswith('haspresubmit') or dir == ''
30 os.path.isfile = MockIsFile 34 os.path.isfile = MockIsFile
31 35
32 self.original_CaptureSVNInfo = gclient.CaptureSVNInfo 36 self.original_CaptureSVNInfo = gclient.CaptureSVNInfo
33 def MockCaptureSVNInfo(path): 37 def MockCaptureSVNInfo(path):
34 if path.count('notfound'): 38 if path.count('notfound'):
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 # TODO(maruel): Add real tests. 794 # TODO(maruel): Add real tests.
791 self.failIf(presubmit_canned_checks.RunPythonUnitTests( 795 self.failIf(presubmit_canned_checks.RunPythonUnitTests(
792 self.MockInputApi(), 796 self.MockInputApi(),
793 presubmit.OutputApi, [])) 797 presubmit.OutputApi, []))
794 self.failUnless(presubmit_canned_checks.RunPythonUnitTests( 798 self.failUnless(presubmit_canned_checks.RunPythonUnitTests(
795 self.MockInputApi(), 799 self.MockInputApi(),
796 presubmit.OutputApi, ['non_existent_module'])) 800 presubmit.OutputApi, ['non_existent_module']))
797 801
798 if __name__ == '__main__': 802 if __name__ == '__main__':
799 unittest.main() 803 unittest.main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698