OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
3 # Copyright 2008-2009 Google Inc. All Rights Reserved. | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # | 4 # found in the LICENSE file. |
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 | 5 |
17 """Unit tests for gclient_scm.py.""" | 6 """Unit tests for gclient_scm.py.""" |
18 | 7 |
19 import os | 8 # Import before super_mox to keep valid references. |
20 import shutil | 9 from os import rename |
21 # Import it before super_mox to keep a valid reference. | 10 from shutil import rmtree |
Nicolas Sylvain
2010/02/03 18:07:18
why?
| |
22 from subprocess import Popen, PIPE, STDOUT | 11 from subprocess import Popen, PIPE, STDOUT |
23 import tempfile | 12 import tempfile |
24 | 13 |
14 # Fixes include path. | |
15 from super_mox import mox, SuperMoxBaseTestBase | |
16 | |
25 import gclient_scm | 17 import gclient_scm |
26 from gclient_test import BaseTestCase as GCBaseTestCase | 18 from gclient_test import BaseTestCase as GCBaseTestCase |
27 from super_mox import mox, SuperMoxBaseTestBase | |
28 | 19 |
29 | 20 |
30 class BaseTestCase(GCBaseTestCase): | 21 class BaseTestCase(GCBaseTestCase): |
31 def setUp(self): | 22 def setUp(self): |
32 GCBaseTestCase.setUp(self) | 23 GCBaseTestCase.setUp(self) |
33 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileRead') | 24 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileRead') |
34 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite') | 25 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite') |
35 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'SubprocessCall') | 26 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'SubprocessCall') |
36 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory') | 27 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory') |
37 self._CaptureSVNInfo = gclient_scm.scm.SVN.CaptureInfo | 28 self._CaptureSVNInfo = gclient_scm.scm.SVN.CaptureInfo |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 self.args = self.Args() | 357 self.args = self.Args() |
367 self.url = 'git://foo' | 358 self.url = 'git://foo' |
368 self.root_dir = tempfile.mkdtemp() | 359 self.root_dir = tempfile.mkdtemp() |
369 self.relpath = '.' | 360 self.relpath = '.' |
370 self.base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | 361 self.base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) |
371 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) | 362 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) |
372 SuperMoxBaseTestBase.setUp(self) | 363 SuperMoxBaseTestBase.setUp(self) |
373 | 364 |
374 def tearDown(self): | 365 def tearDown(self): |
375 SuperMoxBaseTestBase.tearDown(self) | 366 SuperMoxBaseTestBase.tearDown(self) |
376 shutil.rmtree(self.root_dir) | 367 rmtree(self.root_dir) |
377 | 368 |
378 def testDir(self): | 369 def testDir(self): |
379 members = [ | 370 members = [ |
380 'COMMAND', 'Capture', 'CaptureStatus', 'FetchUpstreamTuple', | 371 'COMMAND', 'Capture', 'CaptureStatus', 'FetchUpstreamTuple', |
381 'FullUrlForRelativeUrl', 'GenerateDiff', 'GetBranch', 'GetBranchRef', | 372 'FullUrlForRelativeUrl', 'GenerateDiff', 'GetBranch', 'GetBranchRef', |
382 'GetCheckoutRoot', 'GetDifferentFiles', 'GetEmail', 'GetPatchName', | 373 'GetCheckoutRoot', 'GetDifferentFiles', 'GetEmail', 'GetPatchName', |
383 'GetSVNBranch', 'GetUpstream', 'IsGitSvn', 'RunAndFilterOutput', | 374 'GetSVNBranch', 'GetUpstream', 'IsGitSvn', 'RunAndFilterOutput', |
384 'ShortBranchName', 'RunCommand', | 375 'ShortBranchName', 'RunCommand', |
385 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert', | 376 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert', |
386 'revinfo', 'runhooks', 'scm_name', 'status', 'update', 'url', | 377 'revinfo', 'runhooks', 'scm_name', 'status', 'update', 'url', |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
496 scm = gclient_scm.CreateSCM(url=url, root_dir=root_dir, | 487 scm = gclient_scm.CreateSCM(url=url, root_dir=root_dir, |
497 relpath=relpath) | 488 relpath=relpath) |
498 file_list = [] | 489 file_list = [] |
499 scm.update(options, (), file_list) | 490 scm.update(options, (), file_list) |
500 self.assertEquals(len(file_list), 2) | 491 self.assertEquals(len(file_list), 2) |
501 self.assert_(gclient_scm.os.path.isfile( | 492 self.assert_(gclient_scm.os.path.isfile( |
502 gclient_scm.os.path.join(base_path, 'a'))) | 493 gclient_scm.os.path.join(base_path, 'a'))) |
503 self.assertEquals(scm.revinfo(options, (), None), | 494 self.assertEquals(scm.revinfo(options, (), None), |
504 '069c602044c5388d2d15c3f875b057c852003458') | 495 '069c602044c5388d2d15c3f875b057c852003458') |
505 finally: | 496 finally: |
506 shutil.rmtree(root_dir) | 497 rmtree(root_dir) |
507 | 498 |
508 def testUpdateUpdate(self): | 499 def testUpdateUpdate(self): |
509 if not self.enabled: | 500 if not self.enabled: |
510 return | 501 return |
511 options = self.Options() | 502 options = self.Options() |
512 expected_file_list = [gclient_scm.os.path.join(self.base_path, x) | 503 expected_file_list = [gclient_scm.os.path.join(self.base_path, x) |
513 for x in ['a', 'b']] | 504 for x in ['a', 'b']] |
514 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 505 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
515 relpath=self.relpath) | 506 relpath=self.relpath) |
516 file_list = [] | 507 file_list = [] |
(...skipping 25 matching lines...) Expand all Loading... | |
542 '\tSee man git-rebase for details.\n' | 533 '\tSee man git-rebase for details.\n' |
543 self.assertRaisesError(exception, scm.update, options, (), []) | 534 self.assertRaisesError(exception, scm.update, options, (), []) |
544 | 535 |
545 def testUpdateNotGit(self): | 536 def testUpdateNotGit(self): |
546 if not self.enabled: | 537 if not self.enabled: |
547 return | 538 return |
548 options = self.Options() | 539 options = self.Options() |
549 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 540 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
550 relpath=self.relpath) | 541 relpath=self.relpath) |
551 git_path = gclient_scm.os.path.join(self.base_path, '.git') | 542 git_path = gclient_scm.os.path.join(self.base_path, '.git') |
552 os.rename(git_path, git_path + 'foo') | 543 rename(git_path, git_path + 'foo') |
553 exception = \ | 544 exception = \ |
554 '\n____ .\n' \ | 545 '\n____ .\n' \ |
555 '\tPath is not a git repo. No .git dir.\n' \ | 546 '\tPath is not a git repo. No .git dir.\n' \ |
556 '\tTo resolve:\n' \ | 547 '\tTo resolve:\n' \ |
557 '\t\trm -rf .\n' \ | 548 '\t\trm -rf .\n' \ |
558 '\tAnd run gclient sync again\n' | 549 '\tAnd run gclient sync again\n' |
559 self.assertRaisesError(exception, scm.update, options, (), []) | 550 self.assertRaisesError(exception, scm.update, options, (), []) |
560 | 551 |
561 def testRevinfo(self): | 552 def testRevinfo(self): |
562 if not self.enabled: | 553 if not self.enabled: |
563 return | 554 return |
564 options = self.Options() | 555 options = self.Options() |
565 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 556 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
566 relpath=self.relpath) | 557 relpath=self.relpath) |
567 rev_info = scm.revinfo(options, (), None) | 558 rev_info = scm.revinfo(options, (), None) |
568 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') | 559 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') |
569 | 560 |
570 | 561 |
571 if __name__ == '__main__': | 562 if __name__ == '__main__': |
572 import unittest | 563 import unittest |
573 unittest.main() | 564 unittest.main() |
574 | 565 |
575 # vim: ts=2:sw=2:tw=80:et: | 566 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |