Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Unified Diff: tests/presubmit_unittest.py

Issue 6674059: Make sure warnings fail the check when may_prompt=False. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: moved determine_scm() Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« presubmit_support.py ('K') | « scm.py ('k') | tests/scm_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/presubmit_unittest.py
diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py
index 3bf7d79e317d9c848693e8f0f47f52160e2501aa..b2cb19083dabf683b7e3add0f3bc588907d7b06b 100755
--- a/tests/presubmit_unittest.py
+++ b/tests/presubmit_unittest.py
@@ -119,6 +119,7 @@ def GetPreferredTrySlaves():
presubmit.os.path.abspath = MockAbsPath
presubmit.os.getcwd = self.RootDir
presubmit.os.chdir = MockChdir
+ self.mox.StubOutWithMock(presubmit.scm, 'determine_scm')
self.mox.StubOutWithMock(presubmit.scm.SVN, 'CaptureInfo')
self.mox.StubOutWithMock(presubmit.scm.SVN, 'GetFileProperty')
self.mox.StubOutWithMock(presubmit.gclient_utils, 'FileRead')
@@ -135,12 +136,12 @@ class PresubmitUnittest(PresubmitTestsBase):
self.mox.ReplayAll()
members = [
'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks',
- 'GetTrySlavesExecuter', 'GitAffectedFile', 'GitChange',
- 'InputApi', 'ListRelevantPresubmitFiles', 'Main',
+ 'GetTrySlavesExecuter', 'GitAffectedFile',
+ 'GitChange', 'InputApi', 'ListRelevantPresubmitFiles', 'Main',
'NotImplementedException', 'OutputApi', 'ParseFiles',
'PresubmitExecuter', 'PresubmitOutput', 'ScanSubDirs',
'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO',
- 'exceptions', 'fnmatch', 'gclient_utils', 'glob', 'json',
+ 'exceptions', 'fnmatch', 'gclient_utils', 'glob', 'json', 'load_files',
'logging', 'marshal', 'normpath', 'optparse', 'os', 'owners', 'pickle',
'presubmit_canned_checks', 'random', 're', 'scm', 'subprocess',
'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2',
@@ -662,19 +663,14 @@ 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')
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)
+ presubmit.scm.determine_scm(self.fake_root_dir).AndReturn(None)
+ presubmit.ParseFiles(['random_file.txt'], None
+ ).AndReturn(['random_file.txt'])
output = self.mox.CreateMock(presubmit.PresubmitOutput)
output.should_continue().AndReturn(False)
@@ -684,9 +680,30 @@ 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.scm.determine_scm(self.fake_root_dir).AndReturn(None)
+ 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)
class InputApiUnittest(PresubmitTestsBase):
« presubmit_support.py ('K') | « scm.py ('k') | tests/scm_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698