| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2009 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 trychange.py.""" | 6 """Unit tests for trychange.py.""" |
| 7 | 7 |
| 8 import optparse | 8 import optparse |
| 9 | 9 |
| 10 # Local imports | 10 # Local imports |
| 11 import trychange | 11 import trychange |
| 12 from super_mox import mox, SuperMoxTestBase | 12 from super_mox import mox, SuperMoxTestBase |
| 13 | 13 |
| 14 | 14 |
| 15 class TryChangeTestsBase(SuperMoxTestBase): | 15 class TryChangeTestsBase(SuperMoxTestBase): |
| 16 """Setups and tear downs the mocks but doesn't test anything as-is.""" | 16 """Setups and tear downs the mocks but doesn't test anything as-is.""" |
| 17 def setUp(self): | 17 def setUp(self): |
| 18 SuperMoxTestBase.setUp(self) | 18 SuperMoxTestBase.setUp(self) |
| 19 self.mox.StubOutWithMock(trychange.gclient_utils, 'CheckCall') | 19 self.mox.StubOutWithMock(trychange.gclient_utils, 'CheckCall') |
| 20 self.mox.StubOutWithMock(trychange.scm.GIT, 'Capture') | 20 self.mox.StubOutWithMock(trychange.scm.GIT, 'Capture') |
| 21 self.mox.StubOutWithMock(trychange.scm.GIT, 'GenerateDiff') | 21 self.mox.StubOutWithMock(trychange.scm.GIT, 'GenerateDiff') |
| 22 self.mox.StubOutWithMock(trychange.scm.GIT, 'GetCheckoutRoot') |
| 23 self.mox.StubOutWithMock(trychange.scm.GIT, 'GetPatchName') |
| 22 self.mox.StubOutWithMock(trychange.scm.GIT, 'GetEmail') | 24 self.mox.StubOutWithMock(trychange.scm.GIT, 'GetEmail') |
| 23 self.mox.StubOutWithMock(trychange.scm.SVN, 'DiffItem') | 25 self.mox.StubOutWithMock(trychange.scm.SVN, 'DiffItem') |
| 24 self.mox.StubOutWithMock(trychange.scm.SVN, 'GenerateDiff') | 26 self.mox.StubOutWithMock(trychange.scm.SVN, 'GenerateDiff') |
| 25 self.mox.StubOutWithMock(trychange.scm.SVN, 'GetCheckoutRoot') | 27 self.mox.StubOutWithMock(trychange.scm.SVN, 'GetCheckoutRoot') |
| 26 self.mox.StubOutWithMock(trychange.scm.SVN, 'GetEmail') | 28 self.mox.StubOutWithMock(trychange.scm.SVN, 'GetEmail') |
| 27 self.fake_root = self.Dir() | 29 self.fake_root = self.Dir() |
| 28 self.expected_files = ['foo.txt', 'bar.txt'] | 30 self.expected_files = ['foo.txt', 'bar.txt'] |
| 29 self.options = optparse.Values() | 31 self.options = optparse.Values() |
| 30 self.options.files = self.expected_files | 32 self.options.files = self.expected_files |
| 31 self.options.diff = None | 33 self.options.diff = None |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 class GITUnittest(TryChangeTestsBase): | 74 class GITUnittest(TryChangeTestsBase): |
| 73 """trychange.GIT tests.""" | 75 """trychange.GIT tests.""" |
| 74 def testMembersChanged(self): | 76 def testMembersChanged(self): |
| 75 members = [ | 77 members = [ |
| 76 'GetBots', 'GetFileNames', 'GetLocalRoot', | 78 'GetBots', 'GetFileNames', 'GetLocalRoot', |
| 77 ] | 79 ] |
| 78 # If this test fails, you should add the relevant test. | 80 # If this test fails, you should add the relevant test. |
| 79 self.compareMembers(trychange.GIT, members) | 81 self.compareMembers(trychange.GIT, members) |
| 80 | 82 |
| 81 def testBasic(self): | 83 def testBasic(self): |
| 82 trychange.gclient_utils.CheckCall( | 84 trychange.os.getcwd().AndReturn(self.fake_root) |
| 83 ['git', 'rev-parse', '--show-cdup']).AndReturn(self.fake_root) | 85 trychange.scm.GIT.GetCheckoutRoot(self.fake_root).AndReturn(self.fake_root) |
| 84 trychange.os.path.abspath(self.fake_root).AndReturn(self.fake_root) | |
| 85 trychange.scm.GIT.GenerateDiff(self.fake_root).AndReturn('a diff') | 86 trychange.scm.GIT.GenerateDiff(self.fake_root).AndReturn('a diff') |
| 86 trychange.gclient_utils.CheckCall( | 87 trychange.scm.GIT.GetPatchName(self.fake_root).AndReturn('bleh-1233') |
| 87 ['git', 'symbolic-ref', 'HEAD']).AndReturn('refs/heads/random branch') | 88 trychange.scm.GIT.GetEmail(self.fake_root).AndReturn('georges@example.com') |
| 88 trychange.scm.GIT.GetEmail('.').AndReturn('georges@example.com') | |
| 89 self.mox.ReplayAll() | 89 self.mox.ReplayAll() |
| 90 git = trychange.GIT(self.options) | 90 git = trychange.GIT(self.options) |
| 91 self.assertEqual(git.GetFileNames(), self.expected_files) | 91 self.assertEqual(git.GetFileNames(), self.expected_files) |
| 92 self.assertEqual(git.GetLocalRoot(), self.fake_root) | 92 self.assertEqual(git.GetLocalRoot(), self.fake_root) |
| 93 | 93 |
| 94 | 94 |
| 95 if __name__ == '__main__': | 95 if __name__ == '__main__': |
| 96 import unittest | 96 import unittest |
| 97 unittest.main() | 97 unittest.main() |
| OLD | NEW |