Remove SVN support from PRESUBMIT
R=maruel@chromium.org
BUG=475320
Review-Url: https://codereview.chromium.org/2394043002
diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py
index b47629d..36dd6f9 100644
--- a/presubmit_canned_checks.py
+++ b/presubmit_canned_checks.py
@@ -420,53 +420,6 @@
return []
-def CheckChangeSvnEolStyle(input_api, output_api, source_file_filter=None):
- """Checks that the source files have svn:eol-style=LF."""
- return CheckSvnProperty(input_api, output_api,
- 'svn:eol-style', 'LF',
- input_api.AffectedSourceFiles(source_file_filter))
-
-
-def CheckSvnForCommonMimeTypes(input_api, output_api):
- """Checks that common binary file types have the correct svn:mime-type."""
- output = []
- files = input_api.AffectedFiles(include_deletes=False)
- def IsExts(x, exts):
- path = x.LocalPath()
- for extension in exts:
- if path.endswith(extension):
- return True
- return False
- def FilterFiles(extension):
- return filter(lambda x: IsExts(x, extension), files)
- def RunCheck(mime_type, files):
- output.extend(CheckSvnProperty(input_api, output_api, 'svn:mime-type',
- mime_type, files))
- RunCheck('application/pdf', FilterFiles(['.pdf']))
- RunCheck('image/bmp', FilterFiles(['.bmp']))
- RunCheck('image/gif', FilterFiles(['.gif']))
- RunCheck('image/png', FilterFiles(['.png']))
- RunCheck('image/jpeg', FilterFiles(['.jpg', '.jpeg', '.jpe']))
- RunCheck('image/vnd.microsoft.icon', FilterFiles(['.ico']))
- return output
-
-
-def CheckSvnProperty(input_api, output_api, prop, expected, affected_files):
- """Checks that affected_files files have prop=expected."""
- if input_api.change.scm != 'svn':
- return []
-
- bad = filter(lambda f: f.Property(prop) != expected, affected_files)
- if bad:
- if input_api.is_committing:
- res_type = output_api.PresubmitError
- else:
- res_type = output_api.PresubmitNotifyResult
- message = 'Run the command: svn pset %s %s \\' % (prop, expected)
- return [res_type(message, items=bad)]
- return []
-
-
### Other checks
def CheckDoNotSubmit(input_api, output_api):
@@ -1124,17 +1077,11 @@
snapshot("checking nsobjects")
results.extend(_CheckConstNSObject(
input_api, output_api, source_file_filter=sources))
- snapshot("checking eol style")
- results.extend(input_api.canned_checks.CheckChangeSvnEolStyle(
- input_api, output_api, source_file_filter=text_files))
snapshot("checking license")
results.extend(input_api.canned_checks.CheckLicense(
input_api, output_api, license_header, source_file_filter=sources))
if input_api.is_committing:
- snapshot("checking svn mime types")
- results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes(
- input_api, output_api))
snapshot("checking was uploaded")
results.extend(input_api.canned_checks.CheckChangeWasUploaded(
input_api, output_api))
diff --git a/presubmit_support.py b/presubmit_support.py
index 30ef7a9..6b3581d 100755
--- a/presubmit_support.py
+++ b/presubmit_support.py
@@ -418,35 +418,7 @@
"""
return self._current_presubmit_path
- def DepotToLocalPath(self, depot_path):
- """Translate a depot path to a local path (relative to client root).
-
- Args:
- Depot path as a string.
-
- Returns:
- The local path of the depot path under the user's current client, or None
- if the file is not mapped.
-
- Remember to check for the None case and show an appropriate error!
- """
- return scm.SVN.CaptureLocalInfo([depot_path], self.change.RepositoryRoot()
- ).get('Path')
-
- def LocalToDepotPath(self, local_path):
- """Translate a local path to a depot path.
-
- Args:
- Local path (relative to current directory, or absolute) as a string.
-
- Returns:
- The depot path (SVN URL) of the file if mapped, otherwise None.
- """
- return scm.SVN.CaptureLocalInfo([local_path], self.change.RepositoryRoot()
- ).get('URL')
-
- def AffectedFiles(self, include_dirs=False, include_deletes=True,
- file_filter=None):
+ def AffectedFiles(self, include_deletes=True, file_filter=None):
"""Same as input_api.change.AffectedFiles() except only lists files
(and optionally directories) in the same directory as the current presubmit
script, or subdirectories thereof.
@@ -457,34 +429,34 @@
return filter(
lambda x: normpath(x.AbsoluteLocalPath()).startswith(dir_with_slash),
- self.change.AffectedFiles(include_dirs, include_deletes, file_filter))
+ self.change.AffectedFiles(include_deletes, file_filter))
- def LocalPaths(self, include_dirs=False):
+ def LocalPaths(self):
"""Returns local paths of input_api.AffectedFiles()."""
- paths = [af.LocalPath() for af in self.AffectedFiles(include_dirs)]
+ paths = [af.LocalPath() for af in self.AffectedFiles()]
logging.debug("LocalPaths: %s", paths)
return paths
- def AbsoluteLocalPaths(self, include_dirs=False):
+ def AbsoluteLocalPaths(self):
"""Returns absolute local paths of input_api.AffectedFiles()."""
- return [af.AbsoluteLocalPath() for af in self.AffectedFiles(include_dirs)]
+ return [af.AbsoluteLocalPath() for af in self.AffectedFiles()]
- def ServerPaths(self, include_dirs=False):
- """Returns server paths of input_api.AffectedFiles()."""
- return [af.ServerPath() for af in self.AffectedFiles(include_dirs)]
-
- def AffectedTextFiles(self, include_deletes=None):
- """Same as input_api.change.AffectedTextFiles() except only lists files
+ def AffectedTestableFiles(self, include_deletes=None):
+ """Same as input_api.change.AffectedTestableFiles() except only lists files
in the same directory as the current presubmit script, or subdirectories
thereof.
"""
if include_deletes is not None:
- warn("AffectedTextFiles(include_deletes=%s)"
+ warn("AffectedTestableFiles(include_deletes=%s)"
" is deprecated and ignored" % str(include_deletes),
category=DeprecationWarning,
stacklevel=2)
- return filter(lambda x: x.IsTextFile(),
- self.AffectedFiles(include_dirs=False, include_deletes=False))
+ return filter(lambda x: x.IsTestableFile(),
+ self.AffectedFiles(include_deletes=False))
+
+ def AffectedTextFiles(self, include_deletes=None):
+ """An alias to AffectedTestableFiles for backwards compatibility."""
+ return self.AffectedTestableFiles(include_deletes=include_deletes)
def FilterSourceFile(self, affected_file, white_list=None, black_list=None):
"""Filters out files that aren't considered "source file".
@@ -507,13 +479,13 @@
not Find(affected_file, black_list or self.DEFAULT_BLACK_LIST))
def AffectedSourceFiles(self, source_file):
- """Filter the list of AffectedTextFiles by the function source_file.
+ """Filter the list of AffectedTestableFiles by the function source_file.
If source_file is None, InputApi.FilterSourceFile() is used.
"""
if not source_file:
source_file = self.FilterSourceFile
- return filter(source_file, self.AffectedTextFiles())
+ return filter(source_file, self.AffectedTestableFiles())
def RightHandSideLines(self, source_file_filter=None):
"""An iterator over all text lines in "new" version of changed files.
@@ -586,19 +558,6 @@
raise NotImplementedError()
-class _SvnDiffCache(_DiffCache):
- """DiffCache implementation for subversion."""
- def __init__(self, *args, **kwargs):
- super(_SvnDiffCache, self).__init__(*args, **kwargs)
- self._diffs_by_file = {}
-
- def GetDiff(self, path, local_root):
- if path not in self._diffs_by_file:
- self._diffs_by_file[path] = scm.SVN.GenerateDiff([path], local_root,
- False, None)
- return self._diffs_by_file[path]
-
-
class _GitDiffCache(_DiffCache):
"""DiffCache implementation for git; gets all file diffs at once."""
def __init__(self, upstream):
@@ -653,19 +612,11 @@
self._action = action
self._local_root = repository_root
self._is_directory = None
- self._properties = {}
self._cached_changed_contents = None
self._cached_new_contents = None
self._diff_cache = diff_cache
logging.debug('%s(%s)', self.__class__.__name__, self._path)
- def ServerPath(self):
- """Returns a path string that identifies the file in the SCM system.
-
- Returns the empty string if the file does not exist in SCM.
- """
- return ''
-
def LocalPath(self):
"""Returns the path of this file on the local disk relative to client root.
"""
@@ -676,32 +627,22 @@
"""
return os.path.abspath(os.path.join(self._local_root, self.LocalPath()))
- def IsDirectory(self):
- """Returns true if this object is a directory."""
- if self._is_directory is None:
- path = self.AbsoluteLocalPath()
- self._is_directory = (os.path.exists(path) and
- os.path.isdir(path))
- return self._is_directory
-
def Action(self):
"""Returns the action on this opened file, e.g. A, M, D, etc."""
# TODO(maruel): Somewhat crappy, Could be "A" or "A +" for svn but
# different for other SCM.
return self._action
- def Property(self, property_name):
- """Returns the specified SCM property of this file, or None if no such
- property.
- """
- return self._properties.get(property_name, None)
-
- def IsTextFile(self):
+ def IsTestableFile(self):
"""Returns True if the file is a text file and not a binary file.
Deleted files are not text file."""
raise NotImplementedError() # Implement when needed
+ def IsTextFile(self):
+ """An alias to IsTestableFile for backwards compatibility."""
+ return self.IsTestableFile()
+
def NewContents(self):
"""Returns an iterator over the lines in the new version of file.
@@ -713,12 +654,11 @@
"""
if self._cached_new_contents is None:
self._cached_new_contents = []
- if not self.IsDirectory():
- try:
- self._cached_new_contents = gclient_utils.FileRead(
- self.AbsoluteLocalPath(), 'rU').splitlines()
- except IOError:
- pass # File not found? That's fine; maybe it was deleted.
+ try:
+ self._cached_new_contents = gclient_utils.FileRead(
+ self.AbsoluteLocalPath(), 'rU').splitlines()
+ except IOError:
+ pass # File not found? That's fine; maybe it was deleted.
return self._cached_new_contents[:]
def ChangedContents(self):
@@ -734,9 +674,6 @@
self._cached_changed_contents = []
line_num = 0
- if self.IsDirectory():
- return []
-
for line in self.GenerateScmDiff().splitlines():
m = re.match(r'^@@ [0-9\,\+\-]+ \+([0-9]+)\,[0-9]+ @@', line)
if m:
@@ -755,57 +692,6 @@
return self._diff_cache.GetDiff(self.LocalPath(), self._local_root)
-class SvnAffectedFile(AffectedFile):
- """Representation of a file in a change out of a Subversion checkout."""
- # Method 'NNN' is abstract in class 'NNN' but is not overridden
- # pylint: disable=W0223
-
- DIFF_CACHE = _SvnDiffCache
-
- def __init__(self, *args, **kwargs):
- AffectedFile.__init__(self, *args, **kwargs)
- self._server_path = None
- self._is_text_file = None
-
- def ServerPath(self):
- if self._server_path is None:
- self._server_path = scm.SVN.CaptureLocalInfo(
- [self.LocalPath()], self._local_root).get('URL', '')
- return self._server_path
-
- def IsDirectory(self):
- if self._is_directory is None:
- path = self.AbsoluteLocalPath()
- if os.path.exists(path):
- # Retrieve directly from the file system; it is much faster than
- # querying subversion, especially on Windows.
- self._is_directory = os.path.isdir(path)
- else:
- self._is_directory = scm.SVN.CaptureLocalInfo(
- [self.LocalPath()], self._local_root
- ).get('Node Kind') in ('dir', 'directory')
- return self._is_directory
-
- def Property(self, property_name):
- if not property_name in self._properties:
- self._properties[property_name] = scm.SVN.GetFileProperty(
- self.LocalPath(), property_name, self._local_root).rstrip()
- return self._properties[property_name]
-
- def IsTextFile(self):
- if self._is_text_file is None:
- if self.Action() == 'D':
- # A deleted file is not a text file.
- self._is_text_file = False
- elif self.IsDirectory():
- self._is_text_file = False
- else:
- mime_type = scm.SVN.GetFileProperty(
- self.LocalPath(), 'svn:mime-type', self._local_root)
- self._is_text_file = (not mime_type or mime_type.startswith('text/'))
- return self._is_text_file
-
-
class GitAffectedFile(AffectedFile):
"""Representation of a file in a change out of a git checkout."""
# Method 'NNN' is abstract in class 'NNN' but is not overridden
@@ -816,39 +702,16 @@
def __init__(self, *args, **kwargs):
AffectedFile.__init__(self, *args, **kwargs)
self._server_path = None
- self._is_text_file = None
+ self._is_testable_file = None
- def ServerPath(self):
- if self._server_path is None:
- raise NotImplementedError('TODO(maruel) Implement.')
- return self._server_path
-
- def IsDirectory(self):
- if self._is_directory is None:
- path = self.AbsoluteLocalPath()
- if os.path.exists(path):
- # Retrieve directly from the file system; it is much faster than
- # querying subversion, especially on Windows.
- self._is_directory = os.path.isdir(path)
- else:
- self._is_directory = False
- return self._is_directory
-
- def Property(self, property_name):
- if not property_name in self._properties:
- raise NotImplementedError('TODO(maruel) Implement.')
- return self._properties[property_name]
-
- def IsTextFile(self):
- if self._is_text_file is None:
+ def IsTestableFile(self):
+ if self._is_testable_file is None:
if self.Action() == 'D':
- # A deleted file is not a text file.
- self._is_text_file = False
- elif self.IsDirectory():
- self._is_text_file = False
+ # A deleted file is not testable.
+ self._is_testable_file = False
else:
- self._is_text_file = os.path.isfile(self.AbsoluteLocalPath())
- return self._is_text_file
+ self._is_testable_file = os.path.isfile(self.AbsoluteLocalPath())
+ return self._is_testable_file
class Change(object):
@@ -950,51 +813,44 @@
"""List all files under source control in the repo."""
raise NotImplementedError()
- def AffectedFiles(self, include_dirs=False, include_deletes=True,
- file_filter=None):
+ def AffectedFiles(self, include_deletes=True, file_filter=None):
"""Returns a list of AffectedFile instances for all files in the change.
Args:
include_deletes: If false, deleted files will be filtered out.
- include_dirs: True to include directories in the list
file_filter: An additional filter to apply.
Returns:
[AffectedFile(path, action), AffectedFile(path, action)]
"""
- if include_dirs:
- affected = self._affected_files
- else:
- affected = filter(lambda x: not x.IsDirectory(), self._affected_files)
-
- affected = filter(file_filter, affected)
+ affected = filter(file_filter, self._affected_files)
if include_deletes:
return affected
else:
return filter(lambda x: x.Action() != 'D', affected)
- def AffectedTextFiles(self, include_deletes=None):
+ def AffectedTestableFiles(self, include_deletes=None):
"""Return a list of the existing text files in a change."""
if include_deletes is not None:
- warn("AffectedTextFiles(include_deletes=%s)"
+ warn("AffectedTeestableFiles(include_deletes=%s)"
" is deprecated and ignored" % str(include_deletes),
category=DeprecationWarning,
stacklevel=2)
- return filter(lambda x: x.IsTextFile(),
- self.AffectedFiles(include_dirs=False, include_deletes=False))
+ return filter(lambda x: x.IsTestableFile(),
+ self.AffectedFiles(include_deletes=False))
- def LocalPaths(self, include_dirs=False):
- """Convenience function."""
- return [af.LocalPath() for af in self.AffectedFiles(include_dirs)]
+ def AffectedTextFiles(self, include_deletes=None):
+ """An alias to AffectedTestableFiles for backwards compatibility."""
+ return self.AffectedTestableFiles(include_deletes=include_deletes)
- def AbsoluteLocalPaths(self, include_dirs=False):
+ def LocalPaths(self):
"""Convenience function."""
- return [af.AbsoluteLocalPath() for af in self.AffectedFiles(include_dirs)]
+ return [af.LocalPath() for af in self.AffectedFiles()]
- def ServerPaths(self, include_dirs=False):
+ def AbsoluteLocalPaths(self):
"""Convenience function."""
- return [af.ServerPath() for af in self.AffectedFiles(include_dirs)]
+ return [af.AbsoluteLocalPath() for af in self.AffectedFiles()]
def RightHandSideLines(self):
"""An iterator over all text lines in "new" version of changed files.
@@ -1012,19 +868,7 @@
"""
return _RightHandSideLinesImpl(
x for x in self.AffectedFiles(include_deletes=False)
- if x.IsTextFile())
-
-
-class SvnChange(Change):
- _AFFECTED_FILES = SvnAffectedFile
- scm = 'svn'
- _changelists = None
-
- def AllFiles(self, root=None):
- """List all files under source control in the repo."""
- root = root or self.RepositoryRoot()
- return subprocess.check_output(
- ['svn', 'ls', '-R', '.'], cwd=root).splitlines()
+ if x.IsTestableFile())
class GitChange(Change):
@@ -1383,7 +1227,7 @@
output.write("Running presubmit upload checks ...\n")
start_time = time.time()
presubmit_files = ListRelevantPresubmitFiles(
- change.AbsoluteLocalPaths(True), change.RepositoryRoot())
+ change.AbsoluteLocalPaths(), change.RepositoryRoot())
if not presubmit_files and verbose:
output.write("Warning, no PRESUBMIT.py found.\n")
results = []
@@ -1475,15 +1319,11 @@
def load_files(options, args):
"""Tries to determine the SCM."""
- change_scm = scm.determine_scm(options.root)
files = []
if args:
files = ParseFiles(args, options.recursive)
- if change_scm == 'svn':
- change_class = SvnChange
- if not files:
- files = scm.SVN.CaptureStatus([], options.root)
- elif change_scm == 'git':
+ change_scm = scm.determine_scm(options.root)
+ if change_scm == 'git':
change_class = GitChange
upstream = options.upstream or None
if not files:
diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py
index ad1219b..51bd22c 100755
--- a/tests/presubmit_unittest.py
+++ b/tests/presubmit_unittest.py
@@ -56,8 +56,10 @@
"""
presubmit_diffs = """
---- file1 2011-02-09 10:38:16.517224845 -0800
-+++ file2 2011-02-09 10:38:53.177226516 -0800
+diff --git %(filename)s %(filename)s
+index fe3de7b..54ae6e1 100755
+--- %(filename)s 2011-02-09 10:38:16.517224845 -0800
++++ %(filename)s 2011-02-09 10:38:53.177226516 -0800
@@ -1,6 +1,5 @@
this is line number 0
this is line number 1
@@ -138,11 +140,8 @@
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')
self.mox.StubOutWithMock(presubmit.gclient_utils, 'FileWrite')
- self.mox.StubOutWithMock(presubmit.scm.SVN, 'GenerateDiff')
self.mox.StubOutWithMock(presubmit.scm.GIT, 'GenerateDiff')
# On some platforms this does all sorts of undesirable system calls, so
@@ -164,7 +163,7 @@
'GitChange', 'InputApi', 'ListRelevantPresubmitFiles', 'main',
'NonexistantCannedCheckFilter', 'OutputApi', 'ParseFiles',
'PresubmitFailure', 'PresubmitExecuter', 'PresubmitOutput', 'ScanSubDirs',
- 'SvnAffectedFile', 'SvnChange', 'auth', 'cPickle', 'cpplint', 'cStringIO',
+ 'auth', 'cPickle', 'cpplint', 'cStringIO',
'contextlib', 'canned_check_filter', 'fix_encoding', 'fnmatch',
'gclient_utils', 'glob', 'inspect', 'json', 'load_files', 'logging',
'marshal', 'normpath', 'optparse', 'os', 'owners', 'pickle',
@@ -296,127 +295,6 @@
self.failUnlessEqual(m.group('key'), 'BUG')
self.failUnlessEqual(m.group('value'), '1223, 1445')
- def testGclChange(self):
- description_lines = ('Hello there',
- 'this is a change',
- 'BUG=123',
- ' STORY =http://foo/ \t',
- 'and some more regular text \t')
- files = [
- ['A', 'foo/blat.cc'],
- ['M', 'binary.dll'], # a binary file
- ['A', 'isdir'], # a directory
- ['?', 'flop/notfound.txt'], # not found in SVN, still exists locally
- ['D', 'boo/flap.h'],
- ]
- blat = presubmit.os.path.join('foo', 'blat.cc')
- notfound = presubmit.os.path.join('flop', 'notfound.txt')
- flap = presubmit.os.path.join('boo', 'flap.h')
- binary = 'binary.dll'
- isdir = 'isdir'
- f_blat = presubmit.os.path.join(self.fake_root_dir, blat)
- f_notfound = presubmit.os.path.join(self.fake_root_dir, notfound)
- f_flap = presubmit.os.path.join(self.fake_root_dir, flap)
- f_binary = presubmit.os.path.join(self.fake_root_dir, binary)
- f_isdir = presubmit.os.path.join(self.fake_root_dir, isdir)
- presubmit.os.path.exists(f_blat).AndReturn(True)
- presubmit.os.path.isdir(f_blat).AndReturn(False)
- presubmit.os.path.exists(f_binary).AndReturn(True)
- presubmit.os.path.isdir(f_binary).AndReturn(False)
- presubmit.os.path.exists(f_isdir).AndReturn(True)
- presubmit.os.path.isdir(f_isdir).AndReturn(True)
- presubmit.os.path.exists(f_notfound).AndReturn(True)
- presubmit.os.path.isdir(f_notfound).AndReturn(False)
- presubmit.os.path.exists(f_flap).AndReturn(False)
- presubmit.scm.SVN._CaptureInfo([flap], self.fake_root_dir
- ).AndReturn({'Node Kind': 'file'})
- presubmit.scm.SVN.GetFileProperty(
- blat, 'svn:mime-type', self.fake_root_dir).AndReturn(None)
- presubmit.scm.SVN.GetFileProperty(
- binary, 'svn:mime-type', self.fake_root_dir
- ).AndReturn('application/octet-stream')
- presubmit.scm.SVN.GetFileProperty(
- notfound, 'svn:mime-type', self.fake_root_dir).AndReturn('')
- presubmit.scm.SVN._CaptureInfo([blat], self.fake_root_dir).AndReturn(
- {'URL': 'svn:/foo/foo/blat.cc'})
- presubmit.scm.SVN._CaptureInfo([binary], self.fake_root_dir).AndReturn(
- {'URL': 'svn:/foo/binary.dll'})
- presubmit.scm.SVN._CaptureInfo([notfound], self.fake_root_dir).AndReturn({})
- presubmit.scm.SVN._CaptureInfo([flap], self.fake_root_dir).AndReturn(
- {'URL': 'svn:/foo/boo/flap.h'})
- presubmit.scm.SVN.GenerateDiff([blat], self.fake_root_dir, False, None
- ).AndReturn(self.presubmit_diffs)
- presubmit.scm.SVN.GenerateDiff([notfound], self.fake_root_dir, False, None
- ).AndReturn(self.presubmit_diffs)
-
- self.mox.ReplayAll()
-
- change = presubmit.SvnChange(
- 'mychange',
- '\n'.join(description_lines),
- self.fake_root_dir,
- files,
- 0,
- 0,
- None)
- self.failUnless(change.Name() == 'mychange')
- self.failUnless(change.DescriptionText() ==
- 'Hello there\nthis is a change\nand some more regular text')
- self.failUnless(change.FullDescriptionText() ==
- '\n'.join(description_lines))
-
- self.failUnless(change.BUG == '123')
- self.failUnless(change.STORY == 'http://foo/')
- self.failUnless(change.BLEH == None)
-
- self.failUnless(len(change.AffectedFiles()) == 4)
- self.failUnless(len(change.AffectedFiles(include_dirs=True)) == 5)
- self.failUnless(len(change.AffectedFiles(include_deletes=False)) == 3)
- self.failUnless(len(change.AffectedFiles(include_dirs=True,
- include_deletes=False)) == 4)
-
- affected_text_files = change.AffectedTextFiles()
- self.failUnless(len(affected_text_files) == 2)
- self.failIf(filter(lambda x: x.LocalPath() == 'binary.dll',
- affected_text_files))
-
- local_paths = change.LocalPaths()
- expected_paths = [presubmit.normpath(f[1]) for f in files]
- self.failUnless(
- len(filter(lambda x: x in expected_paths, local_paths)) == 4)
-
- server_paths = change.ServerPaths()
- expected_paths = ['svn:/foo/%s' % f[1] for f in files if
- f[1] != 'flop/notfound.txt']
- expected_paths.append('') # one unknown file
- self.assertEqual(
- len(filter(lambda x: x in expected_paths, server_paths)), 4)
-
- files = [[x[0], presubmit.normpath(x[1])] for x in files]
-
- rhs_lines = []
- for line in change.RightHandSideLines():
- rhs_lines.append(line)
- self.assertEquals(rhs_lines[0][0].LocalPath(), files[0][1])
- self.assertEquals(rhs_lines[0][1], 10)
- self.assertEquals(rhs_lines[0][2],'this is line number 10')
-
- self.assertEquals(rhs_lines[3][0].LocalPath(), files[0][1])
- self.assertEquals(rhs_lines[3][1], 32)
- self.assertEquals(rhs_lines[3][2], 'this is line number 32.1')
-
- self.assertEquals(rhs_lines[8][0].LocalPath(), files[3][1])
- self.assertEquals(rhs_lines[8][1], 23)
- self.assertEquals(rhs_lines[8][2], 'this is line number 23.1')
-
- self.assertEquals(rhs_lines[12][0].LocalPath(), files[3][1])
- self.assertEquals(rhs_lines[12][1], 46)
- self.assertEquals(rhs_lines[12][2], '')
-
- self.assertEquals(rhs_lines[13][0].LocalPath(), files[3][1])
- self.assertEquals(rhs_lines[13][1], 49)
- self.assertEquals(rhs_lines[13][2], 'this is line number 48.1')
-
def testGitChange(self):
description_lines = ('Hello there',
'this is a change',
@@ -523,10 +401,7 @@
for op, path in files:
full_path = presubmit.os.path.join(self.fake_root_dir, *path.split('/'))
- if op.startswith('D'):
- os.path.exists(full_path).AndReturn(False)
- else:
- os.path.exists(full_path).AndReturn(False)
+ if not op.startswith('D'):
os.path.isfile(full_path).AndReturn(True)
presubmit.scm.GIT.GenerateDiff(
@@ -555,26 +430,19 @@
self.failUnless(change.BLEH == None)
self.failUnless(len(change.AffectedFiles()) == 7)
- self.failUnless(len(change.AffectedFiles(include_dirs=True)) == 7)
+ self.failUnless(len(change.AffectedFiles()) == 7)
self.failUnless(len(change.AffectedFiles(include_deletes=False)) == 5)
- self.failUnless(len(change.AffectedFiles(include_dirs=True,
- include_deletes=False)) == 5)
+ self.failUnless(len(change.AffectedFiles(include_deletes=False)) == 5)
# Note that on git, there's no distinction between binary files and text
# files; everything that's not a delete is a text file.
- affected_text_files = change.AffectedTextFiles()
+ affected_text_files = change.AffectedTestableFiles()
self.failUnless(len(affected_text_files) == 5)
local_paths = change.LocalPaths()
expected_paths = [os.path.normpath(f) for op, f in files]
self.assertEqual(local_paths, expected_paths)
- try:
- _ = change.ServerPaths()
- self.fail("ServerPaths implemented.")
- except NotImplementedError:
- pass
-
actual_rhs_lines = []
for f, linenum, line in change.RightHandSideLines():
actual_rhs_lines.append((f.LocalPath(), linenum, line))
@@ -608,7 +476,7 @@
def testInvalidChange(self):
try:
- presubmit.SvnChange(
+ presubmit.GitChange(
'mychange',
'description',
self.fake_root_dir,
@@ -870,27 +738,6 @@
'on the file to figure out who to ask for help.\n')
self.assertEquals(output.getvalue(), text)
- def testDirectoryHandling(self):
- files = [
- ['A', 'isdir'],
- ['A', presubmit.os.path.join('isdir', 'blat.cc')],
- ]
- isdir = presubmit.os.path.join(self.fake_root_dir, 'isdir')
- blat = presubmit.os.path.join(isdir, 'blat.cc')
- presubmit.os.path.exists(isdir).AndReturn(True)
- presubmit.os.path.isdir(isdir).AndReturn(True)
- presubmit.os.path.exists(blat).AndReturn(True)
- presubmit.os.path.isdir(blat).AndReturn(False)
- self.mox.ReplayAll()
-
- change = presubmit.Change(
- 'mychange', 'foo', self.fake_root_dir, files, 0, 0, None)
- affected_files = change.AffectedFiles(include_dirs=False)
- self.failUnless(len(affected_files) == 1)
- self.failUnless(affected_files[0].LocalPath().endswith('blat.cc'))
- affected_files_and_dirs = change.AffectedFiles(include_dirs=True)
- self.failUnless(len(affected_files_and_dirs) == 2)
-
def testTags(self):
DEFAULT_SCRIPT = """
def CheckChangeOnUpload(input_api, output_api):
@@ -1103,19 +950,17 @@
'AbsoluteLocalPaths',
'AffectedFiles',
'AffectedSourceFiles',
+ 'AffectedTestableFiles',
'AffectedTextFiles',
'DEFAULT_BLACK_LIST',
'DEFAULT_WHITE_LIST',
- 'DepotToLocalPath',
'FilterSourceFile',
'LocalPaths',
- 'LocalToDepotPath',
'Command',
'RunTests',
'PresubmitLocalPath',
'ReadFile',
'RightHandSideLines',
- 'ServerPaths',
'ShutdownPool',
'basename',
'cPickle',
@@ -1159,38 +1004,6 @@
presubmit.InputApi(self.fake_change, './.', False, None, False),
members)
- def testDepotToLocalPath(self):
- presubmit.scm.SVN._CaptureInfo(['svn://foo/smurf'], self.fake_root_dir
- ).AndReturn({'Path': 'prout'})
- presubmit.scm.SVN._CaptureInfo(
- ['svn:/foo/notfound/burp'], self.fake_root_dir
- ).AndReturn({})
- self.mox.ReplayAll()
-
- path = presubmit.InputApi(
- self.fake_change, './p', False, None, False).DepotToLocalPath(
- 'svn://foo/smurf')
- self.failUnless(path == 'prout')
- path = presubmit.InputApi(
- self.fake_change, './p', False, None, False).DepotToLocalPath(
- 'svn:/foo/notfound/burp')
- self.failUnless(path == None)
-
- def testLocalToDepotPath(self):
- presubmit.scm.SVN._CaptureInfo(['smurf'], self.fake_root_dir
- ).AndReturn({'URL': 'svn://foo'})
- presubmit.scm.SVN._CaptureInfo(['notfound-food'], self.fake_root_dir
- ).AndReturn({})
- self.mox.ReplayAll()
- path = presubmit.InputApi(
- self.fake_change, './p', False, None, False).LocalToDepotPath(
- 'smurf')
- self.assertEqual(path, 'svn://foo')
- path = presubmit.InputApi(
- self.fake_change, './p', False, None, False).LocalToDepotPath(
- 'notfound-food')
- self.assertEquals(path, None)
-
def testInputApiConstruction(self):
self.mox.ReplayAll()
api = presubmit.InputApi(
@@ -1209,68 +1022,33 @@
' STORY =http://foo/ \t',
'and some more regular text')
files = [
- ['A', join('foo', 'blat.cc')],
- ['M', join('foo', 'blat', 'READ_ME2')],
- ['M', join('foo', 'blat', 'binary.dll')],
- ['M', join('foo', 'blat', 'weird.xyz')],
- ['M', join('foo', 'blat', 'another.h')],
- ['M', join('foo', 'third_party', 'third.cc')],
- ['D', join('foo', 'mat', 'beingdeleted.txt')],
- ['M', join('flop', 'notfound.txt')],
- ['A', join('boo', 'flap.h')],
+ ['A', join('foo', 'blat.cc'), True],
+ ['M', join('foo', 'blat', 'READ_ME2'), True],
+ ['M', join('foo', 'blat', 'binary.dll'), True],
+ ['M', join('foo', 'blat', 'weird.xyz'), True],
+ ['M', join('foo', 'blat', 'another.h'), True],
+ ['M', join('foo', 'third_party', 'third.cc'), True],
+ ['D', join('foo', 'mat', 'beingdeleted.txt'), False],
+ ['M', join('flop', 'notfound.txt'), False],
+ ['A', join('boo', 'flap.h'), True],
]
- blat = presubmit.normpath(join(self.fake_root_dir, files[0][1]))
- readme = presubmit.normpath(join(self.fake_root_dir, files[1][1]))
- binary = presubmit.normpath(join(self.fake_root_dir, files[2][1]))
- weird = presubmit.normpath(join(self.fake_root_dir, files[3][1]))
- another = presubmit.normpath(join(self.fake_root_dir, files[4][1]))
- third_party = presubmit.normpath(join(self.fake_root_dir, files[5][1]))
- beingdeleted = presubmit.normpath(join(self.fake_root_dir, files[6][1]))
- notfound = presubmit.normpath(join(self.fake_root_dir, files[7][1]))
- flap = presubmit.normpath(join(self.fake_root_dir, files[8][1]))
- for i in (blat, readme, binary, weird, another, third_party):
- presubmit.os.path.exists(i).AndReturn(True)
- presubmit.os.path.isdir(i).AndReturn(False)
- presubmit.os.path.exists(beingdeleted).AndReturn(False)
- presubmit.os.path.exists(notfound).AndReturn(False)
- presubmit.os.path.exists(flap).AndReturn(True)
- presubmit.os.path.isdir(flap).AndReturn(False)
- presubmit.scm.SVN._CaptureInfo(
- [files[6][1]], self.fake_root_dir).AndReturn({})
- presubmit.scm.SVN._CaptureInfo(
- [files[7][1]], self.fake_root_dir).AndReturn({})
- presubmit.scm.SVN.GetFileProperty(
- files[0][1], 'svn:mime-type', self.fake_root_dir
- ).AndReturn(None)
- presubmit.scm.SVN.GetFileProperty(
- files[1][1], 'svn:mime-type', self.fake_root_dir
- ).AndReturn(None)
- presubmit.scm.SVN.GetFileProperty(
- files[2][1], 'svn:mime-type', self.fake_root_dir
- ).AndReturn('application/octet-stream')
- presubmit.scm.SVN.GetFileProperty(
- files[3][1], 'svn:mime-type', self.fake_root_dir
- ).AndReturn(None)
- presubmit.scm.SVN.GetFileProperty(
- files[4][1], 'svn:mime-type', self.fake_root_dir
- ).AndReturn(None)
- presubmit.scm.SVN.GetFileProperty(
- files[5][1], 'svn:mime-type', self.fake_root_dir
- ).AndReturn(None)
- presubmit.scm.SVN.GenerateDiff(
- [files[0][1]], self.fake_root_dir, False, None
- ).AndReturn(self.presubmit_diffs)
- presubmit.scm.SVN.GenerateDiff(
- [files[4][1]], self.fake_root_dir, False, None
- ).AndReturn(self.presubmit_diffs)
+ diffs = []
+ for _, f, exists in files:
+ full_file = presubmit.os.path.join(self.fake_root_dir, f)
+ if exists and f.startswith('foo/'):
+ presubmit.os.path.isfile(full_file).AndReturn(exists)
+ diffs.append(self.presubmit_diffs % {'filename': f})
+ presubmit.scm.GIT.GenerateDiff(
+ self.fake_root_dir, branch=None, files=[], full_move=True
+ ).AndReturn('\n'.join(diffs))
self.mox.ReplayAll()
- change = presubmit.SvnChange(
+ change = presubmit.GitChange(
'mychange',
'\n'.join(description_lines),
self.fake_root_dir,
- files,
+ [[f[0], f[1]] for f in files],
0,
0,
None)
@@ -1397,13 +1175,10 @@
files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee')]
for _, item in files:
full_item = presubmit.os.path.join(self.fake_root_dir, item)
- presubmit.os.path.exists(full_item).AndReturn(True)
- presubmit.os.path.isdir(full_item).AndReturn(False)
- presubmit.scm.SVN.GetFileProperty(
- item, 'svn:mime-type', self.fake_root_dir).AndReturn(None)
+ presubmit.os.path.isfile(full_item).AndReturn(True)
self.mox.ReplayAll()
- change = presubmit.SvnChange(
+ change = presubmit.GitChange(
'mychange', '', self.fake_root_dir, files, 0, 0, None)
input_api = presubmit.InputApi(
change,
@@ -1420,13 +1195,10 @@
files = [('A', 'eeaee'), ('M', 'eeabee'), ('M', 'eebcee'), ('M', 'eecaee')]
for _, item in files:
full_item = presubmit.os.path.join(self.fake_root_dir, item)
- presubmit.os.path.exists(full_item).AndReturn(True)
- presubmit.os.path.isdir(full_item).AndReturn(False)
- presubmit.scm.SVN.GetFileProperty(
- item, 'svn:mime-type', self.fake_root_dir).AndReturn(None)
+ presubmit.os.path.isfile(full_item).AndReturn(True)
self.mox.ReplayAll()
- change = presubmit.SvnChange(
+ change = presubmit.GitChange(
'mychange', '', self.fake_root_dir, files, 0, 0, None)
input_api = presubmit.InputApi(
change, './PRESUBMIT.py', False, None, False)
@@ -1454,7 +1226,7 @@
change = presubmit.Change(
'mychange', '', self.fake_root_dir, files, 0, 0, None)
- affected_files = change.AffectedFiles(include_dirs=True)
+ affected_files = change.AffectedFiles()
# Local paths should remain the same
self.assertEquals(affected_files[0].LocalPath(), normpath('isdir'))
self.assertEquals(affected_files[1].LocalPath(), normpath('isdir/blat.cc'))
@@ -1465,13 +1237,13 @@
normpath(join(self.fake_root_dir, 'isdir/blat.cc')))
# New helper functions need to work
- paths_from_change = change.AbsoluteLocalPaths(include_dirs=True)
+ paths_from_change = change.AbsoluteLocalPaths()
self.assertEqual(len(paths_from_change), 3)
presubmit_path = join(self.fake_root_dir, 'isdir', 'PRESUBMIT.py')
api = presubmit.InputApi(
change=change, presubmit_path=presubmit_path,
is_committing=True, rietveld_obj=None, verbose=False)
- paths_from_api = api.AbsoluteLocalPaths(include_dirs=True)
+ paths_from_api = api.AbsoluteLocalPaths()
self.assertEqual(len(paths_from_api), 2)
for absolute_paths in [paths_from_change, paths_from_api]:
self.assertEqual(absolute_paths[0],
@@ -1489,7 +1261,7 @@
change,
presubmit.os.path.join(self.fake_root_dir, 'foo', 'PRESUBMIT.py'), True,
None, False)
- api.AffectedTextFiles(include_deletes=False)
+ api.AffectedTestableFiles(include_deletes=False)
def testReadFileStringDenied(self):
self.mox.ReplayAll()
@@ -1618,28 +1390,21 @@
self.mox.ReplayAll()
members = [
'AbsoluteLocalPath', 'Action', 'ChangedContents', 'DIFF_CACHE',
- 'GenerateScmDiff', 'IsDirectory', 'IsTextFile', 'LocalPath',
- 'NewContents', 'Property', 'ServerPath',
+ 'GenerateScmDiff', 'IsTestableFile', 'IsTextFile', 'LocalPath',
+ 'NewContents',
]
# If this test fails, you should add the relevant test.
self.compareMembers(
presubmit.AffectedFile('a', 'b', self.fake_root_dir, None), members)
self.compareMembers(
- presubmit.SvnAffectedFile('a', 'b', self.fake_root_dir, None), members)
- self.compareMembers(
presubmit.GitAffectedFile('a', 'b', self.fake_root_dir, None), members)
def testAffectedFile(self):
path = presubmit.os.path.join('foo', 'blat.cc')
f_path = presubmit.os.path.join(self.fake_root_dir, path)
- presubmit.os.path.exists(f_path).AndReturn(True)
- presubmit.os.path.isdir(f_path).AndReturn(False)
presubmit.gclient_utils.FileRead(f_path, 'rU').AndReturn('whatever\ncookie')
- presubmit.scm.SVN._CaptureInfo([path], self.fake_root_dir).AndReturn(
- {'URL': 'svn:/foo/foo/blat.cc'})
self.mox.ReplayAll()
- af = presubmit.SvnAffectedFile('foo/blat.cc', 'M', self.fake_root_dir, None)
- self.assertEquals('svn:/foo/foo/blat.cc', af.ServerPath())
+ af = presubmit.GitAffectedFile('foo/blat.cc', 'M', self.fake_root_dir, None)
self.assertEquals(presubmit.normpath('foo/blat.cc'), af.LocalPath())
self.assertEquals('M', af.Action())
self.assertEquals(['whatever', 'cookie'], af.NewContents())
@@ -1647,84 +1412,40 @@
def testAffectedFileNotExists(self):
notfound = 'notfound.cc'
f_notfound = presubmit.os.path.join(self.fake_root_dir, notfound)
- presubmit.os.path.exists(f_notfound).AndReturn(False)
presubmit.gclient_utils.FileRead(f_notfound, 'rU').AndRaise(IOError)
self.mox.ReplayAll()
af = presubmit.AffectedFile(notfound, 'A', self.fake_root_dir, None)
- self.assertEquals('', af.ServerPath())
self.assertEquals([], af.NewContents())
- def testProperty(self):
- presubmit.scm.SVN.GetFileProperty(
- 'foo.cc', 'svn:secret-property', self.fake_root_dir
- ).AndReturn('secret-property-value')
- self.mox.ReplayAll()
- affected_file = presubmit.SvnAffectedFile('foo.cc', 'A', self.fake_root_dir,
- None)
- # Verify cache coherency.
- self.assertEquals('secret-property-value',
- affected_file.Property('svn:secret-property'))
- self.assertEquals('secret-property-value',
- affected_file.Property('svn:secret-property'))
-
- def testIsDirectoryNotExists(self):
- filename = 'foo.cc'
- f_filename = presubmit.os.path.join(self.fake_root_dir, filename)
- presubmit.os.path.exists(f_filename).AndReturn(False)
- presubmit.scm.SVN._CaptureInfo([filename], self.fake_root_dir).AndReturn({})
- self.mox.ReplayAll()
- affected_file = presubmit.SvnAffectedFile(filename, 'A', self.fake_root_dir,
- None)
- # Verify cache coherency.
- self.failIf(affected_file.IsDirectory())
- self.failIf(affected_file.IsDirectory())
-
- def testIsDirectory(self):
- filename = 'foo.cc'
- f_filename = presubmit.os.path.join(self.fake_root_dir, filename)
- presubmit.os.path.exists(f_filename).AndReturn(True)
- presubmit.os.path.isdir(f_filename).AndReturn(True)
- self.mox.ReplayAll()
- affected_file = presubmit.SvnAffectedFile(filename, 'A', self.fake_root_dir,
- None)
- # Verify cache coherency.
- self.failUnless(affected_file.IsDirectory())
- self.failUnless(affected_file.IsDirectory())
-
- def testIsTextFile(self):
+ def testIsTestableFile(self):
files = [
- presubmit.SvnAffectedFile('foo/blat.txt', 'M', self.fake_root_dir,
+ presubmit.GitAffectedFile('foo/blat.txt', 'M', self.fake_root_dir,
None),
- presubmit.SvnAffectedFile('foo/binary.blob', 'M', self.fake_root_dir,
+ presubmit.GitAffectedFile('foo/binary.blob', 'M', self.fake_root_dir,
None),
- presubmit.SvnAffectedFile('blat/flop.txt', 'D', self.fake_root_dir,
+ presubmit.GitAffectedFile('blat/flop.txt', 'D', self.fake_root_dir,
None)
]
blat = presubmit.os.path.join('foo', 'blat.txt')
blob = presubmit.os.path.join('foo', 'binary.blob')
f_blat = presubmit.os.path.join(self.fake_root_dir, blat)
f_blob = presubmit.os.path.join(self.fake_root_dir, blob)
- presubmit.os.path.exists(f_blat).AndReturn(True)
- presubmit.os.path.isdir(f_blat).AndReturn(False)
- presubmit.os.path.exists(f_blob).AndReturn(True)
- presubmit.os.path.isdir(f_blob).AndReturn(False)
- presubmit.scm.SVN.GetFileProperty(blat, 'svn:mime-type', self.fake_root_dir
- ).AndReturn(None)
- presubmit.scm.SVN.GetFileProperty(blob, 'svn:mime-type', self.fake_root_dir
- ).AndReturn('application/octet-stream')
+ presubmit.os.path.isfile(f_blat).AndReturn(True)
+ presubmit.os.path.isfile(f_blob).AndReturn(True)
self.mox.ReplayAll()
- output = filter(lambda x: x.IsTextFile(), files)
- self.assertEquals(1, len(output))
+ output = filter(lambda x: x.IsTestableFile(), files)
+ self.assertEquals(2, len(output))
self.assertEquals(files[0], output[0])
class ChangeUnittest(PresubmitTestsBase):
def testMembersChanged(self):
members = [
- 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', 'AllFiles',
- 'DescriptionText', 'FullDescriptionText', 'LocalPaths', 'Name',
- 'RepositoryRoot', 'RightHandSideLines', 'ServerPaths',
+ 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTestableFiles',
+ 'AffectedTextFiles',
+ 'AllFiles', 'DescriptionText', 'FullDescriptionText', 'LocalPaths',
+ 'Name', 'RepositoryRoot', 'RightHandSideLines',
'SetDescriptionText', 'TAG_LINE_RE',
'author_email', 'issue', 'patchset', 'scm', 'tags',
]
@@ -1745,8 +1466,8 @@
self.assertEquals(3, change.issue)
self.assertEquals(5, change.patchset)
self.assertEquals(self.fake_root_dir, change.RepositoryRoot())
- self.assertEquals(1, len(change.AffectedFiles(include_dirs=True)))
- self.assertEquals('Y', change.AffectedFiles(include_dirs=True)[0].Action())
+ self.assertEquals(1, len(change.AffectedFiles()))
+ self.assertEquals('Y', change.AffectedFiles()[0].Action())
def testSetDescriptionText(self):
change = presubmit.Change(
@@ -1824,7 +1545,6 @@
'CheckChangeHasQaField', 'CheckChangeHasTestedField',
'CheckChangeHasTestField',
'CheckChangeLintsClean',
- 'CheckChangeSvnEolStyle',
'CheckChangeWasUploaded',
'CheckDoNotSubmit',
'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles',
@@ -1836,7 +1556,6 @@
'CheckGNFormatted',
'CheckRietveldTryJobExecution',
'CheckSingletonInHeaders',
- 'CheckSvnForCommonMimeTypes', 'CheckSvnProperty',
'RunPythonUnitTests', 'RunPylint',
'RunUnitTests', 'RunUnitTestsInDirectory',
'GetCodereviewOwnerAndReviewers',
@@ -1877,7 +1596,7 @@
change1 = presubmit.Change(
'foo1', 'foo1\n', self.fake_root_dir, None, 0, 0, None)
input_api1 = self.MockInputApi(change1, False)
- affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile)
+ affected_file = self.mox.CreateMock(presubmit.GitAffectedFile)
input_api1.AffectedFiles(
include_deletes=False,
file_filter=mox.IgnoreArg()).AndReturn([affected_file])
@@ -1924,13 +1643,13 @@
change1 = presubmit.Change(
'foo1', 'foo1\n', self.fake_root_dir, None, 0, 0, None)
input_api1 = self.MockInputApi(change1, False)
- affected_file1 = self.mox.CreateMock(presubmit.SvnAffectedFile)
+ affected_file1 = self.mox.CreateMock(presubmit.GitAffectedFile)
input_api1.AffectedSourceFiles(None).AndReturn([affected_file1])
input_api1.ReadFile(affected_file1, 'rb').AndReturn(content1)
change2 = presubmit.Change(
'foo2', 'foo2\n', self.fake_root_dir, None, 0, 0, None)
input_api2 = self.MockInputApi(change2, False)
- affected_file2 = self.mox.CreateMock(presubmit.SvnAffectedFile)
+ affected_file2 = self.mox.CreateMock(presubmit.GitAffectedFile)
input_api2.AffectedSourceFiles(None).AndReturn([affected_file2])
input_api2.ReadFile(affected_file2, 'rb').AndReturn(content2)
affected_file2.LocalPath().AndReturn('bar.cc')
@@ -1942,51 +1661,6 @@
self.assertEquals(len(results2), 1)
self.assertEquals(results2[0].__class__, error_type)
- def SvnPropertyTest(self, check, property_name, value1, value2, committing,
- error_type, use_source_file):
- change1 = presubmit.SvnChange(
- 'mychange', '', self.fake_root_dir, [], 0, 0, None)
- input_api1 = self.MockInputApi(change1, committing)
- files1 = [
- presubmit.SvnAffectedFile('foo/bar.cc', 'A', self.fake_root_dir, None),
- presubmit.SvnAffectedFile('foo.cc', 'M', self.fake_root_dir, None),
- ]
- if use_source_file:
- input_api1.AffectedSourceFiles(None).AndReturn(files1)
- else:
- input_api1.AffectedFiles(include_deletes=False).AndReturn(files1)
- presubmit.scm.SVN.GetFileProperty(
- presubmit.normpath('foo/bar.cc'), property_name, self.fake_root_dir
- ).AndReturn(value1)
- presubmit.scm.SVN.GetFileProperty(
- presubmit.normpath('foo.cc'), property_name, self.fake_root_dir
- ).AndReturn(value1)
- change2 = presubmit.SvnChange(
- 'mychange', '', self.fake_root_dir, [], 0, 0, None)
- input_api2 = self.MockInputApi(change2, committing)
- files2 = [
- presubmit.SvnAffectedFile('foo/bar.cc', 'A', self.fake_root_dir, None),
- presubmit.SvnAffectedFile('foo.cc', 'M', self.fake_root_dir, None),
- ]
- if use_source_file:
- input_api2.AffectedSourceFiles(None).AndReturn(files2)
- else:
- input_api2.AffectedFiles(include_deletes=False).AndReturn(files2)
-
- presubmit.scm.SVN.GetFileProperty(
- presubmit.normpath('foo/bar.cc'), property_name, self.fake_root_dir
- ).AndReturn(value2)
- presubmit.scm.SVN.GetFileProperty(
- presubmit.normpath('foo.cc'), property_name, self.fake_root_dir
- ).AndReturn(value2)
- self.mox.ReplayAll()
-
- results1 = check(input_api1, presubmit.OutputApi, None)
- self.assertEquals(results1, [])
- results2 = check(input_api2, presubmit.OutputApi, None)
- self.assertEquals(len(results2), 1)
- self.assertEquals(results2[0].__class__, error_type)
-
def testCannedCheckChangeHasBugField(self):
self.DescriptionTest(presubmit_canned_checks.CheckChangeHasBugField,
'Foo\nBUG=1234', 'Foo\n',
@@ -2076,14 +1750,14 @@
change1 = presubmit.Change(
'foo1', 'foo1\n', self.fake_root_dir, None, 0, 0, None)
input_api1 = self.MockInputApi(change1, False)
- affected_file1 = self.mox.CreateMock(presubmit.SvnAffectedFile)
+ affected_file1 = self.mox.CreateMock(presubmit.GitAffectedFile)
affected_file1.LocalPath().AndReturn('foo.cc')
- affected_file2 = self.mox.CreateMock(presubmit.SvnAffectedFile)
+ affected_file2 = self.mox.CreateMock(presubmit.GitAffectedFile)
affected_file2.LocalPath().AndReturn('foo/Makefile')
- affected_file3 = self.mox.CreateMock(presubmit.SvnAffectedFile)
+ affected_file3 = self.mox.CreateMock(presubmit.GitAffectedFile)
affected_file3.LocalPath().AndReturn('makefile')
# Only this one will trigger.
- affected_file4 = self.mox.CreateMock(presubmit.SvnAffectedFile)
+ affected_file4 = self.mox.CreateMock(presubmit.GitAffectedFile)
affected_file1.LocalPath().AndReturn('foo.cc')
affected_file1.NewContents().AndReturn(['yo, '])
affected_file4.LocalPath().AndReturn('makefile.foo')
@@ -2094,7 +1768,7 @@
affected_files = (affected_file1, affected_file2,
affected_file3, affected_file4)
- def test(include_dirs=False, include_deletes=True, file_filter=None):
+ def test(include_deletes=True, file_filter=None):
self.assertFalse(include_deletes)
for x in affected_files:
if file_filter(x):
@@ -2201,23 +1875,12 @@
None,
presubmit.OutputApi.PresubmitPromptWarning)
- def testCheckChangeSvnEolStyleCommit(self):
- # Test CheckSvnProperty at the same time.
- self.SvnPropertyTest(presubmit_canned_checks.CheckChangeSvnEolStyle,
- 'svn:eol-style', 'LF', '', True,
- presubmit.OutputApi.PresubmitError, True)
-
- def testCheckChangeSvnEolStyleUpload(self):
- self.SvnPropertyTest(presubmit_canned_checks.CheckChangeSvnEolStyle,
- 'svn:eol-style', 'LF', '', False,
- presubmit.OutputApi.PresubmitNotifyResult, True)
-
def _LicenseCheck(self, text, license_text, committing, expected_result,
**kwargs):
- change = self.mox.CreateMock(presubmit.SvnChange)
+ change = self.mox.CreateMock(presubmit.GitChange)
change.scm = 'svn'
input_api = self.MockInputApi(change, committing)
- affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile)
+ affected_file = self.mox.CreateMock(presubmit.GitAffectedFile)
input_api.AffectedSourceFiles(42).AndReturn([affected_file])
input_api.ReadFile(affected_file, 'rb').AndReturn(text)
if expected_result:
@@ -2283,41 +1946,6 @@
)
self._LicenseCheck(text, license_text, True, None, accept_empty_files=True)
- def testCheckSvnForCommonMimeTypes(self):
- self.mox.StubOutWithMock(presubmit_canned_checks, 'CheckSvnProperty')
- input_api = self.MockInputApi(None, False)
- output_api = presubmit.OutputApi(False)
- A = lambda x: presubmit.AffectedFile(x, 'M', self.fake_root_dir, None)
- files = [
- A('a.pdf'), A('b.bmp'), A('c.gif'), A('d.png'), A('e.jpg'), A('f.jpe'),
- A('random'), A('g.jpeg'), A('h.ico'),
- ]
- input_api.AffectedFiles(include_deletes=False).AndReturn(files)
- presubmit_canned_checks.CheckSvnProperty(
- input_api, output_api, 'svn:mime-type', 'application/pdf', [files[0]]
- ).AndReturn([1])
- presubmit_canned_checks.CheckSvnProperty(
- input_api, output_api, 'svn:mime-type', 'image/bmp', [files[1]]
- ).AndReturn([2])
- presubmit_canned_checks.CheckSvnProperty(
- input_api, output_api, 'svn:mime-type', 'image/gif', [files[2]]
- ).AndReturn([3])
- presubmit_canned_checks.CheckSvnProperty(
- input_api, output_api, 'svn:mime-type', 'image/png', [files[3]]
- ).AndReturn([4])
- presubmit_canned_checks.CheckSvnProperty(
- input_api, output_api, 'svn:mime-type', 'image/jpeg',
- [files[4], files[5], files[7]]
- ).AndReturn([5])
- presubmit_canned_checks.CheckSvnProperty(
- input_api, output_api, 'svn:mime-type', 'image/vnd.microsoft.icon',
- [files[8]]).AndReturn([6])
- self.mox.ReplayAll()
-
- results = presubmit_canned_checks.CheckSvnForCommonMimeTypes(
- input_api, output_api)
- self.assertEquals(results, [1, 2, 3, 4, 5, 6])
-
def testCannedCheckTreeIsOpenOpen(self):
input_api = self.MockInputApi(None, True)
connection = self.mox.CreateMockAnything()
@@ -2530,7 +2158,7 @@
change.author_email = 'john@example.com'
change.R = ','.join(manually_specified_reviewers)
change.TBR = ''
- affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile)
+ affected_file = self.mox.CreateMock(presubmit.GitAffectedFile)
input_api = self.MockInputApi(change, False)
if gerrit_response:
assert not rietveld_response
@@ -2926,7 +2554,7 @@
change = presubmit.Change(
'foo1', 'description1', self.fake_root_dir, None, 0, 0, None)
input_api = self.MockInputApi(change, False)
- affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile)
+ affected_file = self.mox.CreateMock(presubmit.GitAffectedFile)
for _ in range(3):
input_api.AffectedFiles(file_filter=mox.IgnoreArg(), include_deletes=False
).AndReturn([affected_file])
@@ -2942,9 +2570,6 @@
affected_file.LocalPath().AndReturn('hello.py')
input_api.AffectedSourceFiles(mox.IgnoreArg()).AndReturn([affected_file])
input_api.ReadFile(affected_file).AndReturn('Hey!\nHo!\nHey!\nHo!\n\n')
-
- input_api.AffectedSourceFiles(mox.IgnoreArg()).AndReturn([affected_file])
-
input_api.AffectedSourceFiles(mox.IgnoreArg()).AndReturn([affected_file])
input_api.ReadFile(affected_file, 'rb').AndReturn(
'Hey!\nHo!\nHey!\nHo!\n\n')