| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # | 2 # |
| 3 # Copyright 2008-2009 Google Inc. All Rights Reserved. | 3 # Copyright 2008-2009 Google Inc. All Rights Reserved. |
| 4 # | 4 # |
| 5 # Licensed under the Apache License, Version 2.0 (the "License"); | 5 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 # you may not use this file except in compliance with the License. | 6 # you may not use this file except in compliance with the License. |
| 7 # You may obtain a copy of the License at | 7 # You may obtain a copy of the License at |
| 8 # | 8 # |
| 9 # http://www.apache.org/licenses/LICENSE-2.0 | 9 # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 # | 10 # |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 def testRevertMissing(self): | 89 def testRevertMissing(self): |
| 90 options = self.Options(verbose=True) | 90 options = self.Options(verbose=True) |
| 91 base_path = os.path.join(self.root_dir, self.relpath) | 91 base_path = os.path.join(self.root_dir, self.relpath) |
| 92 gclient.os.path.isdir(base_path).AndReturn(False) | 92 gclient.os.path.isdir(base_path).AndReturn(False) |
| 93 # It'll to a checkout instead. | 93 # It'll to a checkout instead. |
| 94 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False) | 94 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False) |
| 95 print("\n_____ %s is missing, synching instead" % self.relpath) | 95 print("\n_____ %s is missing, synching instead" % self.relpath) |
| 96 # Checkout. | 96 # Checkout. |
| 97 gclient.os.path.exists(base_path).AndReturn(False) | 97 gclient.os.path.exists(base_path).AndReturn(False) |
| 98 files_list = self.mox.CreateMockAnything() | 98 files_list = self.mox.CreateMockAnything() |
| 99 gclient_scm.RunSVNAndGetFileList(options, ['checkout', self.url, base_path], | 99 gclient_scm.RunSVNAndGetFileList(['checkout', self.url, base_path], |
| 100 self.root_dir, files_list) | 100 self.root_dir, files_list) |
| 101 | 101 |
| 102 self.mox.ReplayAll() | 102 self.mox.ReplayAll() |
| 103 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 103 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 104 relpath=self.relpath) | 104 relpath=self.relpath) |
| 105 scm.revert(options, self.args, files_list) | 105 scm.revert(options, self.args, files_list) |
| 106 | 106 |
| 107 def testRevertNone(self): | 107 def testRevertNone(self): |
| 108 options = self.Options(verbose=True) | 108 options = self.Options(verbose=True) |
| 109 base_path = os.path.join(self.root_dir, self.relpath) | 109 base_path = os.path.join(self.root_dir, self.relpath) |
| 110 gclient.os.path.isdir(base_path).AndReturn(True) | 110 gclient.os.path.isdir(base_path).AndReturn(True) |
| 111 gclient_scm.CaptureSVNStatus(base_path).AndReturn([]) | 111 gclient_scm.CaptureSVNStatus(base_path).AndReturn([]) |
| 112 gclient_scm.RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'], | 112 gclient_scm.RunSVNAndGetFileList(['update', '--revision', 'BASE'], |
| 113 base_path, mox.IgnoreArg()) | 113 base_path, mox.IgnoreArg()) |
| 114 | 114 |
| 115 self.mox.ReplayAll() | 115 self.mox.ReplayAll() |
| 116 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 116 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 117 relpath=self.relpath) | 117 relpath=self.relpath) |
| 118 file_list = [] | 118 file_list = [] |
| 119 scm.revert(options, self.args, file_list) | 119 scm.revert(options, self.args, file_list) |
| 120 | 120 |
| 121 def testRevert2Files(self): | 121 def testRevert2Files(self): |
| 122 options = self.Options(verbose=True) | 122 options = self.Options(verbose=True) |
| 123 base_path = os.path.join(self.root_dir, self.relpath) | 123 base_path = os.path.join(self.root_dir, self.relpath) |
| 124 gclient.os.path.isdir(base_path).AndReturn(True) | 124 gclient.os.path.isdir(base_path).AndReturn(True) |
| 125 items = [ | 125 items = [ |
| 126 ('M ', 'a'), | 126 ('M ', 'a'), |
| 127 ('A ', 'b'), | 127 ('A ', 'b'), |
| 128 ] | 128 ] |
| 129 file_path1 = os.path.join(base_path, 'a') | 129 file_path1 = os.path.join(base_path, 'a') |
| 130 file_path2 = os.path.join(base_path, 'b') | 130 file_path2 = os.path.join(base_path, 'b') |
| 131 gclient_scm.CaptureSVNStatus(base_path).AndReturn(items) | 131 gclient_scm.CaptureSVNStatus(base_path).AndReturn(items) |
| 132 gclient_scm.os.path.exists(file_path1).AndReturn(True) | 132 gclient_scm.os.path.exists(file_path1).AndReturn(True) |
| 133 gclient_scm.os.path.isfile(file_path1).AndReturn(True) | 133 gclient_scm.os.path.isfile(file_path1).AndReturn(True) |
| 134 gclient_scm.os.remove(file_path1) | 134 gclient_scm.os.remove(file_path1) |
| 135 gclient_scm.os.path.exists(file_path2).AndReturn(True) | 135 gclient_scm.os.path.exists(file_path2).AndReturn(True) |
| 136 gclient_scm.os.path.isfile(file_path2).AndReturn(True) | 136 gclient_scm.os.path.isfile(file_path2).AndReturn(True) |
| 137 gclient_scm.os.remove(file_path2) | 137 gclient_scm.os.remove(file_path2) |
| 138 gclient_scm.RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'], | 138 gclient_scm.RunSVNAndGetFileList(['update', '--revision', 'BASE'], |
| 139 base_path, mox.IgnoreArg()) | 139 base_path, mox.IgnoreArg()) |
| 140 print(os.path.join(base_path, 'a')) | 140 print(os.path.join(base_path, 'a')) |
| 141 print(os.path.join(base_path, 'b')) | 141 print(os.path.join(base_path, 'b')) |
| 142 | 142 |
| 143 self.mox.ReplayAll() | 143 self.mox.ReplayAll() |
| 144 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 144 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 145 relpath=self.relpath) | 145 relpath=self.relpath) |
| 146 file_list = [] | 146 file_list = [] |
| 147 scm.revert(options, self.args, file_list) | 147 scm.revert(options, self.args, file_list) |
| 148 | 148 |
| 149 def testRevertDirectory(self): | 149 def testRevertDirectory(self): |
| 150 options = self.Options(verbose=True) | 150 options = self.Options(verbose=True) |
| 151 base_path = os.path.join(self.root_dir, self.relpath) | 151 base_path = os.path.join(self.root_dir, self.relpath) |
| 152 gclient.os.path.isdir(base_path).AndReturn(True) | 152 gclient.os.path.isdir(base_path).AndReturn(True) |
| 153 items = [ | 153 items = [ |
| 154 ('~ ', 'a'), | 154 ('~ ', 'a'), |
| 155 ] | 155 ] |
| 156 gclient_scm.CaptureSVNStatus(base_path).AndReturn(items) | 156 gclient_scm.CaptureSVNStatus(base_path).AndReturn(items) |
| 157 file_path = os.path.join(base_path, 'a') | 157 file_path = os.path.join(base_path, 'a') |
| 158 print(file_path) | 158 print(file_path) |
| 159 gclient_scm.os.path.exists(file_path).AndReturn(True) | 159 gclient_scm.os.path.exists(file_path).AndReturn(True) |
| 160 gclient_scm.os.path.isfile(file_path).AndReturn(False) | 160 gclient_scm.os.path.isfile(file_path).AndReturn(False) |
| 161 gclient_scm.os.path.isdir(file_path).AndReturn(True) | 161 gclient_scm.os.path.isdir(file_path).AndReturn(True) |
| 162 gclient_utils.RemoveDirectory(file_path) | 162 gclient_utils.RemoveDirectory(file_path) |
| 163 file_list1 = [] | 163 file_list1 = [] |
| 164 gclient_scm.RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'], | 164 gclient_scm.RunSVNAndGetFileList(['update', '--revision', 'BASE'], |
| 165 base_path, mox.IgnoreArg()) | 165 base_path, mox.IgnoreArg()) |
| 166 | 166 |
| 167 self.mox.ReplayAll() | 167 self.mox.ReplayAll() |
| 168 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 168 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 169 relpath=self.relpath) | 169 relpath=self.relpath) |
| 170 file_list2 = [] | 170 file_list2 = [] |
| 171 scm.revert(options, self.args, file_list2) | 171 scm.revert(options, self.args, file_list2) |
| 172 | 172 |
| 173 def testStatus(self): | 173 def testStatus(self): |
| 174 options = self.Options(verbose=True) | 174 options = self.Options(verbose=True) |
| 175 base_path = os.path.join(self.root_dir, self.relpath) | 175 base_path = os.path.join(self.root_dir, self.relpath) |
| 176 gclient.os.path.isdir(base_path).AndReturn(True) | 176 gclient.os.path.isdir(base_path).AndReturn(True) |
| 177 gclient_scm.RunSVNAndGetFileList(options, ['status'] + self.args, base_path, | 177 gclient_scm.RunSVNAndGetFileList(['status'] + self.args, base_path, |
| 178 []).AndReturn(None) | 178 []).AndReturn(None) |
| 179 | 179 |
| 180 self.mox.ReplayAll() | 180 self.mox.ReplayAll() |
| 181 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 181 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 182 relpath=self.relpath) | 182 relpath=self.relpath) |
| 183 file_list = [] | 183 file_list = [] |
| 184 self.assertEqual(scm.status(options, self.args, file_list), None) | 184 self.assertEqual(scm.status(options, self.args, file_list), None) |
| 185 | 185 |
| 186 | 186 |
| 187 # TODO(maruel): TEST REVISIONS!!! | 187 # TODO(maruel): TEST REVISIONS!!! |
| 188 # TODO(maruel): TEST RELOCATE!!! | 188 # TODO(maruel): TEST RELOCATE!!! |
| 189 def testUpdateCheckout(self): | 189 def testUpdateCheckout(self): |
| 190 options = self.Options(verbose=True) | 190 options = self.Options(verbose=True) |
| 191 base_path = os.path.join(self.root_dir, self.relpath) | 191 base_path = os.path.join(self.root_dir, self.relpath) |
| 192 file_info = gclient_utils.PrintableObject() | 192 file_info = gclient_utils.PrintableObject() |
| 193 file_info.root = 'blah' | 193 file_info.root = 'blah' |
| 194 file_info.url = self.url | 194 file_info.url = self.url |
| 195 file_info.uuid = 'ABC' | 195 file_info.uuid = 'ABC' |
| 196 file_info.revision = 42 | 196 file_info.revision = 42 |
| 197 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False) | 197 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False) |
| 198 # Checkout. | 198 # Checkout. |
| 199 gclient.os.path.exists(base_path).AndReturn(False) | 199 gclient.os.path.exists(base_path).AndReturn(False) |
| 200 files_list = self.mox.CreateMockAnything() | 200 files_list = self.mox.CreateMockAnything() |
| 201 gclient_scm.RunSVNAndGetFileList(options, ['checkout', self.url, base_path], | 201 gclient_scm.RunSVNAndGetFileList(['checkout', self.url, base_path], |
| 202 self.root_dir, files_list) | 202 self.root_dir, files_list) |
| 203 self.mox.ReplayAll() | 203 self.mox.ReplayAll() |
| 204 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 204 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 205 relpath=self.relpath) | 205 relpath=self.relpath) |
| 206 scm.update(options, (), files_list) | 206 scm.update(options, (), files_list) |
| 207 | 207 |
| 208 def testUpdateUpdate(self): | 208 def testUpdateUpdate(self): |
| 209 options = self.Options(verbose=True) | 209 options = self.Options(verbose=True) |
| 210 base_path = os.path.join(self.root_dir, self.relpath) | 210 base_path = os.path.join(self.root_dir, self.relpath) |
| 211 options.force = True | 211 options.force = True |
| 212 options.nohooks = False | 212 options.nohooks = False |
| 213 file_info = { | 213 file_info = { |
| 214 'Repository Root': 'blah', | 214 'Repository Root': 'blah', |
| 215 'URL': self.url, | 215 'URL': self.url, |
| 216 'UUID': 'ABC', | 216 'UUID': 'ABC', |
| 217 'Revision': 42, | 217 'Revision': 42, |
| 218 } | 218 } |
| 219 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False) | 219 gclient.os.path.exists(os.path.join(base_path, '.git')).AndReturn(False) |
| 220 # Checkout or update. | 220 # Checkout or update. |
| 221 gclient.os.path.exists(base_path).AndReturn(True) | 221 gclient.os.path.exists(base_path).AndReturn(True) |
| 222 gclient_scm.CaptureSVNInfo(os.path.join(base_path, "."), '.' | 222 gclient_scm.CaptureSVNInfo(os.path.join(base_path, "."), '.' |
| 223 ).AndReturn(file_info) | 223 ).AndReturn(file_info) |
| 224 # Cheat a bit here. | 224 # Cheat a bit here. |
| 225 gclient_scm.CaptureSVNInfo(file_info['URL'], '.').AndReturn(file_info) | 225 gclient_scm.CaptureSVNInfo(file_info['URL'], '.').AndReturn(file_info) |
| 226 additional_args = [] | 226 additional_args = [] |
| 227 if options.manually_grab_svn_rev: | 227 if options.manually_grab_svn_rev: |
| 228 additional_args = ['--revision', str(file_info['Revision'])] | 228 additional_args = ['--revision', str(file_info['Revision'])] |
| 229 files_list = [] | 229 files_list = [] |
| 230 gclient_scm.RunSVNAndGetFileList(options, | 230 gclient_scm.RunSVNAndGetFileList(['update', base_path] + additional_args, |
| 231 ['update', base_path] + additional_args, self.root_dir, files_list) | 231 self.root_dir, files_list) |
| 232 | 232 |
| 233 self.mox.ReplayAll() | 233 self.mox.ReplayAll() |
| 234 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 234 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 235 relpath=self.relpath) | 235 relpath=self.relpath) |
| 236 scm.update(options, (), files_list) | 236 scm.update(options, (), files_list) |
| 237 | 237 |
| 238 def testUpdateGit(self): | 238 def testUpdateGit(self): |
| 239 options = self.Options(verbose=True) | 239 options = self.Options(verbose=True) |
| 240 file_path = os.path.join(self.root_dir, self.relpath, '.git') | 240 file_path = os.path.join(self.root_dir, self.relpath, '.git') |
| 241 gclient.os.path.exists(file_path).AndReturn(True) | 241 gclient.os.path.exists(file_path).AndReturn(True) |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 self.mox.StubOutWithMock(gclient_utils, 'SubprocessCall') | 536 self.mox.StubOutWithMock(gclient_utils, 'SubprocessCall') |
| 537 gclient_utils.SubprocessCall(['svn', 'foo', 'bar'], param2).AndReturn(None) | 537 gclient_utils.SubprocessCall(['svn', 'foo', 'bar'], param2).AndReturn(None) |
| 538 self.mox.ReplayAll() | 538 self.mox.ReplayAll() |
| 539 gclient_scm.RunSVN(['foo', 'bar'], param2) | 539 gclient_scm.RunSVN(['foo', 'bar'], param2) |
| 540 | 540 |
| 541 | 541 |
| 542 if __name__ == '__main__': | 542 if __name__ == '__main__': |
| 543 unittest.main() | 543 unittest.main() |
| 544 | 544 |
| 545 # vim: ts=2:sw=2:tw=80:et: | 545 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |