| 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=E1101,E1103,W0403 | 
| 9 | 9 | 
| 10 # Import before super_mox to keep valid references. | 10 # Import before super_mox to keep valid references. | 
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 58     gclient_scm.scm.SVN.current_version = None | 58     gclient_scm.scm.SVN.current_version = None | 
| 59     # Absolute path of the fake checkout directory. | 59     # Absolute path of the fake checkout directory. | 
| 60     self.base_path = join(self.root_dir, self.relpath) | 60     self.base_path = join(self.root_dir, self.relpath) | 
| 61 | 61 | 
| 62   def tearDown(self): | 62   def tearDown(self): | 
| 63     SuperMoxTestBase.tearDown(self) | 63     SuperMoxTestBase.tearDown(self) | 
| 64 | 64 | 
| 65 | 65 | 
| 66 class SVNWrapperTestCase(BaseTestCase): | 66 class SVNWrapperTestCase(BaseTestCase): | 
| 67   class OptionsObject(object): | 67   class OptionsObject(object): | 
| 68     def __init__(self, verbose=False, revision=None): | 68     def __init__(self, verbose=False, revision=None, force=False): | 
| 69       self.verbose = verbose | 69       self.verbose = verbose | 
| 70       self.revision = revision | 70       self.revision = revision | 
| 71       self.manually_grab_svn_rev = True | 71       self.manually_grab_svn_rev = True | 
| 72       self.deps_os = None | 72       self.deps_os = None | 
| 73       self.force = False | 73       self.force = force | 
| 74       self.reset = False | 74       self.reset = False | 
| 75       self.nohooks = False | 75       self.nohooks = False | 
| 76 | 76 | 
| 77   def Options(self, *args, **kwargs): | 77   def Options(self, *args, **kwargs): | 
| 78     return self.OptionsObject(*args, **kwargs) | 78     return self.OptionsObject(*args, **kwargs) | 
| 79 | 79 | 
| 80   def setUp(self): | 80   def setUp(self): | 
| 81     BaseTestCase.setUp(self) | 81     BaseTestCase.setUp(self) | 
| 82     self.url = self.SvnUrl() | 82     self.url = self.SvnUrl() | 
| 83 | 83 | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 125     self.assertRaisesError(exception, scm.RunCommand, | 125     self.assertRaisesError(exception, scm.RunCommand, | 
| 126                            'update', options, self.args) | 126                            'update', options, self.args) | 
| 127 | 127 | 
| 128   def testRunCommandUnknown(self): | 128   def testRunCommandUnknown(self): | 
| 129     # TODO(maruel): if ever used. | 129     # TODO(maruel): if ever used. | 
| 130     pass | 130     pass | 
| 131 | 131 | 
| 132   def testRevertMissing(self): | 132   def testRevertMissing(self): | 
| 133     options = self.Options(verbose=True) | 133     options = self.Options(verbose=True) | 
| 134     gclient_scm.os.path.isdir(self.base_path).AndReturn(False) | 134     gclient_scm.os.path.isdir(self.base_path).AndReturn(False) | 
|  | 135     gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 
| 135     gclient_scm.scm.SVN.Capture(['--version'] | 136     gclient_scm.scm.SVN.Capture(['--version'] | 
| 136         ).AndReturn('svn, version 1.5.1 (r32289)') | 137         ).AndReturn('svn, version 1.5.1 (r32289)') | 
| 137     # It'll to a checkout instead. | 138     # It'll to a checkout instead. | 
| 138     gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | 139     gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | 
| 139     gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 140     gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 
| 140     # Checkout. | 141     # Checkout. | 
| 141     gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 142     gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 
| 142     files_list = self.mox.CreateMockAnything() | 143     files_list = self.mox.CreateMockAnything() | 
| 143     gclient_scm.scm.SVN.RunAndGetFileList( | 144     gclient_scm.scm.SVN.RunAndGetFileList( | 
| 144         options.verbose, | 145         options.verbose, | 
| 145         ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], | 146         ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], | 
| 146         cwd=self.root_dir, | 147         cwd=self.root_dir, | 
| 147         file_list=files_list) | 148         file_list=files_list) | 
| 148 | 149 | 
| 149     self.mox.ReplayAll() | 150     self.mox.ReplayAll() | 
| 150     scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 151     scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 
| 151                             relpath=self.relpath) | 152                             relpath=self.relpath) | 
| 152     scm.revert(options, self.args, files_list) | 153     scm.revert(options, self.args, files_list) | 
| 153     self.checkstdout( | 154     self.checkstdout( | 
| 154         ('\n_____ %s is missing, synching instead\n' % self.relpath)) | 155         ('\n_____ %s is missing, synching instead\n' % self.relpath)) | 
| 155 | 156 | 
|  | 157   def testRevertNoDotSvn(self): | 
|  | 158     options = self.Options(verbose=True, force=True) | 
|  | 159     gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 
|  | 160     gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(False) | 
|  | 161     gclient_scm.os.path.isdir(join(self.base_path, '.git')).AndReturn(False) | 
|  | 162     gclient_scm.os.path.isdir(join(self.base_path, '.hg')).AndReturn(False) | 
|  | 163     # Checkout. | 
|  | 164     gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 
|  | 165     gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | 
|  | 166     gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 
|  | 167     gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 
|  | 168     files_list = self.mox.CreateMockAnything() | 
|  | 169     gclient_scm.scm.SVN.Capture(['--version']).AndReturn('svn, version 1.6') | 
|  | 170     gclient_scm.scm.SVN.RunAndGetFileList( | 
|  | 171         options.verbose, | 
|  | 172         ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], | 
|  | 173         cwd=self.root_dir, | 
|  | 174         file_list=files_list) | 
|  | 175 | 
|  | 176     self.mox.ReplayAll() | 
|  | 177     scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 
|  | 178                             relpath=self.relpath) | 
|  | 179     scm.revert(options, self.args, files_list) | 
|  | 180     self.checkstdout( | 
|  | 181         '\n_____ %s is not a valid svn checkout, synching instead\n' % | 
|  | 182         self.relpath) | 
|  | 183 | 
| 156   def testRevertNone(self): | 184   def testRevertNone(self): | 
| 157     options = self.Options(verbose=True) | 185     options = self.Options(verbose=True) | 
| 158     gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 186     gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 
|  | 187     gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(True) | 
| 159     gclient_scm.scm.SVN.CaptureStatus(self.base_path).AndReturn([]) | 188     gclient_scm.scm.SVN.CaptureStatus(self.base_path).AndReturn([]) | 
| 160     gclient_scm.scm.SVN.RunAndGetFileList( | 189     gclient_scm.scm.SVN.RunAndGetFileList( | 
| 161         options.verbose, | 190         options.verbose, | 
| 162         ['update', '--revision', 'BASE', '--ignore-externals'], | 191         ['update', '--revision', 'BASE', '--ignore-externals'], | 
| 163         cwd=self.base_path, | 192         cwd=self.base_path, | 
| 164         file_list=mox.IgnoreArg()) | 193         file_list=mox.IgnoreArg()) | 
| 165 | 194 | 
| 166     self.mox.ReplayAll() | 195     self.mox.ReplayAll() | 
| 167     scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 196     scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 
| 168                             relpath=self.relpath) | 197                             relpath=self.relpath) | 
| 169     file_list = [] | 198     file_list = [] | 
| 170     scm.revert(options, self.args, file_list) | 199     scm.revert(options, self.args, file_list) | 
| 171 | 200 | 
| 172   def testRevertDirectory(self): | 201   def testRevertDirectory(self): | 
| 173     options = self.Options(verbose=True) | 202     options = self.Options(verbose=True) | 
| 174     gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 203     gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 
|  | 204     gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(True) | 
| 175     items = [ | 205     items = [ | 
| 176       ('~      ', 'a'), | 206       ('~      ', 'a'), | 
| 177     ] | 207     ] | 
| 178     gclient_scm.scm.SVN.CaptureStatus(self.base_path).AndReturn(items) | 208     gclient_scm.scm.SVN.CaptureStatus(self.base_path).AndReturn(items) | 
| 179     file_path = join(self.base_path, 'a') | 209     file_path = join(self.base_path, 'a') | 
| 180     gclient_scm.os.path.exists(file_path).AndReturn(True) | 210     gclient_scm.os.path.exists(file_path).AndReturn(True) | 
| 181     gclient_scm.os.path.isfile(file_path).AndReturn(False) | 211     gclient_scm.os.path.isfile(file_path).AndReturn(False) | 
| 182     gclient_scm.os.path.islink(file_path).AndReturn(False) | 212     gclient_scm.os.path.islink(file_path).AndReturn(False) | 
| 183     gclient_scm.os.path.isdir(file_path).AndReturn(True) | 213     gclient_scm.os.path.isdir(file_path).AndReturn(True) | 
| 184     gclient_scm.gclient_utils.RemoveDirectory(file_path) | 214     gclient_scm.gclient_utils.RemoveDirectory(file_path) | 
| (...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 889 | 919 | 
| 890 if __name__ == '__main__': | 920 if __name__ == '__main__': | 
| 891   if '-v' in sys.argv: | 921   if '-v' in sys.argv: | 
| 892     logging.basicConfig( | 922     logging.basicConfig( | 
| 893         level=logging.DEBUG, | 923         level=logging.DEBUG, | 
| 894         format='%(asctime).19s %(levelname)s %(filename)s:' | 924         format='%(asctime).19s %(levelname)s %(filename)s:' | 
| 895                '%(lineno)s %(message)s') | 925                '%(lineno)s %(message)s') | 
| 896   unittest.main() | 926   unittest.main() | 
| 897 | 927 | 
| 898 # vim: ts=2:sw=2:tw=80:et: | 928 # vim: ts=2:sw=2:tw=80:et: | 
| OLD | NEW | 
|---|