| 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 unittest | 9 import unittest |
| 9 | 10 |
| 10 # Local imports | 11 # Local imports |
| 12 import gcl |
| 11 import super_mox | 13 import super_mox |
| 12 import trychange | 14 import trychange |
| 15 import upload |
| 13 from super_mox import mox | 16 from super_mox import mox |
| 14 | 17 |
| 15 | 18 |
| 16 class TryChangeTestsBase(super_mox.SuperMoxTestBase): | 19 class TryChangeTestsBase(super_mox.SuperMoxTestBase): |
| 17 """Setups and tear downs the mocks but doesn't test anything as-is.""" | 20 """Setups and tear downs the mocks but doesn't test anything as-is.""" |
| 18 pass | 21 pass |
| 19 | 22 |
| 20 | 23 |
| 21 class TryChangeUnittest(TryChangeTestsBase): | 24 class TryChangeUnittest(TryChangeTestsBase): |
| 22 """General trychange.py tests.""" | 25 """General trychange.py tests.""" |
| 23 def testMembersChanged(self): | 26 def testMembersChanged(self): |
| 24 members = [ | 27 members = [ |
| 25 'EscapeDot', 'GIT', 'GetSourceRoot', | 28 'EscapeDot', 'GIT', 'GetSourceRoot', |
| 26 'GetTryServerSettings', 'GuessVCS', | 29 'GetTryServerSettings', 'GuessVCS', |
| 27 'HELP_STRING', 'InvalidScript', 'NoTryServerAccess', 'PathDifference', | 30 'HELP_STRING', 'InvalidScript', 'NoTryServerAccess', 'PathDifference', |
| 28 'RunCommand', 'SCM', 'SVN', 'TryChange', 'USAGE', | 31 'RunCommand', 'SCM', 'SVN', 'TryChange', 'USAGE', |
| 29 'datetime', 'gcl', 'gclient', 'gclient_scm', 'getpass', 'logging', | 32 'datetime', 'gcl', 'gclient', 'gclient_scm', 'getpass', 'logging', |
| 30 'optparse', 'os', 'shutil', 'socket', 'sys', 'tempfile', 'traceback', | 33 'optparse', 'os', 'presubmit_support', 'shutil', 'socket', 'subprocess', |
| 31 'upload', 'urllib', 'subprocess', | 34 'sys', 'tempfile', 'traceback', 'upload', 'urllib', |
| 32 ] | 35 ] |
| 33 # If this test fails, you should add the relevant test. | 36 # If this test fails, you should add the relevant test. |
| 34 self.compareMembers(trychange, members) | 37 self.compareMembers(trychange, members) |
| 35 | 38 |
| 36 | 39 |
| 37 class SVNUnittest(TryChangeTestsBase): | 40 class SVNUnittest(TryChangeTestsBase): |
| 38 """trychange.SVN tests.""" | 41 """trychange.SVN tests.""" |
| 42 def setUp(self): |
| 43 self.fake_root = '/fake_root' |
| 44 self.expected_files = ['foo.txt', 'bar.txt'] |
| 45 change_info = gcl.ChangeInfo('test_change', 0, 0, 'desc', |
| 46 [('M', f) for f in self.expected_files], |
| 47 self.fake_root) |
| 48 self.svn = trychange.SVN(None) |
| 49 self.svn.change_info = change_info |
| 50 super_mox.SuperMoxTestBase.setUp(self) |
| 51 |
| 39 def testMembersChanged(self): | 52 def testMembersChanged(self): |
| 40 members = [ | 53 members = [ |
| 41 'GenerateDiff', 'ProcessOptions', 'options' | 54 'GenerateDiff', 'GetFileNames', 'GetLocalRoot', 'ProcessOptions', |
| 55 'options' |
| 42 ] | 56 ] |
| 43 # If this test fails, you should add the relevant test. | 57 # If this test fails, you should add the relevant test. |
| 44 self.compareMembers(trychange.SVN(None), members) | 58 self.compareMembers(trychange.SVN(None), members) |
| 45 | 59 |
| 60 def testGetFileNames(self): |
| 61 self.mox.ReplayAll() |
| 62 self.assertEqual(self.svn.GetFileNames(), self.expected_files) |
| 63 |
| 64 def testGetLocalRoot(self): |
| 65 self.mox.ReplayAll() |
| 66 self.assertEqual(self.svn.GetLocalRoot(), self.fake_root) |
| 67 |
| 46 | 68 |
| 47 class GITUnittest(TryChangeTestsBase): | 69 class GITUnittest(TryChangeTestsBase): |
| 48 """trychange.GIT tests.""" | 70 """trychange.GIT tests.""" |
| 71 def setUp(self): |
| 72 self.fake_root = '/fake_root' |
| 73 self.expected_files = ['foo.txt', 'bar.txt'] |
| 74 options = optparse.Values() |
| 75 options.files = self.expected_files |
| 76 self.git = trychange.GIT(options) |
| 77 super_mox.SuperMoxTestBase.setUp(self) |
| 78 |
| 49 def testMembersChanged(self): | 79 def testMembersChanged(self): |
| 50 members = [ | 80 members = [ |
| 51 'GenerateDiff', 'GetEmail', 'GetPatchName', 'ProcessOptions', 'options' | 81 'GenerateDiff', 'GetEmail', 'GetFileNames', 'GetLocalRoot', |
| 82 'GetPatchName', 'ProcessOptions', 'options' |
| 52 ] | 83 ] |
| 53 # If this test fails, you should add the relevant test. | 84 # If this test fails, you should add the relevant test. |
| 54 self.compareMembers(trychange.GIT(None), members) | 85 self.compareMembers(trychange.GIT(None), members) |
| 55 | 86 |
| 87 def testGetFileNames(self): |
| 88 self.mox.ReplayAll() |
| 89 self.assertEqual(self.git.GetFileNames(), self.expected_files) |
| 90 |
| 91 def testGetLocalRoot(self): |
| 92 self.mox.StubOutWithMock(upload, 'RunShell') |
| 93 upload.RunShell(['git', 'rev-parse', '--show-cdup']).AndReturn( |
| 94 self.fake_root) |
| 95 self.mox.ReplayAll() |
| 96 self.assertEqual(self.git.GetLocalRoot(), self.fake_root) |
| 97 |
| 56 | 98 |
| 57 if __name__ == '__main__': | 99 if __name__ == '__main__': |
| 58 unittest.main() | 100 unittest.main() |
| OLD | NEW |