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