Fix depot_tools unit tests on Windows.

TEST=unittests
BUG=none
Review URL: http://codereview.chromium.org/273010

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@28591 0039d316-1c4b-4281-b951-d872f2087c98
experimental/szager/collated-output
maruel@chromium.org 16 years ago
parent efb9450e27
commit ea6c2c5cea

@ -378,18 +378,22 @@ M 100644 :5 b
reset refs/heads/master reset refs/heads/master
from :3 from :3
""" """
def Options(self, *args, **kwargs): def Options(self, *args, **kwargs):
return self.OptionsObject(self, *args, **kwargs) return self.OptionsObject(self, *args, **kwargs)
def CreateGitRepo(self, git_import, path): def CreateGitRepo(self, git_import, path):
try:
subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE, subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, cwd=path).communicate() 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, subprocess.Popen(['git', 'fast-import'], stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
cwd=path).communicate(input=git_import) cwd=path).communicate(input=git_import)
subprocess.Popen(['git', 'checkout'], stdout=subprocess.PIPE, subprocess.Popen(['git', 'checkout'], stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, cwd=path).communicate() stderr=subprocess.STDOUT, cwd=path).communicate()
return True
def GetGitRev(self, path): def GetGitRev(self, path):
return subprocess.Popen(['git', 'rev-parse', 'HEAD'], return subprocess.Popen(['git', 'rev-parse', 'HEAD'],
@ -404,7 +408,7 @@ from :3
self.root_dir = tempfile.mkdtemp() self.root_dir = tempfile.mkdtemp()
self.relpath = '.' self.relpath = '.'
self.base_path = os.path.join(self.root_dir, self.relpath) self.base_path = os.path.join(self.root_dir, self.relpath)
self.CreateGitRepo(self.sample_git_import, self.base_path) self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path)
def tearDown(self): def tearDown(self):
shutil.rmtree(self.root_dir) shutil.rmtree(self.root_dir)
@ -420,6 +424,8 @@ from :3
self.compareMembers(gclient_scm.CreateSCM(url=self.url), members) self.compareMembers(gclient_scm.CreateSCM(url=self.url), members)
def testRevertMissing(self): def testRevertMissing(self):
if not self.enabled:
return
options = self.Options() options = self.Options()
file_path = os.path.join(self.base_path, 'a') file_path = os.path.join(self.base_path, 'a')
os.remove(file_path) os.remove(file_path)
@ -433,6 +439,8 @@ from :3
self.assertEquals(file_list, []) self.assertEquals(file_list, [])
def testRevertNone(self): def testRevertNone(self):
if not self.enabled:
return
options = self.Options() options = self.Options()
scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
relpath=self.relpath) relpath=self.relpath)
@ -444,6 +452,8 @@ from :3
def testRevertModified(self): def testRevertModified(self):
if not self.enabled:
return
options = self.Options() options = self.Options()
file_path = os.path.join(self.base_path, 'a') file_path = os.path.join(self.base_path, 'a')
open(file_path, 'a').writelines('touched\n') open(file_path, 'a').writelines('touched\n')
@ -459,6 +469,8 @@ from :3
'069c602044c5388d2d15c3f875b057c852003458') '069c602044c5388d2d15c3f875b057c852003458')
def testRevertNew(self): def testRevertNew(self):
if not self.enabled:
return
options = self.Options() options = self.Options()
file_path = os.path.join(self.base_path, 'c') file_path = os.path.join(self.base_path, 'c')
f = open(file_path, 'w') f = open(file_path, 'w')
@ -478,6 +490,8 @@ from :3
'069c602044c5388d2d15c3f875b057c852003458') '069c602044c5388d2d15c3f875b057c852003458')
def testStatusNew(self): def testStatusNew(self):
if not self.enabled:
return
options = self.Options() options = self.Options()
file_path = os.path.join(self.base_path, 'a') file_path = os.path.join(self.base_path, 'a')
open(file_path, 'a').writelines('touched\n') open(file_path, 'a').writelines('touched\n')
@ -488,6 +502,8 @@ from :3
self.assertEquals(file_list, [file_path]) self.assertEquals(file_list, [file_path])
def testStatus2New(self): def testStatus2New(self):
if not self.enabled:
return
options = self.Options() options = self.Options()
expected_file_list = [] expected_file_list = []
for f in ['a', 'b']: for f in ['a', 'b']:
@ -502,6 +518,8 @@ from :3
self.assertEquals(sorted(file_list), expected_file_list) self.assertEquals(sorted(file_list), expected_file_list)
def testUpdateCheckout(self): def testUpdateCheckout(self):
if not self.enabled:
return
options = self.Options(verbose=True) options = self.Options(verbose=True)
root_dir = tempfile.mkdtemp() root_dir = tempfile.mkdtemp()
relpath = 'foo' relpath = 'foo'
@ -520,6 +538,8 @@ from :3
shutil.rmtree(root_dir) shutil.rmtree(root_dir)
def testUpdateUpdate(self): def testUpdateUpdate(self):
if not self.enabled:
return
options = self.Options() options = self.Options()
expected_file_list = [os.path.join(self.base_path, x) for x in ['a', 'b']] expected_file_list = [os.path.join(self.base_path, x) for x in ['a', 'b']]
scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,

@ -442,12 +442,12 @@ class GClientClassTestCase(GclientTestCase):
"deps = {\n" "deps = {\n"
" 'src/t': 'svn://scm.t/trunk',\n" " 'src/t': 'svn://scm.t/trunk',\n"
"}\n") "}\n")
entry_path = os.path.join(solution_name, 'src', 't').replace('\\', '\\\\')
entries_content = ( entries_content = (
"entries = \\\n" "entries = \\\n"
"{ '%s': '%s',\n" "{ '%s': '%s',\n"
" '%s': 'svn://scm.t/trunk'}\n" " '%s': 'svn://scm.t/trunk'}\n"
) % (solution_name, self.url, os.path.join(solution_name, 'src', 't')) ) % (solution_name, self.url, entry_path)
scm_wrapper_sol = self.mox.CreateMockAnything() scm_wrapper_sol = self.mox.CreateMockAnything()
scm_wrapper_t = self.mox.CreateMockAnything() scm_wrapper_t = self.mox.CreateMockAnything()

@ -69,7 +69,8 @@ class SVNUnittest(TryChangeTestsBase):
class GITUnittest(TryChangeTestsBase): class GITUnittest(TryChangeTestsBase):
"""trychange.GIT tests.""" """trychange.GIT tests."""
def setUp(self): def setUp(self):
self.fake_root = '/fake_root' self.fake_root = gcl.os.path.join(gcl.os.path.dirname(__file__),
'fake_root')
self.expected_files = ['foo.txt', 'bar.txt'] self.expected_files = ['foo.txt', 'bar.txt']
options = optparse.Values() options = optparse.Values()
options.files = self.expected_files options.files = self.expected_files

Loading…
Cancel
Save