| Index: tests/trychange_unittest.py
|
| ===================================================================
|
| --- tests/trychange_unittest.py (revision 28147)
|
| +++ tests/trychange_unittest.py (working copy)
|
| @@ -5,11 +5,14 @@
|
|
|
| """Unit tests for trychange.py."""
|
|
|
| +import optparse
|
| import unittest
|
|
|
| # Local imports
|
| +import gcl
|
| import super_mox
|
| import trychange
|
| +import upload
|
| from super_mox import mox
|
|
|
|
|
| @@ -27,8 +30,8 @@
|
| 'HELP_STRING', 'InvalidScript', 'NoTryServerAccess', 'PathDifference',
|
| 'RunCommand', 'SCM', 'SVN', 'TryChange', 'USAGE',
|
| 'datetime', 'gcl', 'gclient', 'gclient_scm', 'getpass', 'logging',
|
| - 'optparse', 'os', 'shutil', 'socket', 'sys', 'tempfile', 'traceback',
|
| - 'upload', 'urllib', 'subprocess',
|
| + 'optparse', 'os', 'presubmit_support', 'shutil', 'socket', 'subprocess',
|
| + 'sys', 'tempfile', 'traceback', 'upload', 'urllib',
|
| ]
|
| # If this test fails, you should add the relevant test.
|
| self.compareMembers(trychange, members)
|
| @@ -36,23 +39,62 @@
|
|
|
| class SVNUnittest(TryChangeTestsBase):
|
| """trychange.SVN tests."""
|
| + def setUp(self):
|
| + self.fake_root = '/fake_root'
|
| + self.expected_files = ['foo.txt', 'bar.txt']
|
| + change_info = gcl.ChangeInfo('test_change', 0, 0, 'desc',
|
| + [('M', f) for f in self.expected_files],
|
| + self.fake_root)
|
| + self.svn = trychange.SVN(None)
|
| + self.svn.change_info = change_info
|
| + super_mox.SuperMoxTestBase.setUp(self)
|
| +
|
| def testMembersChanged(self):
|
| members = [
|
| - 'GenerateDiff', 'ProcessOptions', 'options'
|
| + 'GenerateDiff', 'GetFileNames', 'GetLocalRoot', 'ProcessOptions',
|
| + 'options'
|
| ]
|
| # If this test fails, you should add the relevant test.
|
| self.compareMembers(trychange.SVN(None), members)
|
|
|
| + def testGetFileNames(self):
|
| + self.mox.ReplayAll()
|
| + self.assertEqual(self.svn.GetFileNames(), self.expected_files)
|
|
|
| + def testGetLocalRoot(self):
|
| + self.mox.ReplayAll()
|
| + self.assertEqual(self.svn.GetLocalRoot(), self.fake_root)
|
| +
|
| +
|
| class GITUnittest(TryChangeTestsBase):
|
| """trychange.GIT tests."""
|
| + def setUp(self):
|
| + self.fake_root = '/fake_root'
|
| + self.expected_files = ['foo.txt', 'bar.txt']
|
| + options = optparse.Values()
|
| + options.files = self.expected_files
|
| + self.git = trychange.GIT(options)
|
| + super_mox.SuperMoxTestBase.setUp(self)
|
| +
|
| def testMembersChanged(self):
|
| members = [
|
| - 'GenerateDiff', 'GetEmail', 'GetPatchName', 'ProcessOptions', 'options'
|
| + 'GenerateDiff', 'GetEmail', 'GetFileNames', 'GetLocalRoot',
|
| + 'GetPatchName', 'ProcessOptions', 'options'
|
| ]
|
| # If this test fails, you should add the relevant test.
|
| self.compareMembers(trychange.GIT(None), members)
|
|
|
| + def testGetFileNames(self):
|
| + self.mox.ReplayAll()
|
| + self.assertEqual(self.git.GetFileNames(), self.expected_files)
|
|
|
| + def testGetLocalRoot(self):
|
| + self.mox.StubOutWithMock(upload, 'RunShell')
|
| + upload.RunShell(['git', 'rev-parse', '--show-cdup']).AndReturn(
|
| + self.fake_root)
|
| + self.mox.ReplayAll()
|
| + self.assertEqual(self.git.GetLocalRoot(), self.fake_root)
|
| +
|
| +
|
| if __name__ == '__main__':
|
| unittest.main()
|
|
|