mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
Make more tests pass on Windows.
Also fix a few issues found along the way. Tests had regressed a lot. Add a lot of tweaks to make most test pass. R=dpranke@chromium.org BUG= TEST= Review URL: http://codereview.chromium.org/6792060 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@80618 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
@@ -51,6 +51,10 @@ def CommonChecks(input_api, output_api):
|
||||
def RunGitClTests(input_api, output_api, verbose):
|
||||
"""Run all the shells scripts in the directory test.
|
||||
"""
|
||||
if input_api.platform == 'win32':
|
||||
# Skip for now as long as the test scripts are bash scripts.
|
||||
return []
|
||||
|
||||
# First loads a local Rietveld instance.
|
||||
import sys
|
||||
old_sys_path = sys.path
|
||||
|
||||
@@ -20,7 +20,7 @@ import urlparse
|
||||
import urllib2
|
||||
|
||||
try:
|
||||
import readline # pylint: disable=W0611
|
||||
import readline # pylint: disable=F0401,W0611
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
10
scm.py
10
scm.py
@@ -74,14 +74,16 @@ def determine_scm(root):
|
||||
"""
|
||||
if os.path.isdir(os.path.join(root, '.svn')):
|
||||
return 'svn'
|
||||
elif os.path.isdir(os.path.join(root, '.svn')):
|
||||
elif os.path.isdir(os.path.join(root, '.git')):
|
||||
return 'git'
|
||||
else:
|
||||
if (0 == subprocess.call(
|
||||
try:
|
||||
subprocess2.check_output(
|
||||
['git', 'rev-parse', '--show-cdup'],
|
||||
stdout=subprocess.PIPE, cwd=root)):
|
||||
stdout=subprocess2.VOID,
|
||||
cwd=root)
|
||||
return 'git'
|
||||
else:
|
||||
except (OSError, subprocess2.CalledProcessError):
|
||||
return None
|
||||
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ def kill_pid(pid):
|
||||
"""Kills a process by its process id."""
|
||||
try:
|
||||
# Unable to import 'module'
|
||||
# pylint: disable=F0401
|
||||
# pylint: disable=E1101,F0401
|
||||
import signal
|
||||
return os.kill(pid, signal.SIGKILL)
|
||||
except ImportError:
|
||||
@@ -105,6 +105,8 @@ def get_english_env(env):
|
||||
|
||||
Returns None if it is unnecessary.
|
||||
"""
|
||||
if sys.platform == 'win32':
|
||||
return None
|
||||
env = env or os.environ
|
||||
|
||||
# Test if it is necessary at all.
|
||||
|
||||
@@ -310,8 +310,7 @@ class FakeReposBase(object):
|
||||
return True
|
||||
try:
|
||||
subprocess2.check_call(['svnadmin', 'create', self.svn_repo])
|
||||
except subprocess2.CalledProcessError, e:
|
||||
logging.debug('Failed with : %s' % e)
|
||||
except (OSError, subprocess2.CalledProcessError):
|
||||
return False
|
||||
write(join(self.svn_repo, 'conf', 'svnserve.conf'),
|
||||
'[general]\n'
|
||||
@@ -352,9 +351,11 @@ class FakeReposBase(object):
|
||||
self.set_up()
|
||||
if self.gitdaemon:
|
||||
return True
|
||||
if sys.platform == 'win32':
|
||||
return False
|
||||
assert self.git_pid_file == None
|
||||
try:
|
||||
subprocess2.check_output(['git', '--version'])
|
||||
except (OSError, subprocess2.CalledProcessError):
|
||||
return False
|
||||
for repo in ['repo_%d' % r for r in range(1, self.NB_GIT_REPOS + 1)]:
|
||||
subprocess2.check_call(['git', 'init', '-q', join(self.git_root, repo)])
|
||||
self.git_hashes[repo] = [None]
|
||||
|
||||
@@ -41,12 +41,13 @@ class FixEncodingTest(unittest.TestCase):
|
||||
def test_win_console(self):
|
||||
if sys.platform != 'win32':
|
||||
return
|
||||
# This should fail if redirected. Can be checked with:
|
||||
# python fix_encoding_test.py > a
|
||||
# This should fail if not redirected, e.g. run directly instead of through
|
||||
# the presubmit check. Can be checked with:
|
||||
# python tests\fix_encoding_test.py
|
||||
self.assertEquals(
|
||||
sys.stdout.__class__, fix_encoding.WinUnicodeConsoleOutput)
|
||||
sys.stdout.__class__, fix_encoding.WinUnicodeOutput)
|
||||
self.assertEquals(
|
||||
sys.stderr.__class__, fix_encoding.WinUnicodeConsoleOutput)
|
||||
sys.stderr.__class__, fix_encoding.WinUnicodeOutput)
|
||||
self.assertEquals(sys.stdout.encoding, sys.getdefaultencoding())
|
||||
self.assertEquals(sys.stderr.encoding, sys.getdefaultencoding())
|
||||
|
||||
|
||||
@@ -127,7 +127,14 @@ class GClientSmokeBase(FakeReposTestBase):
|
||||
verb = items[i]
|
||||
path = self.root_dir
|
||||
self.checkString(results[i][0][0], verb, (i, results[i][0][0], verb))
|
||||
self.checkString(results[i][0][2], path, (i, results[i][0][2], path))
|
||||
if sys.platform == 'win32':
|
||||
# Make path lower case since casing can change randomly.
|
||||
self.checkString(
|
||||
results[i][0][2].lower(),
|
||||
path.lower(),
|
||||
(i, results[i][0][2].lower(), path.lower()))
|
||||
else:
|
||||
self.checkString(results[i][0][2], path, (i, results[i][0][2], path))
|
||||
self.assertEquals(len(results), len(items), (stdout, items, len(results)))
|
||||
return results
|
||||
|
||||
|
||||
@@ -71,15 +71,15 @@ class LocalRietveld(object):
|
||||
subprocess2.check_call(
|
||||
['svn', 'co', '-q', 'http://rietveld.googlecode.com/svn/trunk@681',
|
||||
self.rietveld])
|
||||
except subprocess2.CalledProcessError:
|
||||
raise Failure('Failed to checkout rietveld')
|
||||
except (OSError, subprocess2.CalledProcessError), e:
|
||||
raise Failure('Failed to checkout rietveld\n%s' % e)
|
||||
else:
|
||||
print('Syncing rietveld...')
|
||||
try:
|
||||
subprocess2.check_call(
|
||||
['svn', 'up', '-q', '-r', '681'], cwd=self.rietveld)
|
||||
except subprocess2.CalledProcessError:
|
||||
raise Failure('Failed to checkout rietveld')
|
||||
except (OSError, subprocess2.CalledProcessError), e:
|
||||
raise Failure('Failed to sync rietveld\n%s' % e)
|
||||
|
||||
def start_server(self, verbose=False):
|
||||
self.install_prerequisites()
|
||||
@@ -89,6 +89,7 @@ class LocalRietveld(object):
|
||||
else:
|
||||
pipe = subprocess2.VOID
|
||||
cmd = [
|
||||
sys.executable,
|
||||
self.dev_app,
|
||||
'--skip_sdk_update_check',
|
||||
'.',
|
||||
|
||||
@@ -2006,8 +2006,11 @@ mac|success|blew
|
||||
input_api.PresubmitLocalPath().AndReturn(self.fake_root_dir)
|
||||
input_api.subprocess.check_call(
|
||||
['allo'], cwd=self.fake_root_dir)
|
||||
cmd = ['bar.py']
|
||||
if input_api.platform == 'win32':
|
||||
cmd.insert(0, input_api.python_executable)
|
||||
input_api.subprocess.check_call(
|
||||
['bar.py'], cwd=self.fake_root_dir).AndRaise(
|
||||
cmd, cwd=self.fake_root_dir).AndRaise(
|
||||
input_api.subprocess.CalledProcessError())
|
||||
|
||||
self.mox.ReplayAll()
|
||||
@@ -2031,7 +2034,8 @@ mac|success|blew
|
||||
input_api.os_listdir(path).AndReturn(['.', '..', 'a', 'b', 'c'])
|
||||
input_api.os_path.isfile = lambda x: not x.endswith('.')
|
||||
input_api.subprocess.check_call(
|
||||
['random_directory/b'], cwd=self.fake_root_dir)
|
||||
[presubmit.os.path.join('random_directory', 'b')],
|
||||
cwd=self.fake_root_dir)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
results = presubmit_canned_checks.RunUnitTestsInDirectory(
|
||||
@@ -2042,7 +2046,8 @@ mac|success|blew
|
||||
blacklist=['a'],
|
||||
verbose=True)
|
||||
self.assertEqual(results, [])
|
||||
self.checkstdout('Running random_directory/b\n')
|
||||
self.checkstdout(
|
||||
'Running %s\n' % presubmit.os.path.join('random_directory', 'b'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -261,22 +261,27 @@ class RealSvnTest(fake_repos.FakeReposTestBase):
|
||||
# Tests that work with a checkout.
|
||||
def setUp(self):
|
||||
super(RealSvnTest, self).setUp()
|
||||
self.FAKE_REPOS.set_up_svn()
|
||||
self.svn_root = scm.os.path.join(self.root_dir, 'base')
|
||||
scm.SVN.Capture(
|
||||
['checkout', self.svn_base + 'trunk/third_party', 'base'],
|
||||
cwd=self.root_dir)
|
||||
self.tree = self.mangle_svn_tree(('trunk/third_party@-1', ''),)
|
||||
self.enabled = self.FAKE_REPOS.set_up_svn()
|
||||
if self.enabled:
|
||||
self.svn_root = scm.os.path.join(self.root_dir, 'base')
|
||||
scm.SVN.Capture(
|
||||
['checkout', self.svn_base + 'trunk/third_party', 'base'],
|
||||
cwd=self.root_dir)
|
||||
self.tree = self.mangle_svn_tree(('trunk/third_party@-1', ''),)
|
||||
|
||||
def _capture(self, cmd, **kwargs):
|
||||
kwargs.setdefault('cwd', self.svn_root)
|
||||
return scm.SVN.Capture(cmd, **kwargs)
|
||||
|
||||
def testCheckout(self):
|
||||
if not self.enabled:
|
||||
return
|
||||
# Checkout and verify the tree.
|
||||
self.assertTree(self.tree, self.svn_root)
|
||||
|
||||
def testRevert(self):
|
||||
if not self.enabled:
|
||||
return
|
||||
# Mess around and make sure revert works for all corner cases.
|
||||
# - svn add a file
|
||||
# - svn add a file and delete it
|
||||
|
||||
@@ -28,7 +28,7 @@ class Subprocess2Test(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.exe_path = __file__
|
||||
self.exe = [self.exe_path, '--child']
|
||||
self.exe = [sys.executable, self.exe_path, '--child']
|
||||
self.saved = {}
|
||||
for module, names in self.TO_SAVE.iteritems():
|
||||
self.saved[module] = dict(
|
||||
@@ -101,14 +101,20 @@ class Subprocess2Test(unittest.TestCase):
|
||||
results = self._fake_subprocess_Popen()
|
||||
proc = subprocess2.Popen(['foo'], a=True)
|
||||
self.assertEquals(-8, proc.returncode)
|
||||
env = os.environ.copy()
|
||||
env['LANG'] = 'en_US.UTF-8'
|
||||
expected = {
|
||||
'args': ['foo'],
|
||||
'a': True,
|
||||
'shell': bool(sys.platform=='win32'),
|
||||
'env': env,
|
||||
}
|
||||
if sys.platform != 'win32':
|
||||
env = os.environ.copy()
|
||||
is_english = lambda name: env.get(name, 'en').startswith('en')
|
||||
if not is_english('LANG'):
|
||||
env['LANG'] = 'en_US.UTF-8'
|
||||
expected['env'] = env
|
||||
if not is_english('LANGUAGE'):
|
||||
env['LANGUAGE'] = 'en_US.UTF-8'
|
||||
expected['env'] = env
|
||||
self.assertEquals(expected, results)
|
||||
|
||||
def test_check_output_defaults(self):
|
||||
@@ -140,12 +146,14 @@ class Subprocess2Test(unittest.TestCase):
|
||||
self.assertEquals(None, out)
|
||||
out = subprocess2.check_output(
|
||||
self.exe + ['--stdout', '--stderr'],
|
||||
universal_newlines=True,
|
||||
stderr=subprocess2.VOID)
|
||||
self.assertEquals('A\nBB\nCCC\n', out)
|
||||
|
||||
def test_check_output_throw(self):
|
||||
try:
|
||||
subprocess2.check_output(self.exe + ['--fail', '--stderr'])
|
||||
subprocess2.check_output(
|
||||
self.exe + ['--fail', '--stderr'], universal_newlines=True)
|
||||
self.fail()
|
||||
except subprocess2.CalledProcessError, e:
|
||||
self.assertEquals('a\nbb\nccc\n', e.stdout)
|
||||
|
||||
Reference in New Issue
Block a user