Commit 8ce0a13a authored by maruel@chromium.org's avatar maruel@chromium.org

Split scm-specific functions out of gclient_scm.py to scm.py.

TEST=unit tests fixed and reclassified
BUG=none

Review URL: http://codereview.chromium.org/389020

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@31809 0039d316-1c4b-4281-b951-d872f2087c98
parent 2dfc8ee7
......@@ -13,8 +13,10 @@ UNIT_TESTS = [
'tests.gcl_unittest',
'tests.gclient_test',
'tests.gclient_scm_test',
'tests.gclient_utils_test',
'tests.presubmit_unittest',
'tests.revert_unittest',
'tests.scm_unittest',
'tests.trychange_unittest',
'tests.watchlists_unittest',
]
......
This diff is collapsed.
This diff is collapsed.
......@@ -267,115 +267,6 @@ class SVNWrapperTestCase(BaseTestCase):
file_list = []
scm.update(options, self.args, file_list)
def testGetSVNFileInfo(self):
xml_text = 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>
""" % self.url
gclient_scm.CaptureSVN(['info', '--xml', self.url],
'.', True).AndReturn(xml_text)
expected = {
'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d',
'UUID': None,
'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': self.url,
'Revision': 14628,
'Node Kind': 'file',
}
self.mox.ReplayAll()
file_info = self._CaptureSVNInfo(self.url, '.', True)
self.assertEquals(sorted(file_info.items()), sorted(expected.items()))
def testCaptureSvnInfo(self):
xml_text = """<?xml version="1.0"?>
<info>
<entry
kind="dir"
path="."
revision="35">
<url>%s</url>
<repository>
<root>%s</root>
<uuid>7b9385f5-0452-0410-af26-ad4892b7a1fb</uuid>
</repository>
<wc-info>
<schedule>normal</schedule>
<depth>infinity</depth>
</wc-info>
<commit
revision="35">
<author>maruel</author>
<date>2008-12-04T20:12:19.685120Z</date>
</commit>
</entry>
</info>
""" % (self.url, self.root_dir)
gclient_scm.CaptureSVN(['info', '--xml',
self.url], '.', True).AndReturn(xml_text)
self.mox.ReplayAll()
file_info = self._CaptureSVNInfo(self.url, '.', True)
expected = {
'URL': self.url,
'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb',
'Revision': 35,
'Repository Root': self.root_dir,
'Schedule': 'normal',
'Copied From URL': None,
'Copied From Rev': None,
'Path': '.',
'Node Kind': 'dir',
}
self.assertEqual(file_info, expected)
def testRevinfo(self):
options = self.Options(verbose=False)
xml_text = """<?xml version="1.0"?>
<info>
<entry
kind="dir"
path="."
revision="35">
<url>%s</url>
<repository>
<root>%s</root>
<uuid>7b9385f5-0452-0410-af26-ad4892b7a1fb</uuid>
</repository>
<wc-info>
<schedule>normal</schedule>
<depth>infinity</depth>
</wc-info>
<commit
revision="35">
<author>maruel</author>
<date>2008-12-04T20:12:19.685120Z</date>
</commit>
</entry>
</info>
""" % (self.url, self.root_dir)
gclient_scm.os.getcwd().AndReturn('bleh')
gclient_scm.CaptureSVN(['info', '--xml', self.url], 'bleh'
).AndReturn(xml_text)
self.mox.ReplayAll()
scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
relpath=self.relpath)
rev_info = scm.revinfo(options, self.args, None)
self.assertEqual(rev_info, '35')
class GitWrapperTestCase(SuperMoxBaseTestBase):
"""This class doesn't use pymox."""
......@@ -437,6 +328,7 @@ from :3
return self.OptionsObject(self, *args, **kwargs)
def CreateGitRepo(self, git_import, path):
"""Do it for real."""
try:
Popen(['git', 'init'], stdout=PIPE, stderr=STDOUT,
cwd=path).communicate()
......@@ -612,16 +504,6 @@ from :3
self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458')
class RunSVNTestCase(BaseTestCase):
def testRunSVN(self):
self.UnMock(gclient_scm, 'RunSVN')
param2 = 'bleh'
gclient_scm.gclient_utils.SubprocessCall(['svn', 'foo', 'bar'],
param2).AndReturn(None)
self.mox.ReplayAll()
gclient_scm.RunSVN(['foo', 'bar'], param2)
if __name__ == '__main__':
import unittest
unittest.main()
......
......@@ -22,6 +22,8 @@ import __builtin__
import StringIO
import gclient
# Temporary due to the "from scm import *" in gclient_scm.
import scm
from super_mox import mox, IsOneOf, SuperMoxTestBase
......@@ -53,6 +55,11 @@ class GClientBaseTestCase(BaseTestCase):
self.mox.StubOutWithMock(gclient.gclient_scm, 'CaptureSVNStatus')
self.mox.StubOutWithMock(gclient.gclient_scm, 'RunSVN')
self.mox.StubOutWithMock(gclient.gclient_scm, 'RunSVNAndGetFileList')
self.mox.StubOutWithMock(scm, 'CaptureSVN')
self.mox.StubOutWithMock(scm, 'CaptureSVNInfo')
self.mox.StubOutWithMock(scm, 'CaptureSVNStatus')
self.mox.StubOutWithMock(scm, 'RunSVN')
self.mox.StubOutWithMock(scm, 'RunSVNAndGetFileList')
self._gclient_gclient = gclient.GClient
gclient.GClient = self.mox.CreateMockAnything()
self._scm_wrapper = gclient.gclient_scm.CreateSCM
......@@ -1066,112 +1073,6 @@ deps = {
pass
class SubprocessCallAndFilterTestCase(BaseTestCase):
def setUp(self):
BaseTestCase.setUp(self)
self.mox.StubOutWithMock(gclient.gclient_scm, 'CaptureSVN')
def testSubprocessCallAndFilter(self):
command = ['boo', 'foo', 'bar']
in_directory = 'bleh'
fail_status = None
pattern = 'a(.*)b'
test_string = 'ahah\naccb\nallo\naddb\n'
class Mock(object):
stdout = StringIO.StringIO(test_string)
def wait(self):
pass
kid = Mock()
print("\n________ running 'boo foo bar' in 'bleh'")
for i in test_string:
gclient.sys.stdout.write(i)
gclient.gclient_utils.subprocess.Popen(
command, bufsize=0, cwd=in_directory,
shell=(gclient.sys.platform == 'win32'),
stdout=gclient.gclient_utils.subprocess.PIPE,
stderr=gclient.gclient_utils.subprocess.STDOUT).AndReturn(kid)
self.mox.ReplayAll()
compiled_pattern = gclient.re.compile(pattern)
line_list = []
capture_list = []
def FilterLines(line):
line_list.append(line)
match = compiled_pattern.search(line)
if match:
capture_list.append(match.group(1))
gclient.gclient_utils.SubprocessCallAndFilter(
command, in_directory,
True, True,
fail_status, FilterLines)
self.assertEquals(line_list, ['ahah', 'accb', 'allo', 'addb'])
self.assertEquals(capture_list, ['cc', 'dd'])
def testCaptureSVNStatus(self):
gclient.gclient_scm.CaptureSVN(
['status', '--xml', '.']
).AndReturn(r"""<?xml version="1.0"?>
<status>
<target path=".">
<entry path="unversionned_file.txt">
<wc-status props="none" item="unversioned"></wc-status>
</entry>
<entry path="build\internal\essential.vsprops">
<wc-status props="normal" item="modified" revision="14628">
<commit revision="13818">
<author>ajwong@chromium.org</author>
<date>2009-04-16T00:42:06.872358Z</date>
</commit>
</wc-status>
</entry>
<entry path="chrome\app\d">
<wc-status props="none" copied="true" tree-conflicted="true" item="added">
</wc-status>
</entry>
<entry path="chrome\app\DEPS">
<wc-status props="modified" item="modified" revision="14628">
<commit revision="1279">
<author>brettw@google.com</author>
<date>2008-08-23T17:16:42.090152Z</date>
</commit>
</wc-status>
</entry>
<entry path="scripts\master\factory\gclient_factory.py">
<wc-status props="normal" item="conflicted" revision="14725">
<commit revision="14633">
<author>nsylvain@chromium.org</author>
<date>2009-04-27T19:37:17.977400Z</date>
</commit>
</wc-status>
</entry>
</target>
</status>
""")
self.mox.ReplayAll()
info = gclient.gclient_scm.CaptureSVNStatus('.')
expected = [
('? ', 'unversionned_file.txt'),
('M ', 'build\\internal\\essential.vsprops'),
('A + ', 'chrome\\app\\d'),
('MM ', 'chrome\\app\\DEPS'),
('C ', 'scripts\\master\\factory\\gclient_factory.py'),
]
self.assertEquals(sorted(info), sorted(expected))
def testCaptureSVNStatusEmpty(self):
gclient.gclient_scm.CaptureSVN(
['status', '--xml']
).AndReturn(r"""<?xml version="1.0"?>
<status>
<target
path="perf">
</target>
</status>
""")
self.mox.ReplayAll()
info = gclient.gclient_scm.CaptureSVNStatus(None)
self.assertEquals(info, [])
if __name__ == '__main__':
import unittest
unittest.main()
......
#!/usr/bin/python
# Copyright (c) 2006-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 scm.py."""
from gclient_test import BaseTestCase
import scm
from super_mox import mox
class BaseSCMTestCase(BaseTestCase):
def setUp(self):
BaseTestCase.setUp(self)
self.mox.StubOutWithMock(scm.gclient_utils, 'SubprocessCall')
self.mox.StubOutWithMock(scm.gclient_utils, 'SubprocessCallAndFilter')
class RootTestCase(BaseSCMTestCase):
def testMembersChanged(self):
self.mox.ReplayAll()
members = [
'CaptureGit', 'CaptureGitStatus', 'GIT_COMMAND',
'CaptureSVN', 'CaptureSVNHeadRevision', 'CaptureSVNInfo',
'CaptureSVNStatus', 'RunSVN', 'RunSVNAndFilterOutput',
'RunSVNAndGetFileList', 'SVN_COMMAND',
'gclient_utils', 'os', 're', 'subprocess', 'sys', 'xml',
]
# If this test fails, you should add the relevant test.
self.compareMembers(scm, members)
class GitWrapperTestCase(BaseSCMTestCase):
sample_git_import = """blob
mark :1
data 6
Hello
blob
mark :2
data 4
Bye
reset refs/heads/master
commit refs/heads/master
mark :3
author Bob <bob@example.com> 1253744361 -0700
committer Bob <bob@example.com> 1253744361 -0700
data 8
A and B
M 100644 :1 a
M 100644 :2 b
blob
mark :4
data 10
Hello
You
blob
mark :5
data 8
Bye
You
commit refs/heads/origin
mark :6
author Alice <alice@example.com> 1253744424 -0700
committer Alice <alice@example.com> 1253744424 -0700
data 13
Personalized
from :3
M 100644 :4 a
M 100644 :5 b
reset refs/heads/master
from :3
"""
def CreateGitRepo(self, git_import, path):
try:
subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, cwd=path).communicate()
except WindowsError:
# git is not available, skip this test.
return False
subprocess.Popen(['git', 'fast-import'], stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
cwd=path).communicate(input=git_import)
subprocess.Popen(['git', 'checkout'], stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, cwd=path).communicate()
return True
def setUp(self):
BaseSCMTestCase.setUp(self)
self.args = self.Args()
self.url = 'git://foo'
self.root_dir = tempfile.mkdtemp()
self.relpath = '.'
self.base_path = os.path.join(self.root_dir, self.relpath)
self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path)
def tearDown(self):
shutil.rmtree(self.root_dir)
gclient_test.BaseTestCase.tearDown(self)
class SVNTestCase(BaseSCMTestCase):
def setUp(self):
BaseSCMTestCase.setUp(self)
self.root_dir = self.Dir()
self.args = self.Args()
self.url = self.Url()
self.relpath = 'asf'
def testGetSVNFileInfo(self):
xml_text = 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>
""" % self.url
self.mox.StubOutWithMock(scm, 'CaptureSVN')
scm.CaptureSVN(['info', '--xml', self.url], '.', True).AndReturn(xml_text)
expected = {
'URL': 'http://src.chromium.org/svn/trunk/src/chrome/app/d',
'UUID': None,
'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': self.url,
'Revision': 14628,
'Node Kind': 'file',
}
self.mox.ReplayAll()
file_info = scm.CaptureSVNInfo(self.url, '.', True)
self.assertEquals(sorted(file_info.items()), sorted(expected.items()))
def testCaptureSvnInfo(self):
xml_text = """<?xml version="1.0"?>
<info>
<entry
kind="dir"
path="."
revision="35">
<url>%s</url>
<repository>
<root>%s</root>
<uuid>7b9385f5-0452-0410-af26-ad4892b7a1fb</uuid>
</repository>
<wc-info>
<schedule>normal</schedule>
<depth>infinity</depth>
</wc-info>
<commit
revision="35">
<author>maruel</author>
<date>2008-12-04T20:12:19.685120Z</date>
</commit>
</entry>
</info>
""" % (self.url, self.root_dir)
self.mox.StubOutWithMock(scm, 'CaptureSVN')
scm.CaptureSVN(['info', '--xml', self.url], '.', True).AndReturn(xml_text)
self.mox.ReplayAll()
file_info = scm.CaptureSVNInfo(self.url, '.', True)
expected = {
'URL': self.url,
'UUID': '7b9385f5-0452-0410-af26-ad4892b7a1fb',
'Revision': 35,
'Repository Root': self.root_dir,
'Schedule': 'normal',
'Copied From URL': None,
'Copied From Rev': None,
'Path': '.',
'Node Kind': 'dir',
}
self.assertEqual(file_info, expected)
def testCaptureSVNStatus(self):
text =r"""<?xml version="1.0"?>
<status>
<target path=".">
<entry path="unversionned_file.txt">
<wc-status props="none" item="unversioned"></wc-status>
</entry>
<entry path="build\internal\essential.vsprops">
<wc-status props="normal" item="modified" revision="14628">
<commit revision="13818">
<author>ajwong@chromium.org</author>
<date>2009-04-16T00:42:06.872358Z</date>
</commit>
</wc-status>
</entry>
<entry path="chrome\app\d">
<wc-status props="none" copied="true" tree-conflicted="true" item="added">
</wc-status>
</entry>
<entry path="chrome\app\DEPS">
<wc-status props="modified" item="modified" revision="14628">
<commit revision="1279">
<author>brettw@google.com</author>
<date>2008-08-23T17:16:42.090152Z</date>
</commit>
</wc-status>
</entry>
<entry path="scripts\master\factory\gclient_factory.py">
<wc-status props="normal" item="conflicted" revision="14725">
<commit revision="14633">
<author>nsylvain@chromium.org</author>
<date>2009-04-27T19:37:17.977400Z</date>
</commit>
</wc-status>
</entry>
</target>
</status>
"""
proc = self.mox.CreateMockAnything()
scm.subprocess.Popen(['svn', 'status', '--xml', '.'],
cwd=None,
shell=scm.sys.platform.startswith('win'),
stderr=None,
stdout=scm.subprocess.PIPE).AndReturn(proc)
proc.communicate().AndReturn((text, 0))
self.mox.ReplayAll()
info = scm.CaptureSVNStatus('.')
expected = [
('? ', 'unversionned_file.txt'),
('M ', 'build\\internal\\essential.vsprops'),
('A + ', 'chrome\\app\\d'),
('MM ', 'chrome\\app\\DEPS'),
('C ', 'scripts\\master\\factory\\gclient_factory.py'),
]
self.assertEquals(sorted(info), sorted(expected))
def testRunSVN(self):
param2 = 'bleh'
scm.gclient_utils.SubprocessCall(['svn', 'foo', 'bar'],
param2).AndReturn(None)
self.mox.ReplayAll()
scm.RunSVN(['foo', 'bar'], param2)
def testCaptureSVNStatusEmpty(self):
text = r"""<?xml version="1.0"?>
<status>
<target
path="perf">
</target>
</status>"""
proc = self.mox.CreateMockAnything()
scm.subprocess.Popen(['svn', 'status', '--xml'],
cwd=None,
shell=scm.sys.platform.startswith('win'),
stderr=None,
stdout=scm.subprocess.PIPE).AndReturn(proc)
proc.communicate().AndReturn((text, 0))
self.mox.ReplayAll()
info = scm.CaptureSVNStatus(None)
self.assertEquals(info, [])
if __name__ == '__main__':
import unittest
unittest.main()
# vim: ts=2:sw=2:tw=80:et:
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