Index: tests/presubmit_unittest.py |
diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py |
index 1d390bd8dfad296413dfb996708ad8787fa70809..36f74c5ce4137757a08c658ca6cd36e6ee6fa42c 100755 |
--- a/tests/presubmit_unittest.py |
+++ b/tests/presubmit_unittest.py |
@@ -134,9 +134,9 @@ class PresubmitUnittest(PresubmitTestsBase): |
def testMembersChanged(self): |
self.mox.ReplayAll() |
members = [ |
- 'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks', |
- 'GetTrySlavesExecuter', 'GitAffectedFile', 'GitChange', |
- 'InputApi', 'ListRelevantPresubmitFiles', 'Main', |
+ 'AffectedFile', 'Change', 'DetermineScm', 'DoGetTrySlaves', |
+ 'DoPresubmitChecks', 'GetTrySlavesExecuter', 'GitAffectedFile', |
+ 'GitChange', 'InputApi', 'ListRelevantPresubmitFiles', 'Main', |
'NotImplementedException', 'OutputApi', 'ParseFiles', |
'PresubmitExecuter', 'PresubmitOutput', 'ScanSubDirs', |
'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO', |
@@ -662,7 +662,7 @@ def CheckChangeOnCommit(input_api, output_api): |
self.fake_root_dir, None, False, |
output)) |
- def testMain(self): |
+ def testMainUnversioned(self): |
# OptParser calls presubmit.os.path.exists and is a pain when mocked. |
self.UnMock(presubmit.os.path, 'exists') |
self.mox.StubOutWithMock(presubmit, 'DoPresubmitChecks') |
@@ -675,6 +675,8 @@ def CheckChangeOnCommit(input_api, output_api): |
['git', 'rev-parse', '--show-cdup'], |
cwd=self.fake_root_dir, |
stdout=presubmit.subprocess.PIPE).AndReturn(1) |
+ presubmit.ParseFiles(['random_file.txt'], None |
+ ).AndReturn(['random_file.txt']) |
output = self.mox.CreateMock(presubmit.PresubmitOutput) |
output.should_continue().AndReturn(False) |
@@ -684,9 +686,37 @@ def CheckChangeOnCommit(input_api, output_api): |
None, False).AndReturn(output) |
self.mox.ReplayAll() |
- self.assertEquals(True, |
- presubmit.Main(['presubmit', '--root', |
- self.fake_root_dir])) |
+ self.assertEquals( |
+ True, |
+ presubmit.Main(['--root', self.fake_root_dir, 'random_file.txt'])) |
+ |
+ def testMainUnversionedFail(self): |
+ # OptParser calls presubmit.os.path.exists and is a pain when mocked. |
+ self.UnMock(presubmit.os.path, 'exists') |
+ self.mox.StubOutWithMock(presubmit, 'DoPresubmitChecks') |
+ self.mox.StubOutWithMock(presubmit, 'ParseFiles') |
+ presubmit.os.path.isdir(presubmit.os.path.join(self.fake_root_dir, '.svn') |
+ ).AndReturn(False) |
+ presubmit.os.path.isdir(presubmit.os.path.join(self.fake_root_dir, '.git') |
+ ).AndReturn(False) |
+ presubmit.subprocess.call( |
+ ['git', 'rev-parse', '--show-cdup'], |
+ cwd=self.fake_root_dir, |
+ stdout=presubmit.subprocess.PIPE).AndReturn(1) |
+ self.mox.StubOutWithMock(presubmit.sys, 'stderr') |
+ presubmit.sys.stderr.write( |
+ 'Usage: presubmit_unittest.py [options] <files...>\n') |
+ presubmit.sys.stderr.write('\n') |
+ presubmit.sys.stderr.write( |
+ 'presubmit_unittest.py: error: For unversioned directory, <files> is ' |
+ 'not optional.\n') |
+ self.mox.ReplayAll() |
+ |
+ try: |
+ presubmit.Main(['--root', self.fake_root_dir]) |
+ self.fail() |
+ except SystemExit, e: |
+ self.assertEquals(2, e.code) |
Dirk Pranke
2011/03/17 19:12:56
This is the sort of thing that makes mock testing
|
class InputApiUnittest(PresubmitTestsBase): |