| 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 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 ] | 101 ] |
| 102 # If this test fails, you should add the relevant test. | 102 # If this test fails, you should add the relevant test. |
| 103 self.compareMembers(scm.SVN, members) | 103 self.compareMembers(scm.SVN, members) |
| 104 | 104 |
| 105 def testGetCheckoutRoot(self): | 105 def testGetCheckoutRoot(self): |
| 106 # pylint: disable=E1103 | 106 # pylint: disable=E1103 |
| 107 self.mox.StubOutWithMock(scm.SVN, 'CaptureInfo') | 107 self.mox.StubOutWithMock(scm.SVN, 'CaptureInfo') |
| 108 self.mox.StubOutWithMock(scm, 'GetCasedPath') | 108 self.mox.StubOutWithMock(scm, 'GetCasedPath') |
| 109 scm.os.path.abspath = lambda x: x | 109 scm.os.path.abspath = lambda x: x |
| 110 scm.GetCasedPath = lambda x: x | 110 scm.GetCasedPath = lambda x: x |
| 111 scm.SVN.CaptureInfo(self.root_dir + '/foo/bar').AndReturn({ | 111 scm.SVN.CaptureInfo(None, self.root_dir + '/foo/bar').AndReturn({ |
| 112 'Repository Root': 'svn://svn.chromium.org/chrome', | 112 'Repository Root': 'svn://svn.chromium.org/chrome', |
| 113 'URL': 'svn://svn.chromium.org/chrome/trunk/src', | 113 'URL': 'svn://svn.chromium.org/chrome/trunk/src', |
| 114 }) | 114 }) |
| 115 scm.SVN.CaptureInfo(self.root_dir + '/foo').AndReturn({ | 115 scm.SVN.CaptureInfo(None, self.root_dir + '/foo').AndReturn({ |
| 116 'Repository Root': 'svn://svn.chromium.org/chrome', | 116 'Repository Root': 'svn://svn.chromium.org/chrome', |
| 117 'URL': 'svn://svn.chromium.org/chrome/trunk', | 117 'URL': 'svn://svn.chromium.org/chrome/trunk', |
| 118 }) | 118 }) |
| 119 scm.SVN.CaptureInfo(self.root_dir).AndReturn({ | 119 scm.SVN.CaptureInfo(None, self.root_dir).AndReturn({ |
| 120 'Repository Root': 'svn://svn.chromium.org/chrome', | 120 'Repository Root': 'svn://svn.chromium.org/chrome', |
| 121 'URL': 'svn://svn.chromium.org/chrome/trunk/tools/commit-queue/workdir', | 121 'URL': 'svn://svn.chromium.org/chrome/trunk/tools/commit-queue/workdir', |
| 122 }) | 122 }) |
| 123 self.mox.ReplayAll() | 123 self.mox.ReplayAll() |
| 124 self.assertEquals(scm.SVN.GetCheckoutRoot(self.root_dir + '/foo/bar'), | 124 self.assertEquals(scm.SVN.GetCheckoutRoot(self.root_dir + '/foo/bar'), |
| 125 self.root_dir + '/foo') | 125 self.root_dir + '/foo') |
| 126 | 126 |
| 127 def testGetFileInfo(self): | 127 def testGetFileInfo(self): |
| 128 xml_text = r"""<?xml version="1.0"?> | 128 xml_text = r"""<?xml version="1.0"?> |
| 129 <info> | 129 <info> |
| 130 <entry kind="file" path="%s" revision="14628"> | 130 <entry kind="file" path="%s" revision="14628"> |
| 131 <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url> | 131 <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url> |
| 132 <repository><root>http://src.chromium.org/svn</root></repository> | 132 <repository><root>http://src.chromium.org/svn</root></repository> |
| 133 <wc-info> | 133 <wc-info> |
| 134 <schedule>add</schedule> | 134 <schedule>add</schedule> |
| 135 <depth>infinity</depth> | 135 <depth>infinity</depth> |
| 136 <copy-from-url>http://src.chromium.org/svn/trunk/src/chrome/app/DEPS</copy-from-
url> | 136 <copy-from-url>http://src.chromium.org/svn/trunk/src/chrome/app/DEPS</copy-from-
url> |
| 137 <copy-from-rev>14628</copy-from-rev> | 137 <copy-from-rev>14628</copy-from-rev> |
| 138 <checksum>369f59057ba0e6d9017e28f8bdfb1f43</checksum> | 138 <checksum>369f59057ba0e6d9017e28f8bdfb1f43</checksum> |
| 139 </wc-info> | 139 </wc-info> |
| 140 </entry> | 140 </entry> |
| 141 </info> | 141 </info> |
| 142 """ % self.url | 142 """ % self.url |
| 143 scm.SVN.Capture(['info', '--xml', self.url]).AndReturn(xml_text) | 143 scm.SVN.Capture(['info', '--xml', self.url], None).AndReturn(xml_text) |
| 144 expected = { | 144 expected = { |
| 145 'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d', | 145 'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d', |
| 146 'UUID': None, | 146 'UUID': None, |
| 147 'Repository Root': 'http://src.chromium.org/svn', | 147 'Repository Root': 'http://src.chromium.org/svn', |
| 148 'Schedule': 'add', | 148 'Schedule': 'add', |
| 149 'Copied From URL': | 149 'Copied From URL': |
| 150 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS', | 150 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS', |
| 151 'Copied From Rev': '14628', | 151 'Copied From Rev': '14628', |
| 152 'Path': self.url, | 152 'Path': self.url, |
| 153 'Revision': 14628, | 153 'Revision': 14628, |
| 154 'Node Kind': 'file', | 154 'Node Kind': 'file', |
| 155 } | 155 } |
| 156 self.mox.ReplayAll() | 156 self.mox.ReplayAll() |
| 157 file_info = scm.SVN.CaptureInfo(self.url) | 157 file_info = scm.SVN.CaptureInfo(self.url, None) |
| 158 self.assertEquals(sorted(file_info.items()), sorted(expected.items())) | 158 self.assertEquals(sorted(file_info.items()), sorted(expected.items())) |
| 159 | 159 |
| 160 def testCaptureInfo(self): | 160 def testCaptureInfo(self): |
| 161 xml_text = """<?xml version="1.0"?> | 161 xml_text = """<?xml version="1.0"?> |
| 162 <info> | 162 <info> |
| 163 <entry | 163 <entry |
| 164 kind="dir" | 164 kind="dir" |
| 165 path="." | 165 path="." |
| 166 revision="35"> | 166 revision="35"> |
| 167 <url>%s</url> | 167 <url>%s</url> |
| 168 <repository> | 168 <repository> |
| 169 <root>%s</root> | 169 <root>%s</root> |
| 170 <uuid>7b9385f5-0452-0410-af26-ad4892b7a1fb</uuid> | 170 <uuid>7b9385f5-0452-0410-af26-ad4892b7a1fb</uuid> |
| 171 </repository> | 171 </repository> |
| 172 <wc-info> | 172 <wc-info> |
| 173 <schedule>normal</schedule> | 173 <schedule>normal</schedule> |
| 174 <depth>infinity</depth> | 174 <depth>infinity</depth> |
| 175 </wc-info> | 175 </wc-info> |
| 176 <commit | 176 <commit |
| 177 revision="35"> | 177 revision="35"> |
| 178 <author>maruel</author> | 178 <author>maruel</author> |
| 179 <date>2008-12-04T20:12:19.685120Z</date> | 179 <date>2008-12-04T20:12:19.685120Z</date> |
| 180 </commit> | 180 </commit> |
| 181 </entry> | 181 </entry> |
| 182 </info> | 182 </info> |
| 183 """ % (self.url, self.root_dir) | 183 """ % (self.url, self.root_dir) |
| 184 scm.SVN.Capture(['info', '--xml', self.url]).AndReturn(xml_text) | 184 scm.SVN.Capture(['info', '--xml', self.url], None).AndReturn(xml_text) |
| 185 self.mox.ReplayAll() | 185 self.mox.ReplayAll() |
| 186 file_info = scm.SVN.CaptureInfo(self.url) | 186 file_info = scm.SVN.CaptureInfo(self.url, None) |
| 187 expected = { | 187 expected = { |
| 188 'URL': self.url, | 188 'URL': self.url, |
| 189 'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb', | 189 'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb', |
| 190 'Revision': 35, | 190 'Revision': 35, |
| 191 'Repository Root': self.root_dir, | 191 'Repository Root': self.root_dir, |
| 192 'Schedule': 'normal', | 192 'Schedule': 'normal', |
| 193 'Copied From URL': None, | 193 'Copied From URL': None, |
| 194 'Copied From Rev': None, | 194 'Copied From Rev': None, |
| 195 'Path': '.', | 195 'Path': '.', |
| 196 'Node Kind': 'directory', | 196 '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"> | 228 <wc-status props="normal" item="conflicted" revision="14725"> |
| 229 <commit revision="14633"> | 229 <commit revision="14633"> |
| 230 <author>nsylvain@chromium.org</author> | 230 <author>nsylvain@chromium.org</author> |
| 231 <date>2009-04-27T19:37:17.977400Z</date> | 231 <date>2009-04-27T19:37:17.977400Z</date> |
| 232 </commit> | 232 </commit> |
| 233 </wc-status> | 233 </wc-status> |
| 234 </entry> | 234 </entry> |
| 235 </target> | 235 </target> |
| 236 </status> | 236 </status> |
| 237 """ | 237 """ |
| 238 scm.SVN.Capture(['status', '--xml', '.']).AndReturn(text) | 238 scm.SVN.Capture(['status', '--xml'], '.').AndReturn(text) |
| 239 | 239 |
| 240 self.mox.ReplayAll() | 240 self.mox.ReplayAll() |
| 241 info = scm.SVN.CaptureStatus('.') | 241 info = scm.SVN.CaptureStatus(None, '.') |
| 242 expected = [ | 242 expected = [ |
| 243 ('? ', 'unversionned_file.txt'), | 243 ('? ', 'unversionned_file.txt'), |
| 244 ('M ', 'build\\internal\\essential.vsprops'), | 244 ('M ', 'build\\internal\\essential.vsprops'), |
| 245 ('A + ', 'chrome\\app\\d'), | 245 ('A + ', 'chrome\\app\\d'), |
| 246 ('MM ', 'chrome\\app\\DEPS'), | 246 ('MM ', 'chrome\\app\\DEPS'), |
| 247 ('C ', 'scripts\\master\\factory\\gclient_factory.py'), | 247 ('C ', 'scripts\\master\\factory\\gclient_factory.py'), |
| 248 ] | 248 ] |
| 249 self.assertEquals(sorted(info), sorted(expected)) | 249 self.assertEquals(sorted(info), sorted(expected)) |
| 250 | 250 |
| 251 def testCaptureStatusEmpty(self): | 251 def testCaptureStatusEmpty(self): |
| 252 text = r"""<?xml version="1.0"?> | 252 text = r"""<?xml version="1.0"?> |
| 253 <status> | 253 <status> |
| 254 <target | 254 <target |
| 255 path="perf"> | 255 path="perf"> |
| 256 </target> | 256 </target> |
| 257 </status>""" | 257 </status>""" |
| 258 scm.SVN.Capture(['status', '--xml']).AndReturn(text) | 258 scm.SVN.Capture(['status', '--xml'], None).AndReturn(text) |
| 259 self.mox.ReplayAll() | 259 self.mox.ReplayAll() |
| 260 info = scm.SVN.CaptureStatus(None) | 260 info = scm.SVN.CaptureStatus(None, None) |
| 261 self.assertEquals(info, []) | 261 self.assertEquals(info, []) |
| 262 | 262 |
| 263 | 263 |
| 264 class RealSvnTest(fake_repos.FakeReposTestBase): | 264 class RealSvnTest(fake_repos.FakeReposTestBase): |
| 265 # Tests that work with a checkout. | 265 # Tests that work with a checkout. |
| 266 def setUp(self): | 266 def setUp(self): |
| 267 super(RealSvnTest, self).setUp() | 267 super(RealSvnTest, self).setUp() |
| 268 self.enabled = self.FAKE_REPOS.set_up_svn() | 268 self.enabled = self.FAKE_REPOS.set_up_svn() |
| 269 if self.enabled: | 269 if self.enabled: |
| 270 self.svn_root = scm.os.path.join(self.root_dir, 'base') | 270 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. | 337 # Asserting the tree is not sufficient, svn status must come out clear too. |
| 338 self.assertEquals('', self._capture(['status'])) | 338 self.assertEquals('', self._capture(['status'])) |
| 339 | 339 |
| 340 | 340 |
| 341 if __name__ == '__main__': | 341 if __name__ == '__main__': |
| 342 if '-v' in sys.argv: | 342 if '-v' in sys.argv: |
| 343 logging.basicConfig(level=logging.DEBUG) | 343 logging.basicConfig(level=logging.DEBUG) |
| 344 unittest.main() | 344 unittest.main() |
| 345 | 345 |
| 346 # vim: ts=2:sw=2:tw=80:et: | 346 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |