| 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 scm.py.""" | 6 """Unit tests for scm.py.""" |
| 7 | 7 |
| 8 from __future__ import with_statement | 8 from __future__ import with_statement |
| 9 import logging | 9 import logging |
| 10 import os | 10 import os |
| 11 import sys | 11 import sys |
| 12 import unittest | 12 import unittest |
| 13 | 13 |
| 14 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | 14 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 15 | 15 |
| 16 from testing_support import fake_repos | 16 from testing_support import fake_repos |
| 17 from testing_support.super_mox import SuperMoxTestBase | 17 from testing_support.super_mox import SuperMoxTestBase |
| 18 | 18 |
| 19 import scm | 19 import scm |
| 20 import subprocess2 | 20 import subprocess2 |
| 21 | 21 |
| 22 | 22 |
| 23 # Access to a protected member XXX of a client class |
| 24 # pylint: disable=W0212 |
| 25 |
| 26 |
| 23 class BaseTestCase(SuperMoxTestBase): | 27 class BaseTestCase(SuperMoxTestBase): |
| 24 # Like unittest's assertRaises, but checks for Gclient.Error. | 28 # Like unittest's assertRaises, but checks for Gclient.Error. |
| 25 def assertRaisesError(self, msg, fn, *args, **kwargs): | 29 def assertRaisesError(self, msg, fn, *args, **kwargs): |
| 26 try: | 30 try: |
| 27 fn(*args, **kwargs) | 31 fn(*args, **kwargs) |
| 28 except scm.gclient_utils.Error, e: | 32 except scm.gclient_utils.Error, e: |
| 29 self.assertEquals(e.args[0], msg) | 33 self.assertEquals(e.args[0], msg) |
| 30 else: | 34 else: |
| 31 self.fail('%s not raised' % msg) | 35 self.fail('%s not raised' % msg) |
| 32 | 36 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 91 |
| 88 class SVNTestCase(BaseSCMTestCase): | 92 class SVNTestCase(BaseSCMTestCase): |
| 89 def setUp(self): | 93 def setUp(self): |
| 90 BaseSCMTestCase.setUp(self) | 94 BaseSCMTestCase.setUp(self) |
| 91 self.mox.StubOutWithMock(scm.SVN, 'Capture') | 95 self.mox.StubOutWithMock(scm.SVN, 'Capture') |
| 92 self.url = self.SvnUrl() | 96 self.url = self.SvnUrl() |
| 93 | 97 |
| 94 def testMembersChanged(self): | 98 def testMembersChanged(self): |
| 95 self.mox.ReplayAll() | 99 self.mox.ReplayAll() |
| 96 members = [ | 100 members = [ |
| 97 'AssertVersion', 'Capture', 'CaptureRevision', 'CaptureInfo', | 101 'AssertVersion', 'Capture', 'CaptureRevision', 'CaptureLocalInfo', |
| 102 'CaptureRemoteInfo', |
| 98 'CaptureStatus', 'current_version', 'DiffItem', 'GenerateDiff', | 103 'CaptureStatus', 'current_version', 'DiffItem', 'GenerateDiff', |
| 99 'GetCheckoutRoot', 'GetEmail', 'GetFileProperty', 'IsMoved', | 104 'GetCheckoutRoot', 'GetEmail', 'GetFileProperty', 'IsMoved', |
| 100 'IsMovedInfo', 'ReadSimpleAuth', 'Revert', 'RunAndGetFileList', | 105 'IsMovedInfo', 'ReadSimpleAuth', 'Revert', 'RunAndGetFileList', |
| 101 ] | 106 ] |
| 102 # If this test fails, you should add the relevant test. | 107 # If this test fails, you should add the relevant test. |
| 103 self.compareMembers(scm.SVN, members) | 108 self.compareMembers(scm.SVN, members) |
| 104 | 109 |
| 105 def testGetCheckoutRoot(self): | 110 def testGetCheckoutRoot(self): |
| 106 # pylint: disable=E1103 | 111 # pylint: disable=E1103 |
| 107 self.mox.StubOutWithMock(scm.SVN, 'CaptureInfo') | 112 self.mox.StubOutWithMock(scm.SVN, '_CaptureInfo') |
| 108 self.mox.StubOutWithMock(scm, 'GetCasedPath') | 113 self.mox.StubOutWithMock(scm, 'GetCasedPath') |
| 109 scm.os.path.abspath = lambda x: x | 114 scm.os.path.abspath = lambda x: x |
| 110 scm.GetCasedPath = lambda x: x | 115 scm.GetCasedPath = lambda x: x |
| 111 scm.SVN.CaptureInfo(self.root_dir + '/foo/bar').AndReturn({ | 116 scm.SVN._CaptureInfo([], self.root_dir + '/foo/bar').AndReturn({ |
| 112 'Repository Root': 'svn://svn.chromium.org/chrome', | 117 'Repository Root': 'svn://svn.chromium.org/chrome', |
| 113 'URL': 'svn://svn.chromium.org/chrome/trunk/src', | 118 'URL': 'svn://svn.chromium.org/chrome/trunk/src', |
| 114 }) | 119 }) |
| 115 scm.SVN.CaptureInfo(self.root_dir + '/foo').AndReturn({ | 120 scm.SVN._CaptureInfo([], self.root_dir + '/foo').AndReturn({ |
| 116 'Repository Root': 'svn://svn.chromium.org/chrome', | 121 'Repository Root': 'svn://svn.chromium.org/chrome', |
| 117 'URL': 'svn://svn.chromium.org/chrome/trunk', | 122 'URL': 'svn://svn.chromium.org/chrome/trunk', |
| 118 }) | 123 }) |
| 119 scm.SVN.CaptureInfo(self.root_dir).AndReturn({ | 124 scm.SVN._CaptureInfo([], self.root_dir).AndReturn({ |
| 120 'Repository Root': 'svn://svn.chromium.org/chrome', | 125 'Repository Root': 'svn://svn.chromium.org/chrome', |
| 121 'URL': 'svn://svn.chromium.org/chrome/trunk/tools/commit-queue/workdir', | 126 'URL': 'svn://svn.chromium.org/chrome/trunk/tools/commit-queue/workdir', |
| 122 }) | 127 }) |
| 123 self.mox.ReplayAll() | 128 self.mox.ReplayAll() |
| 124 self.assertEquals(scm.SVN.GetCheckoutRoot(self.root_dir + '/foo/bar'), | 129 self.assertEquals(scm.SVN.GetCheckoutRoot(self.root_dir + '/foo/bar'), |
| 125 self.root_dir + '/foo') | 130 self.root_dir + '/foo') |
| 126 | 131 |
| 127 def testGetFileInfo(self): | 132 def testGetFileInfo(self): |
| 128 xml_text = r"""<?xml version="1.0"?> | 133 xml_text = r"""<?xml version="1.0"?> |
| 129 <info> | 134 <info> |
| 130 <entry kind="file" path="%s" revision="14628"> | 135 <entry kind="file" path="%s" revision="14628"> |
| 131 <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url> | 136 <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url> |
| 132 <repository><root>http://src.chromium.org/svn</root></repository> | 137 <repository><root>http://src.chromium.org/svn</root></repository> |
| 133 <wc-info> | 138 <wc-info> |
| 134 <schedule>add</schedule> | 139 <schedule>add</schedule> |
| 135 <depth>infinity</depth> | 140 <depth>infinity</depth> |
| 136 <copy-from-url>http://src.chromium.org/svn/trunk/src/chrome/app/DEPS</copy-from-
url> | 141 <copy-from-url>http://src.chromium.org/svn/trunk/src/chrome/app/DEPS</copy-from-
url> |
| 137 <copy-from-rev>14628</copy-from-rev> | 142 <copy-from-rev>14628</copy-from-rev> |
| 138 <checksum>369f59057ba0e6d9017e28f8bdfb1f43</checksum> | 143 <checksum>369f59057ba0e6d9017e28f8bdfb1f43</checksum> |
| 139 </wc-info> | 144 </wc-info> |
| 140 </entry> | 145 </entry> |
| 141 </info> | 146 </info> |
| 142 """ % self.url | 147 """ % self.url |
| 143 scm.SVN.Capture(['info', '--xml', self.url]).AndReturn(xml_text) | 148 scm.SVN.Capture(['info', '--xml', self.url], None).AndReturn(xml_text) |
| 144 expected = { | 149 expected = { |
| 145 'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d', | 150 'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d', |
| 146 'UUID': None, | 151 'UUID': None, |
| 147 'Repository Root': 'http://src.chromium.org/svn', | 152 'Repository Root': 'http://src.chromium.org/svn', |
| 148 'Schedule': 'add', | 153 'Schedule': 'add', |
| 149 'Copied From URL': | 154 'Copied From URL': |
| 150 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS', | 155 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS', |
| 151 'Copied From Rev': '14628', | 156 'Copied From Rev': '14628', |
| 152 'Path': self.url, | 157 'Path': self.url, |
| 153 'Revision': 14628, | 158 'Revision': 14628, |
| 154 'Node Kind': 'file', | 159 'Node Kind': 'file', |
| 155 } | 160 } |
| 156 self.mox.ReplayAll() | 161 self.mox.ReplayAll() |
| 157 file_info = scm.SVN.CaptureInfo(self.url) | 162 file_info = scm.SVN._CaptureInfo([self.url], None) |
| 158 self.assertEquals(sorted(file_info.items()), sorted(expected.items())) | 163 self.assertEquals(sorted(file_info.items()), sorted(expected.items())) |
| 159 | 164 |
| 160 def testCaptureInfo(self): | 165 def testCaptureInfo(self): |
| 161 xml_text = """<?xml version="1.0"?> | 166 xml_text = """<?xml version="1.0"?> |
| 162 <info> | 167 <info> |
| 163 <entry | 168 <entry |
| 164 kind="dir" | 169 kind="dir" |
| 165 path="." | 170 path="." |
| 166 revision="35"> | 171 revision="35"> |
| 167 <url>%s</url> | 172 <url>%s</url> |
| 168 <repository> | 173 <repository> |
| 169 <root>%s</root> | 174 <root>%s</root> |
| 170 <uuid>7b9385f5-0452-0410-af26-ad4892b7a1fb</uuid> | 175 <uuid>7b9385f5-0452-0410-af26-ad4892b7a1fb</uuid> |
| 171 </repository> | 176 </repository> |
| 172 <wc-info> | 177 <wc-info> |
| 173 <schedule>normal</schedule> | 178 <schedule>normal</schedule> |
| 174 <depth>infinity</depth> | 179 <depth>infinity</depth> |
| 175 </wc-info> | 180 </wc-info> |
| 176 <commit | 181 <commit |
| 177 revision="35"> | 182 revision="35"> |
| 178 <author>maruel</author> | 183 <author>maruel</author> |
| 179 <date>2008-12-04T20:12:19.685120Z</date> | 184 <date>2008-12-04T20:12:19.685120Z</date> |
| 180 </commit> | 185 </commit> |
| 181 </entry> | 186 </entry> |
| 182 </info> | 187 </info> |
| 183 """ % (self.url, self.root_dir) | 188 """ % (self.url, self.root_dir) |
| 184 scm.SVN.Capture(['info', '--xml', self.url]).AndReturn(xml_text) | 189 scm.SVN.Capture(['info', '--xml', self.url], None).AndReturn(xml_text) |
| 185 self.mox.ReplayAll() | 190 self.mox.ReplayAll() |
| 186 file_info = scm.SVN.CaptureInfo(self.url) | 191 file_info = scm.SVN._CaptureInfo([self.url], None) |
| 187 expected = { | 192 expected = { |
| 188 'URL': self.url, | 193 'URL': self.url, |
| 189 'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb', | 194 'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb', |
| 190 'Revision': 35, | 195 'Revision': 35, |
| 191 'Repository Root': self.root_dir, | 196 'Repository Root': self.root_dir, |
| 192 'Schedule': 'normal', | 197 'Schedule': 'normal', |
| 193 'Copied From URL': None, | 198 'Copied From URL': None, |
| 194 'Copied From Rev': None, | 199 'Copied From Rev': None, |
| 195 'Path': '.', | 200 'Path': '.', |
| 196 'Node Kind': 'directory', | 201 'Node Kind': 'directory', |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 <wc-status props="normal" item="conflicted" revision="14725"> | 233 <wc-status props="normal" item="conflicted" revision="14725"> |
| 229 <commit revision="14633"> | 234 <commit revision="14633"> |
| 230 <author>nsylvain@chromium.org</author> | 235 <author>nsylvain@chromium.org</author> |
| 231 <date>2009-04-27T19:37:17.977400Z</date> | 236 <date>2009-04-27T19:37:17.977400Z</date> |
| 232 </commit> | 237 </commit> |
| 233 </wc-status> | 238 </wc-status> |
| 234 </entry> | 239 </entry> |
| 235 </target> | 240 </target> |
| 236 </status> | 241 </status> |
| 237 """ | 242 """ |
| 238 scm.SVN.Capture(['status', '--xml', '.']).AndReturn(text) | 243 scm.SVN.Capture(['status', '--xml'], '.').AndReturn(text) |
| 239 | 244 |
| 240 self.mox.ReplayAll() | 245 self.mox.ReplayAll() |
| 241 info = scm.SVN.CaptureStatus('.') | 246 info = scm.SVN.CaptureStatus(None, '.') |
| 242 expected = [ | 247 expected = [ |
| 243 ('? ', 'unversionned_file.txt'), | 248 ('? ', 'unversionned_file.txt'), |
| 244 ('M ', 'build\\internal\\essential.vsprops'), | 249 ('M ', 'build\\internal\\essential.vsprops'), |
| 245 ('A + ', 'chrome\\app\\d'), | 250 ('A + ', 'chrome\\app\\d'), |
| 246 ('MM ', 'chrome\\app\\DEPS'), | 251 ('MM ', 'chrome\\app\\DEPS'), |
| 247 ('C ', 'scripts\\master\\factory\\gclient_factory.py'), | 252 ('C ', 'scripts\\master\\factory\\gclient_factory.py'), |
| 248 ] | 253 ] |
| 249 self.assertEquals(sorted(info), sorted(expected)) | 254 self.assertEquals(sorted(info), sorted(expected)) |
| 250 | 255 |
| 251 def testCaptureStatusEmpty(self): | 256 def testCaptureStatusEmpty(self): |
| 252 text = r"""<?xml version="1.0"?> | 257 text = r"""<?xml version="1.0"?> |
| 253 <status> | 258 <status> |
| 254 <target | 259 <target |
| 255 path="perf"> | 260 path="perf"> |
| 256 </target> | 261 </target> |
| 257 </status>""" | 262 </status>""" |
| 258 scm.SVN.Capture(['status', '--xml']).AndReturn(text) | 263 scm.SVN.Capture(['status', '--xml'], None).AndReturn(text) |
| 259 self.mox.ReplayAll() | 264 self.mox.ReplayAll() |
| 260 info = scm.SVN.CaptureStatus(None) | 265 info = scm.SVN.CaptureStatus(None, None) |
| 261 self.assertEquals(info, []) | 266 self.assertEquals(info, []) |
| 262 | 267 |
| 263 | 268 |
| 264 class RealSvnTest(fake_repos.FakeReposTestBase): | 269 class RealSvnTest(fake_repos.FakeReposTestBase): |
| 265 # Tests that work with a checkout. | 270 # Tests that work with a checkout. |
| 266 def setUp(self): | 271 def setUp(self): |
| 267 super(RealSvnTest, self).setUp() | 272 super(RealSvnTest, self).setUp() |
| 268 self.enabled = self.FAKE_REPOS.set_up_svn() | 273 self.enabled = self.FAKE_REPOS.set_up_svn() |
| 269 if self.enabled: | 274 if self.enabled: |
| 270 self.svn_root = scm.os.path.join(self.root_dir, 'base') | 275 self.svn_root = scm.os.path.join(self.root_dir, 'base') |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 # Asserting the tree is not sufficient, svn status must come out clear too. | 342 # Asserting the tree is not sufficient, svn status must come out clear too. |
| 338 self.assertEquals('', self._capture(['status'])) | 343 self.assertEquals('', self._capture(['status'])) |
| 339 | 344 |
| 340 | 345 |
| 341 if __name__ == '__main__': | 346 if __name__ == '__main__': |
| 342 if '-v' in sys.argv: | 347 if '-v' in sys.argv: |
| 343 logging.basicConfig(level=logging.DEBUG) | 348 logging.basicConfig(level=logging.DEBUG) |
| 344 unittest.main() | 349 unittest.main() |
| 345 | 350 |
| 346 # vim: ts=2:sw=2:tw=80:et: | 351 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |