| 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 gclient_scm.py.""" | 6 """Unit tests for gclient_scm.py.""" |
| 7 | 7 |
| 8 # pylint: disable=E1101,E1103,W0403 | 8 # pylint: disable=E1103 |
| 9 | 9 |
| 10 # Import before super_mox to keep valid references. | 10 # Import before super_mox to keep valid references. |
| 11 from os import rename | 11 from os import rename |
| 12 from shutil import rmtree | 12 from shutil import rmtree |
| 13 from subprocess import Popen, PIPE, STDOUT | 13 from subprocess import Popen, PIPE, STDOUT |
| 14 |
| 15 import logging |
| 16 import os |
| 17 import sys |
| 14 import tempfile | 18 import tempfile |
| 15 import unittest | 19 import unittest |
| 16 import __builtin__ | 20 import __builtin__ |
| 17 | 21 |
| 18 # Fixes include path. | 22 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 19 from super_mox import mox, StdoutCheck, TestCaseUtils, SuperMoxTestBase | |
| 20 | 23 |
| 21 import logging | 24 from super_mox import mox, StdoutCheck, SuperMoxTestBase |
| 22 import sys | 25 from super_mox import TestCaseUtils |
| 26 |
| 23 import gclient_scm | 27 import gclient_scm |
| 24 import subprocess2 | 28 import subprocess2 |
| 25 | 29 |
| 26 # Shortcut since this function is used often | 30 # Shortcut since this function is used often |
| 27 join = gclient_scm.os.path.join | 31 join = gclient_scm.os.path.join |
| 28 | 32 |
| 29 | 33 |
| 30 class GCBaseTestCase(object): | 34 class GCBaseTestCase(object): |
| 31 def assertRaisesError(self, msg, fn, *args, **kwargs): | 35 def assertRaisesError(self, msg, fn, *args, **kwargs): |
| 32 """Like unittest's assertRaises() but checks for Gclient.Error.""" | 36 """Like unittest's assertRaises() but checks for Gclient.Error.""" |
| 37 # pylint: disable=E1101 |
| 33 try: | 38 try: |
| 34 fn(*args, **kwargs) | 39 fn(*args, **kwargs) |
| 35 except gclient_scm.gclient_utils.Error, e: | 40 except gclient_scm.gclient_utils.Error, e: |
| 36 self.assertEquals(e.args[0], msg) | 41 self.assertEquals(e.args[0], msg) |
| 37 else: | 42 else: |
| 38 self.fail('%s not raised' % msg) | 43 self.fail('%s not raised' % msg) |
| 39 | 44 |
| 40 | 45 |
| 41 class BaseTestCase(GCBaseTestCase, SuperMoxTestBase): | 46 class BaseTestCase(GCBaseTestCase, SuperMoxTestBase): |
| 42 def setUp(self): | 47 def setUp(self): |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 items = [ | 250 items = [ |
| 246 ('~ ', '.'), | 251 ('~ ', '.'), |
| 247 ] | 252 ] |
| 248 gclient_scm.scm.SVN.CaptureStatus(self.base_path).AndReturn(items) | 253 gclient_scm.scm.SVN.CaptureStatus(self.base_path).AndReturn(items) |
| 249 file_path = join(self.base_path, '.') | 254 file_path = join(self.base_path, '.') |
| 250 gclient_scm.os.path.exists(file_path).AndReturn(True) | 255 gclient_scm.os.path.exists(file_path).AndReturn(True) |
| 251 gclient_scm.os.path.isfile(file_path).AndReturn(False) | 256 gclient_scm.os.path.isfile(file_path).AndReturn(False) |
| 252 gclient_scm.os.path.islink(file_path).AndReturn(False) | 257 gclient_scm.os.path.islink(file_path).AndReturn(False) |
| 253 gclient_scm.os.path.isdir(file_path).AndReturn(True) | 258 gclient_scm.os.path.isdir(file_path).AndReturn(True) |
| 254 gclient_scm.gclient_utils.RemoveDirectory(file_path) | 259 gclient_scm.gclient_utils.RemoveDirectory(file_path) |
| 260 # pylint: disable=E1120 |
| 255 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) | 261 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) |
| 256 # The mock is unbound so self is not necessary. | |
| 257 # pylint: disable=E1120 | |
| 258 gclient_scm.SVNWrapper.update(options, [], ['.']) | 262 gclient_scm.SVNWrapper.update(options, [], ['.']) |
| 259 | 263 |
| 260 self.mox.ReplayAll() | 264 self.mox.ReplayAll() |
| 261 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 265 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 262 relpath=self.relpath) | 266 relpath=self.relpath) |
| 263 file_list2 = [] | 267 file_list2 = [] |
| 264 scm.revert(options, self.args, file_list2) | 268 scm.revert(options, self.args, file_list2) |
| 265 self.checkstdout(('%s\n' % file_path)) | 269 self.checkstdout(('%s\n' % file_path)) |
| 266 | 270 |
| 267 def testStatus(self): | 271 def testStatus(self): |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 962 | 966 |
| 963 if __name__ == '__main__': | 967 if __name__ == '__main__': |
| 964 if '-v' in sys.argv: | 968 if '-v' in sys.argv: |
| 965 logging.basicConfig( | 969 logging.basicConfig( |
| 966 level=logging.DEBUG, | 970 level=logging.DEBUG, |
| 967 format='%(asctime).19s %(levelname)s %(filename)s:' | 971 format='%(asctime).19s %(levelname)s %(filename)s:' |
| 968 '%(lineno)s %(message)s') | 972 '%(lineno)s %(message)s') |
| 969 unittest.main() | 973 unittest.main() |
| 970 | 974 |
| 971 # vim: ts=2:sw=2:tw=80:et: | 975 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |