gclient_scm_test.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. #!/usr/bin/python
  2. #
  3. # Copyright 2008-2009 Google Inc. All Rights Reserved.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (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
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. """Unit tests for gclient_scm.py."""
  17. import shutil
  18. # Import it before super_mox to keep a valid reference.
  19. from subprocess import Popen, PIPE, STDOUT
  20. import tempfile
  21. import gclient_scm
  22. from gclient_test import BaseTestCase as GCBaseTestCase
  23. from super_mox import mox, SuperMoxBaseTestBase
  24. class BaseTestCase(GCBaseTestCase):
  25. def setUp(self):
  26. GCBaseTestCase.setUp(self)
  27. self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileRead')
  28. self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite')
  29. self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'SubprocessCall')
  30. self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory')
  31. self._CaptureSVNInfo = gclient_scm.CaptureSVNInfo
  32. self.mox.StubOutWithMock(gclient_scm, 'CaptureSVN')
  33. self.mox.StubOutWithMock(gclient_scm, 'CaptureSVNInfo')
  34. self.mox.StubOutWithMock(gclient_scm, 'CaptureSVNStatus')
  35. self.mox.StubOutWithMock(gclient_scm, 'RunSVN')
  36. self.mox.StubOutWithMock(gclient_scm, 'RunSVNAndGetFileList')
  37. self._scm_wrapper = gclient_scm.CreateSCM
  38. class SVNWrapperTestCase(BaseTestCase):
  39. class OptionsObject(object):
  40. def __init__(self, test_case, verbose=False, revision=None):
  41. self.verbose = verbose
  42. self.revision = revision
  43. self.manually_grab_svn_rev = True
  44. self.deps_os = None
  45. self.force = False
  46. self.nohooks = False
  47. def Options(self, *args, **kwargs):
  48. return self.OptionsObject(self, *args, **kwargs)
  49. def setUp(self):
  50. BaseTestCase.setUp(self)
  51. self.root_dir = self.Dir()
  52. self.args = self.Args()
  53. self.url = self.Url()
  54. self.relpath = 'asf'
  55. def testDir(self):
  56. members = [
  57. 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export',
  58. 'pack', 'relpath', 'revert', 'revinfo', 'runhooks', 'scm_name', 'status',
  59. 'update', 'url',
  60. ]
  61. # If you add a member, be sure to add the relevant test!
  62. self.compareMembers(self._scm_wrapper(), members)
  63. def testUnsupportedSCM(self):
  64. args = [self.url, self.root_dir, self.relpath]
  65. kwargs = {'scm_name' : 'foo'}
  66. exception_msg = 'Unsupported scm %(scm_name)s' % kwargs
  67. self.assertRaisesError(exception_msg, self._scm_wrapper, *args, **kwargs)
  68. def testFullUrlForRelativeUrl(self):
  69. self.url = 'svn://a/b/c/d'
  70. self.mox.ReplayAll()
  71. scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
  72. relpath=self.relpath)
  73. self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'svn://a/b/crap')
  74. def testRunCommandException(self):
  75. options = self.Options(verbose=False)
  76. file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git')
  77. gclient_scm.os.path.exists(file_path).AndReturn(False)
  78. self.mox.ReplayAll()
  79. scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
  80. relpath=self.relpath)
  81. exception = "Unsupported argument(s): %s" % ','.join(self.args)
  82. self.assertRaisesError(exception, scm.RunCommand,
  83. 'update', options, self.args)
  84. def testRunCommandUnknown(self):
  85. # TODO(maruel): if ever used.
  86. pass
  87. def testRevertMissing(self):
  88. options = self.Options(verbose=True)
  89. base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
  90. gclient_scm.os.path.isdir(base_path).AndReturn(False)
  91. # It'll to a checkout instead.
  92. gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
  93. ).AndReturn(False)
  94. print("\n_____ %s is missing, synching instead" % self.relpath)
  95. # Checkout.
  96. gclient_scm.os.path.exists(base_path).AndReturn(False)
  97. files_list = self.mox.CreateMockAnything()
  98. gclient_scm.RunSVNAndGetFileList(options, ['checkout', self.url, base_path],
  99. self.root_dir, files_list)
  100. self.mox.ReplayAll()
  101. scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
  102. relpath=self.relpath)
  103. scm.revert(options, self.args, files_list)
  104. def testRevertNone(self):
  105. options = self.Options(verbose=True)
  106. base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
  107. gclient_scm.os.path.isdir(base_path).AndReturn(True)
  108. gclient_scm.CaptureSVNStatus(base_path).AndReturn([])
  109. gclient_scm.RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'],
  110. base_path, mox.IgnoreArg())
  111. self.mox.ReplayAll()
  112. scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
  113. relpath=self.relpath)
  114. file_list = []
  115. scm.revert(options, self.args, file_list)
  116. def testRevert2Files(self):
  117. options = self.Options(verbose=True)
  118. base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
  119. gclient_scm.os.path.isdir(base_path).AndReturn(True)
  120. items = [
  121. ('M ', 'a'),
  122. ('A ', 'b'),
  123. ]
  124. file_path1 = gclient_scm.os.path.join(base_path, 'a')
  125. file_path2 = gclient_scm.os.path.join(base_path, 'b')
  126. gclient_scm.CaptureSVNStatus(base_path).AndReturn(items)
  127. gclient_scm.os.path.exists(file_path1).AndReturn(True)
  128. gclient_scm.os.path.isfile(file_path1).AndReturn(True)
  129. gclient_scm.os.remove(file_path1)
  130. gclient_scm.os.path.exists(file_path2).AndReturn(True)
  131. gclient_scm.os.path.isfile(file_path2).AndReturn(True)
  132. gclient_scm.os.remove(file_path2)
  133. gclient_scm.RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'],
  134. base_path, mox.IgnoreArg())
  135. print(gclient_scm.os.path.join(base_path, 'a'))
  136. print(gclient_scm.os.path.join(base_path, 'b'))
  137. self.mox.ReplayAll()
  138. scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
  139. relpath=self.relpath)
  140. file_list = []
  141. scm.revert(options, self.args, file_list)
  142. def testRevertDirectory(self):
  143. options = self.Options(verbose=True)
  144. base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
  145. gclient_scm.os.path.isdir(base_path).AndReturn(True)
  146. items = [
  147. ('~ ', 'a'),
  148. ]
  149. gclient_scm.CaptureSVNStatus(base_path).AndReturn(items)
  150. file_path = gclient_scm.os.path.join(base_path, 'a')
  151. print(file_path)
  152. gclient_scm.os.path.exists(file_path).AndReturn(True)
  153. gclient_scm.os.path.isfile(file_path).AndReturn(False)
  154. gclient_scm.os.path.isdir(file_path).AndReturn(True)
  155. gclient_scm.gclient_utils.RemoveDirectory(file_path)
  156. file_list1 = []
  157. gclient_scm.RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'],
  158. base_path, mox.IgnoreArg())
  159. self.mox.ReplayAll()
  160. scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
  161. relpath=self.relpath)
  162. file_list2 = []
  163. scm.revert(options, self.args, file_list2)
  164. def testStatus(self):
  165. options = self.Options(verbose=True)
  166. base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
  167. gclient_scm.os.path.isdir(base_path).AndReturn(True)
  168. gclient_scm.RunSVNAndGetFileList(options, ['status'] + self.args,
  169. base_path, []).AndReturn(None)
  170. self.mox.ReplayAll()
  171. scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
  172. relpath=self.relpath)
  173. file_list = []
  174. self.assertEqual(scm.status(options, self.args, file_list), None)
  175. # TODO(maruel): TEST REVISIONS!!!
  176. # TODO(maruel): TEST RELOCATE!!!
  177. def testUpdateCheckout(self):
  178. options = self.Options(verbose=True)
  179. base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
  180. file_info = gclient_scm.gclient_utils.PrintableObject()
  181. file_info.root = 'blah'
  182. file_info.url = self.url
  183. file_info.uuid = 'ABC'
  184. file_info.revision = 42
  185. gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
  186. ).AndReturn(False)
  187. # Checkout.
  188. gclient_scm.os.path.exists(base_path).AndReturn(False)
  189. files_list = self.mox.CreateMockAnything()
  190. gclient_scm.RunSVNAndGetFileList(options, ['checkout', self.url,
  191. base_path], self.root_dir, files_list)
  192. self.mox.ReplayAll()
  193. scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
  194. relpath=self.relpath)
  195. scm.update(options, (), files_list)
  196. def testUpdateUpdate(self):
  197. options = self.Options(verbose=True)
  198. base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
  199. options.force = True
  200. options.nohooks = False
  201. file_info = {
  202. 'Repository Root': 'blah',
  203. 'URL': self.url,
  204. 'UUID': 'ABC',
  205. 'Revision': 42,
  206. }
  207. gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git')
  208. ).AndReturn(False)
  209. # Checkout or update.
  210. gclient_scm.os.path.exists(base_path).AndReturn(True)
  211. gclient_scm.CaptureSVNInfo(gclient_scm.os.path.join(base_path, "."), '.'
  212. ).AndReturn(file_info)
  213. # Cheat a bit here.
  214. gclient_scm.CaptureSVNInfo(file_info['URL'], '.').AndReturn(file_info)
  215. additional_args = []
  216. if options.manually_grab_svn_rev:
  217. additional_args = ['--revision', str(file_info['Revision'])]
  218. files_list = []
  219. gclient_scm.RunSVNAndGetFileList(options,
  220. ['update', base_path] + additional_args,
  221. self.root_dir, files_list)
  222. self.mox.ReplayAll()
  223. scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
  224. relpath=self.relpath)
  225. scm.update(options, (), files_list)
  226. def testUpdateGit(self):
  227. options = self.Options(verbose=True)
  228. file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git')
  229. gclient_scm.os.path.exists(file_path).AndReturn(True)
  230. print("________ found .git directory; skipping %s" % self.relpath)
  231. self.mox.ReplayAll()
  232. scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
  233. relpath=self.relpath)
  234. file_list = []
  235. scm.update(options, self.args, file_list)
  236. def testGetSVNFileInfo(self):
  237. xml_text = r"""<?xml version="1.0"?>
  238. <info>
  239. <entry kind="file" path="%s" revision="14628">
  240. <url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url>
  241. <repository><root>http://src.chromium.org/svn</root></repository>
  242. <wc-info>
  243. <schedule>add</schedule>
  244. <depth>infinity</depth>
  245. <copy-from-url>http://src.chromium.org/svn/trunk/src/chrome/app/DEPS</copy-from-url>
  246. <copy-from-rev>14628</copy-from-rev>
  247. <checksum>369f59057ba0e6d9017e28f8bdfb1f43</checksum>
  248. </wc-info>
  249. </entry>
  250. </info>
  251. """ % self.url
  252. gclient_scm.CaptureSVN(['info', '--xml', self.url],
  253. '.', True).AndReturn(xml_text)
  254. expected = {
  255. 'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d',
  256. 'UUID': None,
  257. 'Repository Root': 'http://src.chromium.org/svn',
  258. 'Schedule': 'add',
  259. 'Copied From URL':
  260. 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS',
  261. 'Copied From Rev': '14628',
  262. 'Path': self.url,
  263. 'Revision': 14628,
  264. 'Node Kind': 'file',
  265. }
  266. self.mox.ReplayAll()
  267. file_info = self._CaptureSVNInfo(self.url, '.', True)
  268. self.assertEquals(sorted(file_info.items()), sorted(expected.items()))
  269. def testCaptureSvnInfo(self):
  270. xml_text = """<?xml version="1.0"?>
  271. <info>
  272. <entry
  273. kind="dir"
  274. path="."
  275. revision="35">
  276. <url>%s</url>
  277. <repository>
  278. <root>%s</root>
  279. <uuid>7b9385f5-0452-0410-af26-ad4892b7a1fb</uuid>
  280. </repository>
  281. <wc-info>
  282. <schedule>normal</schedule>
  283. <depth>infinity</depth>
  284. </wc-info>
  285. <commit
  286. revision="35">
  287. <author>maruel</author>
  288. <date>2008-12-04T20:12:19.685120Z</date>
  289. </commit>
  290. </entry>
  291. </info>
  292. """ % (self.url, self.root_dir)
  293. gclient_scm.CaptureSVN(['info', '--xml',
  294. self.url], '.', True).AndReturn(xml_text)
  295. self.mox.ReplayAll()
  296. file_info = self._CaptureSVNInfo(self.url, '.', True)
  297. expected = {
  298. 'URL': self.url,
  299. 'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb',
  300. 'Revision': 35,
  301. 'Repository Root': self.root_dir,
  302. 'Schedule': 'normal',
  303. 'Copied From URL': None,
  304. 'Copied From Rev': None,
  305. 'Path': '.',
  306. 'Node Kind': 'dir',
  307. }
  308. self.assertEqual(file_info, expected)
  309. def testRevinfo(self):
  310. options = self.Options(verbose=False)
  311. xml_text = """<?xml version="1.0"?>
  312. <info>
  313. <entry
  314. kind="dir"
  315. path="."
  316. revision="35">
  317. <url>%s</url>
  318. <repository>
  319. <root>%s</root>
  320. <uuid>7b9385f5-0452-0410-af26-ad4892b7a1fb</uuid>
  321. </repository>
  322. <wc-info>
  323. <schedule>normal</schedule>
  324. <depth>infinity</depth>
  325. </wc-info>
  326. <commit
  327. revision="35">
  328. <author>maruel</author>
  329. <date>2008-12-04T20:12:19.685120Z</date>
  330. </commit>
  331. </entry>
  332. </info>
  333. """ % (self.url, self.root_dir)
  334. gclient_scm.os.getcwd().AndReturn('bleh')
  335. gclient_scm.CaptureSVN(['info', '--xml', self.url], 'bleh'
  336. ).AndReturn(xml_text)
  337. self.mox.ReplayAll()
  338. scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
  339. relpath=self.relpath)
  340. rev_info = scm.revinfo(options, self.args, None)
  341. self.assertEqual(rev_info, '35')
  342. class GitWrapperTestCase(SuperMoxBaseTestBase):
  343. """This class doesn't use pymox."""
  344. class OptionsObject(object):
  345. def __init__(self, test_case, verbose=False, revision=None):
  346. self.verbose = verbose
  347. self.revision = revision
  348. self.manually_grab_svn_rev = True
  349. self.deps_os = None
  350. self.force = False
  351. self.nohooks = False
  352. sample_git_import = """blob
  353. mark :1
  354. data 6
  355. Hello
  356. blob
  357. mark :2
  358. data 4
  359. Bye
  360. reset refs/heads/master
  361. commit refs/heads/master
  362. mark :3
  363. author Bob <bob@example.com> 1253744361 -0700
  364. committer Bob <bob@example.com> 1253744361 -0700
  365. data 8
  366. A and B
  367. M 100644 :1 a
  368. M 100644 :2 b
  369. blob
  370. mark :4
  371. data 10
  372. Hello
  373. You
  374. blob
  375. mark :5
  376. data 8
  377. Bye
  378. You
  379. commit refs/heads/origin
  380. mark :6
  381. author Alice <alice@example.com> 1253744424 -0700
  382. committer Alice <alice@example.com> 1253744424 -0700
  383. data 13
  384. Personalized
  385. from :3
  386. M 100644 :4 a
  387. M 100644 :5 b
  388. reset refs/heads/master
  389. from :3
  390. """
  391. def Options(self, *args, **kwargs):
  392. return self.OptionsObject(self, *args, **kwargs)
  393. def CreateGitRepo(self, git_import, path):
  394. try:
  395. Popen(['git', 'init'], stdout=PIPE, stderr=STDOUT,
  396. cwd=path).communicate()
  397. except OSError:
  398. # git is not available, skip this test.
  399. return False
  400. Popen(['git', 'fast-import'], stdin=PIPE, stdout=PIPE, stderr=STDOUT,
  401. cwd=path).communicate(input=git_import)
  402. Popen(['git', 'checkout'], stdout=PIPE, stderr=STDOUT,
  403. cwd=path).communicate()
  404. return True
  405. def setUp(self):
  406. self.args = self.Args()
  407. self.url = 'git://foo'
  408. self.root_dir = tempfile.mkdtemp()
  409. self.relpath = '.'
  410. self.base_path = gclient_scm.os.path.join(self.root_dir, self.relpath)
  411. self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path)
  412. SuperMoxBaseTestBase.setUp(self)
  413. def tearDown(self):
  414. SuperMoxBaseTestBase.tearDown(self)
  415. shutil.rmtree(self.root_dir)
  416. def testDir(self):
  417. members = [
  418. 'FullUrlForRelativeUrl', 'RunCommand', 'cleanup', 'diff', 'export',
  419. 'relpath', 'revert', 'revinfo', 'runhooks', 'scm_name', 'status',
  420. 'update', 'url',
  421. ]
  422. # If you add a member, be sure to add the relevant test!
  423. self.compareMembers(gclient_scm.CreateSCM(url=self.url), members)
  424. def testRevertMissing(self):
  425. if not self.enabled:
  426. return
  427. options = self.Options()
  428. file_path = gclient_scm.os.path.join(self.base_path, 'a')
  429. gclient_scm.os.remove(file_path)
  430. scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
  431. relpath=self.relpath)
  432. file_list = []
  433. scm.revert(options, self.args, file_list)
  434. self.assertEquals(file_list, [file_path])
  435. file_list = []
  436. scm.diff(options, self.args, file_list)
  437. self.assertEquals(file_list, [])
  438. def testRevertNone(self):
  439. if not self.enabled:
  440. return
  441. options = self.Options()
  442. scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
  443. relpath=self.relpath)
  444. file_list = []
  445. scm.revert(options, self.args, file_list)
  446. self.assertEquals(file_list, [])
  447. self.assertEquals(scm.revinfo(options, self.args, None),
  448. '069c602044c5388d2d15c3f875b057c852003458')
  449. def testRevertModified(self):
  450. if not self.enabled:
  451. return
  452. options = self.Options()
  453. file_path = gclient_scm.os.path.join(self.base_path, 'a')
  454. open(file_path, 'a').writelines('touched\n')
  455. scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
  456. relpath=self.relpath)
  457. file_list = []
  458. scm.revert(options, self.args, file_list)
  459. self.assertEquals(file_list, [file_path])
  460. file_list = []
  461. scm.diff(options, self.args, file_list)
  462. self.assertEquals(file_list, [])
  463. self.assertEquals(scm.revinfo(options, self.args, None),
  464. '069c602044c5388d2d15c3f875b057c852003458')
  465. def testRevertNew(self):
  466. if not self.enabled:
  467. return
  468. options = self.Options()
  469. file_path = gclient_scm.os.path.join(self.base_path, 'c')
  470. f = open(file_path, 'w')
  471. f.writelines('new\n')
  472. f.close()
  473. Popen(['git', 'add', 'c'], stdout=PIPE,
  474. stderr=STDOUT, cwd=self.base_path).communicate()
  475. scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
  476. relpath=self.relpath)
  477. file_list = []
  478. scm.revert(options, self.args, file_list)
  479. self.assertEquals(file_list, [file_path])
  480. file_list = []
  481. scm.diff(options, self.args, file_list)
  482. self.assertEquals(file_list, [])
  483. self.assertEquals(scm.revinfo(options, self.args, None),
  484. '069c602044c5388d2d15c3f875b057c852003458')
  485. def testStatusNew(self):
  486. if not self.enabled:
  487. return
  488. options = self.Options()
  489. file_path = gclient_scm.os.path.join(self.base_path, 'a')
  490. open(file_path, 'a').writelines('touched\n')
  491. scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
  492. relpath=self.relpath)
  493. file_list = []
  494. scm.status(options, self.args, file_list)
  495. self.assertEquals(file_list, [file_path])
  496. def testStatus2New(self):
  497. if not self.enabled:
  498. return
  499. options = self.Options()
  500. expected_file_list = []
  501. for f in ['a', 'b']:
  502. file_path = gclient_scm.os.path.join(self.base_path, f)
  503. open(file_path, 'a').writelines('touched\n')
  504. expected_file_list.extend([file_path])
  505. scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
  506. relpath=self.relpath)
  507. file_list = []
  508. scm.status(options, self.args, file_list)
  509. expected_file_list = [gclient_scm.os.path.join(self.base_path, x)
  510. for x in ['a', 'b']]
  511. self.assertEquals(sorted(file_list), expected_file_list)
  512. def testUpdateCheckout(self):
  513. if not self.enabled:
  514. return
  515. options = self.Options(verbose=True)
  516. root_dir = tempfile.mkdtemp()
  517. relpath = 'foo'
  518. base_path = gclient_scm.os.path.join(root_dir, relpath)
  519. url = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git')
  520. try:
  521. scm = gclient_scm.CreateSCM(url=url, root_dir=root_dir,
  522. relpath=relpath)
  523. file_list = []
  524. scm.update(options, (), file_list)
  525. self.assertEquals(len(file_list), 2)
  526. self.assert_(gclient_scm.os.path.isfile(
  527. gclient_scm.os.path.join(base_path, 'a')))
  528. self.assertEquals(scm.revinfo(options, (), None),
  529. '069c602044c5388d2d15c3f875b057c852003458')
  530. finally:
  531. shutil.rmtree(root_dir)
  532. def testUpdateUpdate(self):
  533. if not self.enabled:
  534. return
  535. options = self.Options()
  536. expected_file_list = [gclient_scm.os.path.join(self.base_path, x)
  537. for x in ['a', 'b']]
  538. scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
  539. relpath=self.relpath)
  540. file_list = []
  541. scm.update(options, (), file_list)
  542. self.assertEquals(file_list, expected_file_list)
  543. self.assertEquals(scm.revinfo(options, (), None),
  544. 'a7142dc9f0009350b96a11f372b6ea658592aa95')
  545. def testRevinfo(self):
  546. if not self.enabled:
  547. return
  548. options = self.Options()
  549. scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
  550. relpath=self.relpath)
  551. rev_info = scm.revinfo(options, (), None)
  552. self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458')
  553. class RunSVNTestCase(BaseTestCase):
  554. def testRunSVN(self):
  555. self.UnMock(gclient_scm, 'RunSVN')
  556. param2 = 'bleh'
  557. gclient_scm.gclient_utils.SubprocessCall(['svn', 'foo', 'bar'],
  558. param2).AndReturn(None)
  559. self.mox.ReplayAll()
  560. gclient_scm.RunSVN(['foo', 'bar'], param2)
  561. if __name__ == '__main__':
  562. import unittest
  563. unittest.main()
  564. # vim: ts=2:sw=2:tw=80:et: