Commit 11e0fd69 authored by maruel@chromium.org's avatar maruel@chromium.org

Revert changes 15823 and 15824 because they broke gclient revert.

TBR=sgk
Review URL: http://codereview.chromium.org/115217

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@15827 0039d316-1c4b-4281-b951-d872f2087c98
parent 46b9ae69
...@@ -18,8 +18,6 @@ import upload ...@@ -18,8 +18,6 @@ import upload
import urllib2 import urllib2
import xml.dom.minidom import xml.dom.minidom
# gcl now depends on gclient.
import gclient
__version__ = '1.0' __version__ = '1.0'
...@@ -50,16 +48,60 @@ MISSING_TEST_MSG = "Change contains new or modified methods, but no new tests!" ...@@ -50,16 +48,60 @@ MISSING_TEST_MSG = "Change contains new or modified methods, but no new tests!"
read_gcl_info = False read_gcl_info = False
### Simplified XML processing functions.
def ParseXML(output):
try:
return xml.dom.minidom.parseString(output)
except xml.parsers.expat.ExpatError:
return None
def GetNamedNodeText(node, node_name):
child_nodes = node.getElementsByTagName(node_name)
if not child_nodes:
return None
assert len(child_nodes) == 1 and child_nodes[0].childNodes.length == 1
return child_nodes[0].firstChild.nodeValue
def GetNodeNamedAttributeText(node, node_name, attribute_name):
child_nodes = node.getElementsByTagName(node_name)
if not child_nodes:
return None
assert len(child_nodes) == 1
return child_nodes[0].getAttribute(attribute_name)
### SVN Functions ### SVN Functions
def IsSVNMoved(filename): def IsSVNMoved(filename):
"""Determine if a file has been added through svn mv""" """Determine if a file has been added through svn mv"""
info = gclient.CaptureSVNInfo(filename) info = GetSVNFileInfo(filename)
return (info.get('Copied From URL') and return (info.get('Copied From URL') and
info.get('Copied From Rev') and info.get('Copied From Rev') and
info.get('Schedule') == 'add') info.get('Schedule') == 'add')
def GetSVNFileInfo(file):
"""Returns a dictionary from the svn info output for the given file."""
dom = ParseXML(RunShell(["svn", "info", "--xml", file]))
result = {}
if dom:
# /info/entry/
# url
# reposityory/(root|uuid)
# wc-info/(schedule|depth)
# commit/(author|date)
result['Node Kind'] = GetNodeNamedAttributeText(dom, 'entry', 'kind')
result['Repository Root'] = GetNamedNodeText(dom, 'root')
result['Schedule'] = GetNamedNodeText(dom, 'schedule')
result['URL'] = GetNamedNodeText(dom, 'url')
result['Path'] = GetNodeNamedAttributeText(dom, 'entry', 'path')
result['Copied From URL'] = GetNamedNodeText(dom, 'copy-from-url')
result['Copied From Rev'] = GetNamedNodeText(dom, 'copy-from-rev')
return result
def GetSVNFileProperty(file, property_name): def GetSVNFileProperty(file, property_name):
"""Returns the value of an SVN property for the given file. """Returns the value of an SVN property for the given file.
...@@ -105,7 +147,7 @@ def GetSVNStatus(file): ...@@ -105,7 +147,7 @@ def GetSVNStatus(file):
'unversioned': '?', 'unversioned': '?',
# TODO(maruel): Find the corresponding strings for X, ~ # TODO(maruel): Find the corresponding strings for X, ~
} }
dom = gclient.ParseXML(RunShell(command)) dom = ParseXML(RunShell(command))
results = [] results = []
if dom: if dom:
# /status/target/entry/(wc-status|commit|author|date) # /status/target/entry/(wc-status|commit|author|date)
...@@ -160,16 +202,14 @@ def GetRepositoryRoot(): ...@@ -160,16 +202,14 @@ def GetRepositoryRoot():
""" """
global repository_root global repository_root
if not repository_root: if not repository_root:
infos = gclient.CaptureSVNInfo(os.getcwd(), print_error=False) cur_dir_repo_root = GetSVNFileInfo(os.getcwd()).get("Repository Root")
cur_dir_repo_root = infos.get("Repository Root")
if not cur_dir_repo_root: if not cur_dir_repo_root:
raise Exception("gcl run outside of repository") raise Exception("gcl run outside of repository")
repository_root = os.getcwd() repository_root = os.getcwd()
while True: while True:
parent = os.path.dirname(repository_root) parent = os.path.dirname(repository_root)
if (gclient.CaptureSVNInfo(parent).get("Repository Root") != if GetSVNFileInfo(parent).get("Repository Root") != cur_dir_repo_root:
cur_dir_repo_root):
break break
repository_root = parent repository_root = parent
return repository_root return repository_root
...@@ -192,7 +232,7 @@ def GetCodeReviewSetting(key): ...@@ -192,7 +232,7 @@ def GetCodeReviewSetting(key):
cached_settings_file = os.path.join(GetInfoDir(), CODEREVIEW_SETTINGS_FILE) cached_settings_file = os.path.join(GetInfoDir(), CODEREVIEW_SETTINGS_FILE)
if (not os.path.exists(cached_settings_file) or if (not os.path.exists(cached_settings_file) or
os.stat(cached_settings_file).st_mtime > 60*60*24*3): os.stat(cached_settings_file).st_mtime > 60*60*24*3):
dir_info = gclient.CaptureSVNInfo(".") dir_info = GetSVNFileInfo(".")
repo_root = dir_info["Repository Root"] repo_root = dir_info["Repository Root"]
url_path = dir_info["URL"] url_path = dir_info["URL"]
settings = "" settings = ""
...@@ -294,13 +334,11 @@ class ChangeInfo: ...@@ -294,13 +334,11 @@ class ChangeInfo:
files: a list of 2 tuple containing (status, filename) of changed files, files: a list of 2 tuple containing (status, filename) of changed files,
with paths being relative to the top repository directory. with paths being relative to the top repository directory.
""" """
def __init__(self, name="", issue="", description="", files=None): def __init__(self, name="", issue="", description="", files=[]):
self.name = name self.name = name
self.issue = issue self.issue = issue
self.description = description self.description = description
self.files = files self.files = files
if self.files is None:
self.files = []
self.patch = None self.patch = None
def FileList(self): def FileList(self):
...@@ -712,7 +750,7 @@ def GenerateDiff(files, root=None): ...@@ -712,7 +750,7 @@ def GenerateDiff(files, root=None):
for file in files: for file in files:
# Use svn info output instead of os.path.isdir because the latter fails # Use svn info output instead of os.path.isdir because the latter fails
# when the file is deleted. # when the file is deleted.
if gclient.CaptureSVNInfo(file).get("Node Kind") in ("dir", "directory"): if GetSVNFileInfo(file).get("Node Kind") in ("dir", "directory"):
continue continue
# If the user specified a custom diff command in their svn config file, # If the user specified a custom diff command in their svn config file,
# then it'll be used when we do svn diff, which we don't want to happen # then it'll be used when we do svn diff, which we don't want to happen
......
...@@ -475,7 +475,7 @@ def IsUsingGit(root, paths): ...@@ -475,7 +475,7 @@ def IsUsingGit(root, paths):
# SVN utils: # SVN utils:
def RunSVN(args, in_directory): def RunSVN(options, args, in_directory):
"""Runs svn, sending output to stdout. """Runs svn, sending output to stdout.
Args: Args:
...@@ -491,7 +491,7 @@ def RunSVN(args, in_directory): ...@@ -491,7 +491,7 @@ def RunSVN(args, in_directory):
SubprocessCall(c, in_directory, options.stdout) SubprocessCall(c, in_directory, options.stdout)
def CaptureSVN(args, in_directory=None, print_error=True): def CaptureSVN(options, args, in_directory):
"""Runs svn, capturing output sent to stdout as a string. """Runs svn, capturing output sent to stdout as a string.
Args: Args:
...@@ -508,14 +508,8 @@ def CaptureSVN(args, in_directory=None, print_error=True): ...@@ -508,14 +508,8 @@ def CaptureSVN(args, in_directory=None, print_error=True):
# the svn.exe executable, but shell=True makes subprocess on Linux fail # the svn.exe executable, but shell=True makes subprocess on Linux fail
# when it's called with a list because it only tries to execute the # when it's called with a list because it only tries to execute the
# first string ("svn"). # first string ("svn").
stderr = None return subprocess.Popen(c, cwd=in_directory, shell=(sys.platform == 'win32'),
if print_error: stdout=subprocess.PIPE).communicate()[0]
stderr = subprocess.PIPE
return subprocess.Popen(c,
cwd=in_directory,
shell=(sys.platform == 'win32'),
stdout=subprocess.PIPE,
stderr=stderr).communicate()[0]
def RunSVNAndGetFileList(options, args, in_directory, file_list): def RunSVNAndGetFileList(options, args, in_directory, file_list):
...@@ -562,7 +556,7 @@ def RunSVNAndGetFileList(options, args, in_directory, file_list): ...@@ -562,7 +556,7 @@ def RunSVNAndGetFileList(options, args, in_directory, file_list):
pattern=pattern, capture_list=file_list) pattern=pattern, capture_list=file_list)
def CaptureSVNInfo(relpath, in_directory=None, print_error=True): def CaptureSVNInfo(options, relpath, in_directory):
"""Returns a dictionary from the svn info output for the given file. """Returns a dictionary from the svn info output for the given file.
Args: Args:
...@@ -570,8 +564,7 @@ def CaptureSVNInfo(relpath, in_directory=None, print_error=True): ...@@ -570,8 +564,7 @@ def CaptureSVNInfo(relpath, in_directory=None, print_error=True):
the directory given by in_directory. the directory given by in_directory.
in_directory: The directory where svn is to be run. in_directory: The directory where svn is to be run.
""" """
output = CaptureSVN(["info", "--xml", relpath], in_directory, print_error) dom = ParseXML(CaptureSVN(options, ["info", "--xml", relpath], in_directory))
dom = ParseXML(output)
result = {} result = {}
if dom: if dom:
def C(item, f): def C(item, f):
...@@ -599,13 +592,13 @@ def CaptureSVNInfo(relpath, in_directory=None, print_error=True): ...@@ -599,13 +592,13 @@ def CaptureSVNInfo(relpath, in_directory=None, print_error=True):
return result return result
def CaptureSVNHeadRevision(url): def CaptureSVNHeadRevision(options, url):
"""Get the head revision of a SVN repository. """Get the head revision of a SVN repository.
Returns: Returns:
Int head revision Int head revision
""" """
info = CaptureSVN(["info", "--xml", url], os.getcwd()) info = CaptureSVN(options, ["info", "--xml", url], os.getcwd())
dom = xml.dom.minidom.parseString(info) dom = xml.dom.minidom.parseString(info)
return int(dom.getElementsByTagName('entry')[0].getAttribute('revision')) return int(dom.getElementsByTagName('entry')[0].getAttribute('revision'))
...@@ -624,7 +617,7 @@ class FileStatus: ...@@ -624,7 +617,7 @@ class FileStatus:
self.path) self.path)
def CaptureSVNStatus(path): def CaptureSVNStatus(options, path):
"""Runs 'svn status' on an existing path. """Runs 'svn status' on an existing path.
Args: Args:
...@@ -633,7 +626,7 @@ def CaptureSVNStatus(path): ...@@ -633,7 +626,7 @@ def CaptureSVNStatus(path):
Returns: Returns:
An array of FileStatus corresponding to the emulated output of 'svn status' An array of FileStatus corresponding to the emulated output of 'svn status'
version 1.5.""" version 1.5."""
dom = ParseXML(CaptureSVN(["status", "--xml"], path)) dom = ParseXML(CaptureSVN(options, ["status", "--xml"], path))
results = [] results = []
if dom: if dom:
# /status/target/entry/(wc-status|commit|author|date) # /status/target/entry/(wc-status|commit|author|date)
...@@ -735,13 +728,13 @@ class SCMWrapper(object): ...@@ -735,13 +728,13 @@ class SCMWrapper(object):
"""Cleanup working copy.""" """Cleanup working copy."""
command = ['cleanup'] command = ['cleanup']
command.extend(args) command.extend(args)
RunSVN(command, os.path.join(self._root_dir, self.relpath)) RunSVN(options, command, os.path.join(self._root_dir, self.relpath))
def diff(self, options, args, file_list): def diff(self, options, args, file_list):
# NOTE: This function does not currently modify file_list. # NOTE: This function does not currently modify file_list.
command = ['diff'] command = ['diff']
command.extend(args) command.extend(args)
RunSVN(command, os.path.join(self._root_dir, self.relpath)) RunSVN(options, command, os.path.join(self._root_dir, self.relpath))
def update(self, options, args, file_list): def update(self, options, args, file_list):
"""Runs SCM to update or transparently checkout the working copy. """Runs SCM to update or transparently checkout the working copy.
...@@ -787,18 +780,19 @@ class SCMWrapper(object): ...@@ -787,18 +780,19 @@ class SCMWrapper(object):
return return
# Get the existing scm url and the revision number of the current checkout. # Get the existing scm url and the revision number of the current checkout.
from_info = CaptureSVNInfo(os.path.join(self._root_dir, self.relpath, '.'), from_info = CaptureSVNInfo(options,
os.path.join(self._root_dir, self.relpath, '.'),
'.') '.')
if options.manually_grab_svn_rev: if options.manually_grab_svn_rev:
# Retrieve the current HEAD version because svn is slow at null updates. # Retrieve the current HEAD version because svn is slow at null updates.
if not revision: if not revision:
from_info_live = CaptureSVNInfo(from_info['URL'], '.') from_info_live = CaptureSVNInfo(options, from_info['URL'], '.')
revision = int(from_info_live['Revision']) revision = int(from_info_live['Revision'])
rev_str = ' at %d' % revision rev_str = ' at %d' % revision
if from_info['URL'] != components[0]: if from_info['URL'] != components[0]:
to_info = CaptureSVNInfo(url, '.') to_info = CaptureSVNInfo(options, url, '.')
if from_info['Repository Root'] != to_info['Repository Root']: if from_info['Repository Root'] != to_info['Repository Root']:
# We have different roots, so check if we can switch --relocate. # We have different roots, so check if we can switch --relocate.
# Subversion only permits this if the repository UUIDs match. # Subversion only permits this if the repository UUIDs match.
...@@ -820,7 +814,7 @@ class SCMWrapper(object): ...@@ -820,7 +814,7 @@ class SCMWrapper(object):
from_info['Repository Root'], from_info['Repository Root'],
to_info['Repository Root'], to_info['Repository Root'],
self.relpath] self.relpath]
RunSVN(command, self._root_dir) RunSVN(options, command, self._root_dir)
from_info['URL'] = from_info['URL'].replace( from_info['URL'] = from_info['URL'].replace(
from_info['Repository Root'], from_info['Repository Root'],
to_info['Repository Root']) to_info['Repository Root'])
...@@ -853,7 +847,7 @@ class SCMWrapper(object): ...@@ -853,7 +847,7 @@ class SCMWrapper(object):
# Don't reuse the args. # Don't reuse the args.
return self.update(options, [], file_list) return self.update(options, [], file_list)
files = CaptureSVNStatus(path) files = CaptureSVNStatus(options, path)
# Batch the command. # Batch the command.
files_to_revert = [] files_to_revert = []
for file in files: for file in files:
...@@ -882,7 +876,7 @@ class SCMWrapper(object): ...@@ -882,7 +876,7 @@ class SCMWrapper(object):
for p in files_to_revert: for p in files_to_revert:
# Some shell have issues with command lines too long. # Some shell have issues with command lines too long.
if accumulated_length and accumulated_length + len(p) > 3072: if accumulated_length and accumulated_length + len(p) > 3072:
RunSVN(command + accumulated_paths, RunSVN(options, command + accumulated_paths,
os.path.join(self._root_dir, self.relpath)) os.path.join(self._root_dir, self.relpath))
accumulated_paths = [] accumulated_paths = []
accumulated_length = 0 accumulated_length = 0
...@@ -890,7 +884,7 @@ class SCMWrapper(object): ...@@ -890,7 +884,7 @@ class SCMWrapper(object):
accumulated_paths.append(p) accumulated_paths.append(p)
accumulated_length += len(p) accumulated_length += len(p)
if accumulated_paths: if accumulated_paths:
RunSVN(command + accumulated_paths, RunSVN(options, command + accumulated_paths,
os.path.join(self._root_dir, self.relpath)) os.path.join(self._root_dir, self.relpath))
def status(self, options, args, file_list): def status(self, options, args, file_list):
...@@ -1331,7 +1325,7 @@ class GClient(object): ...@@ -1331,7 +1325,7 @@ class GClient(object):
for entry in prev_entries: for entry in prev_entries:
e_dir = os.path.join(self._root_dir, entry) e_dir = os.path.join(self._root_dir, entry)
if entry not in entries and self._options.path_exists(e_dir): if entry not in entries and self._options.path_exists(e_dir):
if CaptureSVNStatus(e_dir): if CaptureSVNStatus(self._options, e_dir):
# There are modified files in this entry # There are modified files in this entry
entries[entry] = None # Keep warning until removed. entries[entry] = None # Keep warning until removed.
print >> self._options.stdout, ( print >> self._options.stdout, (
...@@ -1389,7 +1383,8 @@ class GClient(object): ...@@ -1389,7 +1383,8 @@ class GClient(object):
return (original_url, int(revision_overrides[name])) return (original_url, int(revision_overrides[name]))
else: else:
# TODO(aharper): SVN/SCMWrapper cleanup (non-local commandset) # TODO(aharper): SVN/SCMWrapper cleanup (non-local commandset)
return (original_url, CaptureSVNHeadRevision(original_url)) return (original_url, CaptureSVNHeadRevision(self._options,
original_url))
else: else:
url_components = original_url.split("@") url_components = original_url.split("@")
if revision_overrides.has_key(name): if revision_overrides.has_key(name):
...@@ -1406,6 +1401,7 @@ class GClient(object): ...@@ -1406,6 +1401,7 @@ class GClient(object):
entries[name] = "%s@%d" % (url, rev) entries[name] = "%s@%d" % (url, rev)
# TODO(aharper): SVN/SCMWrapper cleanup (non-local commandset) # TODO(aharper): SVN/SCMWrapper cleanup (non-local commandset)
entries_deps_content[name] = CaptureSVN( entries_deps_content[name] = CaptureSVN(
self._options,
["cat", ["cat",
"%s/%s@%d" % (url, "%s/%s@%d" % (url,
self._options.deps_file, self._options.deps_file,
...@@ -1433,6 +1429,7 @@ class GClient(object): ...@@ -1433,6 +1429,7 @@ class GClient(object):
deps_parent_url_components = deps_parent_url.split("@") deps_parent_url_components = deps_parent_url.split("@")
# TODO(aharper): SVN/SCMWrapper cleanup (non-local commandset) # TODO(aharper): SVN/SCMWrapper cleanup (non-local commandset)
deps_parent_content = CaptureSVN( deps_parent_content = CaptureSVN(
self._options,
["cat", ["cat",
"%s/%s@%s" % (deps_parent_url_components[0], "%s/%s@%s" % (deps_parent_url_components[0],
self._options.deps_file, self._options.deps_file,
......
...@@ -5,9 +5,7 @@ ...@@ -5,9 +5,7 @@
"""Unit tests for gcl.py.""" """Unit tests for gcl.py."""
import StringIO
import os import os
import sys
import unittest import unittest
# Local imports # Local imports
...@@ -48,14 +46,15 @@ class GclUnittest(GclTestsBase): ...@@ -48,14 +46,15 @@ class GclUnittest(GclTestsBase):
'ErrorExit', 'GenerateChangeName', 'GenerateDiff', 'GetCLs', 'ErrorExit', 'GenerateChangeName', 'GenerateDiff', 'GetCLs',
'GetChangelistInfoFile', 'GetCodeReviewSetting', 'GetEditor', 'GetChangelistInfoFile', 'GetCodeReviewSetting', 'GetEditor',
'GetFilesNotInCL', 'GetInfoDir', 'GetIssueDescription', 'GetFilesNotInCL', 'GetInfoDir', 'GetIssueDescription',
'GetModifiedFiles', 'GetRepositoryRoot', 'GetSVNStatus', 'GetModifiedFiles', 'GetNamedNodeText', 'GetNodeNamedAttributeText',
'GetRepositoryRoot', 'GetSVNFileInfo', 'GetSVNStatus',
'GetSVNFileProperty', 'Help', 'IGNORE_PATHS', 'IsSVNMoved', 'IsTreeOpen', 'GetSVNFileProperty', 'Help', 'IGNORE_PATHS', 'IsSVNMoved', 'IsTreeOpen',
'Lint', 'LoadChangelistInfo', 'LoadChangelistInfoForMultiple', 'Lint', 'LoadChangelistInfo', 'LoadChangelistInfoForMultiple',
'MISSING_TEST_MSG', 'Opened', 'PresubmitCL', 'ReadFile', 'MISSING_TEST_MSG', 'Opened', 'ParseXML', 'PresubmitCL', 'ReadFile',
'RunShell', 'RunShell',
'RunShellWithReturnCode', 'SEPARATOR', 'SendToRietveld', 'TryChange', 'RunShellWithReturnCode', 'SEPARATOR', 'SendToRietveld', 'TryChange',
'UnknownFiles', 'UploadCL', 'Warn', 'WriteFile', 'gclient', 'UnknownFiles', 'UploadCL', 'Warn', 'WriteFile', 'gcl_info_dir',
'gcl_info_dir', 'getpass', 'main', 'os', 'random', 're', 'read_gcl_info', 'getpass', 'main', 'os', 'random', 're', 'read_gcl_info',
'repository_root', 'string', 'subprocess', 'sys', 'tempfile', 'upload', 'repository_root', 'string', 'subprocess', 'sys', 'tempfile', 'upload',
'urllib2', 'use_shell', 'xml', 'urllib2', 'use_shell', 'xml',
...@@ -63,6 +62,37 @@ class GclUnittest(GclTestsBase): ...@@ -63,6 +62,37 @@ class GclUnittest(GclTestsBase):
# If this test fails, you should add the relevant test. # If this test fails, you should add the relevant test.
self.compareMembers(gcl, members) self.compareMembers(gcl, members)
def testGetSVNFileInfo(self):
def RunShellMock(command):
return r"""<?xml version="1.0"?>
<info>
<entry kind="file" path="%s" revision="14628">
<url>http://src.chromium.org/svn/trunk/src/chrome/app/d</url>
<repository><root>http://src.chromium.org/svn</root></repository>
<wc-info>
<schedule>add</schedule>
<depth>infinity</depth>
<copy-from-url>http://src.chromium.org/svn/trunk/src/chrome/app/DEPS</copy-from-url>
<copy-from-rev>14628</copy-from-rev>
<checksum>369f59057ba0e6d9017e28f8bdfb1f43</checksum>
</wc-info>
</entry>
</info>
""" % command[3]
gcl.RunShell = RunShellMock
filename = os.path.join('app', 'd')
info = gcl.GetSVNFileInfo(filename)
expected = {
'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d',
'Repository Root': 'http://src.chromium.org/svn',
'Schedule': 'add',
'Copied From URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/DEPS',
'Copied From Rev': '14628',
'Path': filename,
'Node Kind': 'file',
}
self.assertEquals(sorted(info.items()), sorted(expected.items()))
def testGetSVNStatus(self): def testGetSVNStatus(self):
def RunShellMock(command): def RunShellMock(command):
return r"""<?xml version="1.0"?> return r"""<?xml version="1.0"?>
...@@ -126,41 +156,6 @@ class GclUnittest(GclTestsBase): ...@@ -126,41 +156,6 @@ class GclUnittest(GclTestsBase):
info = gcl.GetSVNStatus(None) info = gcl.GetSVNStatus(None)
self.assertEquals(info, []) self.assertEquals(info, [])
def testHelp(self):
stdout = sys.stdout
dummy = StringIO.StringIO()
sys.stdout = dummy
gcl.Help()
sys.stdout = stdout
self.assertEquals(len(dummy.getvalue()), 1718)
def testGetRepositoryRoot(self):
try:
gcl.GetRepositoryRoot()
except Exception,e:
self.assertEquals(e.args[0], "gcl run outside of repository")
class ChangeInfoUnittest(GclTestsBase):
def testChangeInfoMembers(self):
members = [
'CloseIssue', 'Delete', 'FileList', 'MissingTests', 'Save',
'UpdateRietveldDescription', 'description', 'files', 'issue', 'name',
'patch'
]
# If this test fails, you should add the relevant test.
self.compareMembers(gcl.ChangeInfo(), members)
def testChangeInfoBase(self):
files = [('M', 'foo'), ('A', 'bar')]
o = gcl.ChangeInfo('name2', 'issue2', 'description2', files)
self.assertEquals(o.name, 'name2')
self.assertEquals(o.issue, 'issue2')
self.assertEquals(o.description, 'description2')
self.assertEquals(o.files, files)
self.assertEquals(o.patch, None)
self.assertEquals(o.FileList(), ['foo', 'bar'])
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -1145,7 +1145,7 @@ class SCMWrapperTestCase(BaseTestCase): ...@@ -1145,7 +1145,7 @@ class SCMWrapperTestCase(BaseTestCase):
base_path = os.path.join(self.root_dir, self.relpath) base_path = os.path.join(self.root_dir, self.relpath)
gclient.os.path.isdir = self.mox.CreateMockAnything() gclient.os.path.isdir = self.mox.CreateMockAnything()
gclient.os.path.isdir(base_path).AndReturn(True) gclient.os.path.isdir(base_path).AndReturn(True)
gclient.CaptureSVNStatus(base_path).AndReturn([]) gclient.CaptureSVNStatus(options, base_path).AndReturn([])
self.mox.ReplayAll() self.mox.ReplayAll()
scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir,
...@@ -1164,11 +1164,11 @@ class SCMWrapperTestCase(BaseTestCase): ...@@ -1164,11 +1164,11 @@ class SCMWrapperTestCase(BaseTestCase):
gclient.FileStatus('a', 'M', ' ', ' ', ' '), gclient.FileStatus('a', 'M', ' ', ' ', ' '),
gclient.FileStatus('b', 'A', ' ', ' ', ' '), gclient.FileStatus('b', 'A', ' ', ' ', ' '),
] ]
gclient.CaptureSVNStatus(base_path).AndReturn(items) gclient.CaptureSVNStatus(options, base_path).AndReturn(items)
print >>options.stdout, os.path.join(base_path, 'a') print >>options.stdout, os.path.join(base_path, 'a')
print >>options.stdout, os.path.join(base_path, 'b') print >>options.stdout, os.path.join(base_path, 'b')
gclient.RunSVN(['revert', 'a', 'b'], base_path) gclient.RunSVN(options, ['revert', 'a', 'b'], base_path)
self.mox.ReplayAll() self.mox.ReplayAll()
scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir, scm = gclient.SCMWrapper(url=self.url, root_dir=self.root_dir,
...@@ -1229,10 +1229,10 @@ class SCMWrapperTestCase(BaseTestCase): ...@@ -1229,10 +1229,10 @@ class SCMWrapperTestCase(BaseTestCase):
options.path_exists(os.path.join(base_path, '.git')).AndReturn(False) options.path_exists(os.path.join(base_path, '.git')).AndReturn(False)
# Checkout or update. # Checkout or update.
options.path_exists(base_path).AndReturn(True) options.path_exists(base_path).AndReturn(True)
gclient.CaptureSVNInfo(os.path.join(base_path, "."), '.' gclient.CaptureSVNInfo(options, os.path.join(base_path, "."), '.'
).AndReturn(file_info) ).AndReturn(file_info)
# Cheat a bit here. # Cheat a bit here.
gclient.CaptureSVNInfo(file_info['URL'], '.').AndReturn(file_info) gclient.CaptureSVNInfo(options, file_info['URL'], '.').AndReturn(file_info)
additional_args = [] additional_args = []
if options.manually_grab_svn_rev: if options.manually_grab_svn_rev:
additional_args = ['--revision', str(file_info['Revision'])] additional_args = ['--revision', str(file_info['Revision'])]
...@@ -1276,8 +1276,9 @@ class SCMWrapperTestCase(BaseTestCase): ...@@ -1276,8 +1276,9 @@ class SCMWrapperTestCase(BaseTestCase):
</entry> </entry>
</info> </info>
""" % self.url """ % self.url
gclient.CaptureSVN(['info', '--xml', self.url], options = self.Options(verbose=True)
'.', True).AndReturn(xml_text) gclient.CaptureSVN(options, ['info', '--xml', self.url],
'.').AndReturn(xml_text)
expected = { expected = {
'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d', 'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d',
'UUID': None, 'UUID': None,
...@@ -1290,7 +1291,7 @@ class SCMWrapperTestCase(BaseTestCase): ...@@ -1290,7 +1291,7 @@ class SCMWrapperTestCase(BaseTestCase):
'Node Kind': 'file', 'Node Kind': 'file',
} }
self.mox.ReplayAll() self.mox.ReplayAll()
file_info = self._CaptureSVNInfo(self.url, '.', True) file_info = self._CaptureSVNInfo(options, self.url, '.')
self.assertEquals(sorted(file_info.items()), sorted(expected.items())) self.assertEquals(sorted(file_info.items()), sorted(expected.items()))
self.mox.VerifyAll() self.mox.VerifyAll()
...@@ -1318,10 +1319,11 @@ class SCMWrapperTestCase(BaseTestCase): ...@@ -1318,10 +1319,11 @@ class SCMWrapperTestCase(BaseTestCase):
</entry> </entry>
</info> </info>
""" % (self.url, self.root_dir) """ % (self.url, self.root_dir)
gclient.CaptureSVN(['info', '--xml', self.url], options = self.Options(verbose=True)
'.', True).AndReturn(xml_text) gclient.CaptureSVN(options, ['info', '--xml', self.url],
'.').AndReturn(xml_text)
self.mox.ReplayAll() self.mox.ReplayAll()
file_info = self._CaptureSVNInfo(self.url, '.', True) file_info = self._CaptureSVNInfo(options, self.url, '.')
expected = { expected = {
'URL': self.url, 'URL': self.url,
'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb', 'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb',
......
#!/usr/bin/python
# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Unit tests for trychange.py."""
import os
import unittest
# Local imports
import trychange
class TryChangeTestsBase(unittest.TestCase):
"""Setups and tear downs the mocks but doesn't test anything as-is."""
def setUp(self):
pass
def tearDown(self):
pass
def compareMembers(self, object, members):
"""If you add a member, be sure to add the relevant test!"""
# Skip over members starting with '_' since they are usually not meant to
# be for public use.
actual_members = [x for x in sorted(dir(object))
if not x.startswith('_')]
expected_members = sorted(members)
if actual_members != expected_members:
diff = ([i for i in actual_members if i not in expected_members] +
[i for i in expected_members if i not in actual_members])
print diff
self.assertEqual(actual_members, expected_members)
class TryChangeUnittest(TryChangeTestsBase):
"""General trychange.py tests."""
def testMembersChanged(self):
members = [
'EscapeDot', 'ExecuteTryServerScript', 'GIT', 'GetSourceRoot', 'GuessVCS',
'HELP_STRING', 'InvalidScript', 'NoTryServerAccess', 'PathDifference',
'RunCommand', 'SCM', 'SCRIPT_PATH', 'SVN', 'TryChange', 'USAGE',
'datetime', 'gcl', 'gclient', 'getpass', 'logging', 'optparse', 'os',
'shutil', 'sys', 'tempfile', 'traceback', 'urllib',
]
# If this test fails, you should add the relevant test.
self.compareMembers(trychange, members)
class SVNUnittest(TryChangeTestsBase):
"""General trychange.py tests."""
def testMembersChanged(self):
members = [
'GenerateDiff', 'ProcessOptions', 'options'
]
# If this test fails, you should add the relevant test.
self.compareMembers(trychange.SVN(None), members)
class TryChangeUnittest(TryChangeTestsBase):
"""General trychange.py tests."""
def testMembersChanged(self):
members = [
'GenerateDiff', 'GetEmail', 'GetPatchName', 'ProcessOptions', 'options'
]
# If this test fails, you should add the relevant test.
self.compareMembers(trychange.GIT(None), members)
if __name__ == '__main__':
unittest.main()
...@@ -20,7 +20,6 @@ import traceback ...@@ -20,7 +20,6 @@ import traceback
import urllib import urllib
import gcl import gcl
import gclient
__version__ = '1.1' __version__ = '1.1'
...@@ -133,7 +132,7 @@ class SVN(SCM): ...@@ -133,7 +132,7 @@ class SVN(SCM):
for file in files: for file in files:
# Use svn info output instead of os.path.isdir because the latter fails # Use svn info output instead of os.path.isdir because the latter fails
# when the file is deleted. # when the file is deleted.
if gclient.CaptureSVNInfo(file).get("Node Kind") in ("dir", "directory"): if gcl.GetSVNFileInfo(file).get("Node Kind") == "directory":
continue continue
# If the user specified a custom diff command in their svn config file, # If the user specified a custom diff command in their svn config file,
# then it'll be used when we do svn diff, which we don't want to happen # then it'll be used when we do svn diff, which we don't want to happen
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment