OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 scm.py.""" | 6 """Unit tests for scm.py.""" |
7 | 7 |
8 # pylint: disable=E1101,W0403 | 8 # pylint: disable=E1101,W0403 |
9 | 9 |
10 # Fixes include path. | 10 # Fixes include path. |
11 from super_mox import SuperMoxTestBase | 11 from super_mox import SuperMoxTestBase |
12 | 12 |
| 13 import fake_repos |
13 import scm | 14 import scm |
14 | 15 |
15 | 16 |
16 class BaseTestCase(SuperMoxTestBase): | 17 class BaseTestCase(SuperMoxTestBase): |
17 # Like unittest's assertRaises, but checks for Gclient.Error. | 18 # Like unittest's assertRaises, but checks for Gclient.Error. |
18 def assertRaisesError(self, msg, fn, *args, **kwargs): | 19 def assertRaisesError(self, msg, fn, *args, **kwargs): |
19 try: | 20 try: |
20 fn(*args, **kwargs) | 21 fn(*args, **kwargs) |
21 except scm.gclient_utils.Error, e: | 22 except scm.gclient_utils.Error, e: |
22 self.assertEquals(e.args[0], msg) | 23 self.assertEquals(e.args[0], msg) |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 <target | 234 <target |
234 path="perf"> | 235 path="perf"> |
235 </target> | 236 </target> |
236 </status>""" | 237 </status>""" |
237 scm.SVN.Capture(['status', '--xml']).AndReturn(text) | 238 scm.SVN.Capture(['status', '--xml']).AndReturn(text) |
238 self.mox.ReplayAll() | 239 self.mox.ReplayAll() |
239 info = scm.SVN.CaptureStatus(None) | 240 info = scm.SVN.CaptureStatus(None) |
240 self.assertEquals(info, []) | 241 self.assertEquals(info, []) |
241 | 242 |
242 | 243 |
| 244 class RealSvnTest(fake_repos.FakeReposTestBase): |
| 245 # Tests that work with a checkout. |
| 246 def setUp(self): |
| 247 super(RealSvnTest, self).setUp() |
| 248 self.FAKE_REPOS.setUpSVN() |
| 249 self.svn_root = scm.os.path.join(self.root_dir, 'base') |
| 250 scm.SVN.Capture( |
| 251 ['checkout', self.svn_base + 'trunk/third_party', 'base'], |
| 252 cwd=self.root_dir) |
| 253 self.tree = self.mangle_svn_tree(('trunk/third_party@-1', ''),) |
| 254 |
| 255 def _capture(self, cmd, **kwargs): |
| 256 kwargs.setdefault('cwd', self.svn_root) |
| 257 return scm.SVN.Capture(cmd, **kwargs) |
| 258 |
| 259 def testCheckout(self): |
| 260 # Checkout and verify the tree. |
| 261 self.assertTree(self.tree, self.svn_root) |
| 262 |
| 263 def testRevert(self): |
| 264 # Mess around and make sure revert works for all corner cases. |
| 265 # - svn add a file |
| 266 # - svn add a file and delete it |
| 267 # - Delete a file |
| 268 # - svn delete a file |
| 269 # - svn move a directory and svn rename files in it |
| 270 self._capture(['move', 'foo', 'foo2']) |
| 271 self._capture( |
| 272 ['move', |
| 273 scm.os.path.join('foo2', 'origin'), |
| 274 scm.os.path.join('foo2', 'o')]) |
| 275 scm.os.remove(scm.os.path.join(self.svn_root, 'origin')) |
| 276 self._capture( |
| 277 ['propset', 'foo', 'bar', |
| 278 scm.os.path.join(self.svn_root, 'prout', 'origin')]) |
| 279 fake_repos.rmtree(scm.os.path.join(self.svn_root, 'prout')) |
| 280 with open(scm.os.path.join(self.svn_root, 'faa'), 'w') as f: |
| 281 f.write('eh') |
| 282 with open(scm.os.path.join(self.svn_root, 'faala'), 'w') as f: |
| 283 f.write('oh') |
| 284 self._capture(['add', scm.os.path.join(self.svn_root, 'faala')]) |
| 285 |
| 286 scm.SVN.Revert(self.svn_root) |
| 287 self._capture(['update', '--revision', 'base']) |
| 288 |
| 289 self.assertTree(self.tree, self.svn_root) |
| 290 |
| 291 |
243 if __name__ == '__main__': | 292 if __name__ == '__main__': |
244 import unittest | 293 import unittest |
245 unittest.main() | 294 unittest.main() |
246 | 295 |
247 # vim: ts=2:sw=2:tw=80:et: | 296 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |