Commit ea6c2c5c authored by maruel@chromium.org's avatar maruel@chromium.org

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
parent efb9450e
......@@ -378,18 +378,22 @@ M 100644 :5 b
reset refs/heads/master
from :3
"""
def Options(self, *args, **kwargs):
return self.OptionsObject(self, *args, **kwargs)
def CreateGitRepo(self, git_import, path):
subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, cwd=path).communicate()
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 GetGitRev(self, path):
return subprocess.Popen(['git', 'rev-parse', 'HEAD'],
......@@ -404,7 +408,7 @@ from :3
self.root_dir = tempfile.mkdtemp()
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):
shutil.rmtree(self.root_dir)
......@@ -420,6 +424,8 @@ from :3
self.compareMembers(gclient_scm.CreateSCM(url=self.url), members)
def testRevertMissing(self):
if not self.enabled:
return
options = self.Options()
file_path = os.path.join(self.base_path, 'a')
os.remove(file_path)
......@@ -433,6 +439,8 @@ from :3
self.assertEquals(file_list, [])
def testRevertNone(self):
if not self.enabled:
return
options = self.Options()
scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
relpath=self.relpath)
......@@ -444,6 +452,8 @@ from :3
def testRevertModified(self):
if not self.enabled:
return
options = self.Options()
file_path = os.path.join(self.base_path, 'a')
open(file_path, 'a').writelines('touched\n')
......@@ -459,6 +469,8 @@ from :3
'069c602044c5388d2d15c3f875b057c852003458')
def testRevertNew(self):
if not self.enabled:
return
options = self.Options()
file_path = os.path.join(self.base_path, 'c')
f = open(file_path, 'w')
......@@ -478,6 +490,8 @@ from :3
'069c602044c5388d2d15c3f875b057c852003458')
def testStatusNew(self):
if not self.enabled:
return
options = self.Options()
file_path = os.path.join(self.base_path, 'a')
open(file_path, 'a').writelines('touched\n')
......@@ -488,6 +502,8 @@ from :3
self.assertEquals(file_list, [file_path])
def testStatus2New(self):
if not self.enabled:
return
options = self.Options()
expected_file_list = []
for f in ['a', 'b']:
......@@ -502,6 +518,8 @@ from :3
self.assertEquals(sorted(file_list), expected_file_list)
def testUpdateCheckout(self):
if not self.enabled:
return
options = self.Options(verbose=True)
root_dir = tempfile.mkdtemp()
relpath = 'foo'
......@@ -520,6 +538,8 @@ from :3
shutil.rmtree(root_dir)
def testUpdateUpdate(self):
if not self.enabled:
return
options = self.Options()
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,
......
......@@ -442,12 +442,12 @@ class GClientClassTestCase(GclientTestCase):
"deps = {\n"
" 'src/t': 'svn://scm.t/trunk',\n"
"}\n")
entry_path = os.path.join(solution_name, 'src', 't').replace('\\', '\\\\')
entries_content = (
"entries = \\\n"
"{ '%s': '%s',\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_t = self.mox.CreateMockAnything()
......
......@@ -69,7 +69,8 @@ class SVNUnittest(TryChangeTestsBase):
class GITUnittest(TryChangeTestsBase):
"""trychange.GIT tests."""
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']
options = optparse.Values()
options.files = self.expected_files
......
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