Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(769)

Unified Diff: tests/gclient_smoketest.py

Issue 2189001: Add real gclient_smoke tests now (Closed)
Patch Set: Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/fake_repos.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/gclient_smoketest.py
diff --git a/tests/gclient_smoketest.py b/tests/gclient_smoketest.py
index 9d04dc6d8fae51d966ee0c567f599e8c1a4f27c0..7f3491f066bb52fc9dedd393f610003aaccf0096 100755
--- a/tests/gclient_smoketest.py
+++ b/tests/gclient_smoketest.py
@@ -10,27 +10,74 @@ Shell out 'gclient' and run basic conformance tests.
This test assumes GClientSmokeBase.URL_BASE is valid.
"""
+import logging
import os
+import pprint
import shutil
import subprocess
import sys
import unittest
-from fake_repos import rmtree, FakeRepos
+from fake_repos import rmtree, write, FakeRepos
+
+join = os.path.join
SHOULD_LEAK = False
UNITTEST_DIR = os.path.abspath(os.path.dirname(__file__))
-GCLIENT_PATH = os.path.join(os.path.dirname(UNITTEST_DIR), 'gclient')
+GCLIENT_PATH = join(os.path.dirname(UNITTEST_DIR), 'gclient')
# all tests outputs goes there.
-TRIAL_DIR = os.path.join(UNITTEST_DIR, '_trial')
+TRIAL_DIR = join(UNITTEST_DIR, '_trial')
# In case you want to use another machine to create the fake repos, e.g.
# not on Windows.
HOST = '127.0.0.1'
+FAKE = None
+
+
+def read_tree(tree_root):
+ """Returns a dict of all the files in a tree."""
+ tree = {}
+ for root, dirs, files in os.walk(tree_root):
+ for d in filter(lambda x: x.startswith('.'), dirs):
+ dirs.remove(d)
+ for f in [join(root, f) for f in files if not f.startswith('.')]:
+ tree[f[len(tree_root) + 1:]] = open(join(root, f), 'rb').read()
+ return tree
+
+
+def dict_diff(dict1, dict2):
+ diff = {}
+ for k, v in dict1.iteritems():
+ if k not in dict2:
+ diff[k] = v
+ elif v != dict2[k]:
+ diff[k] = (v, dict2[k])
+ for k, v in dict2.iteritems():
+ if k not in dict1:
+ diff[k] = v
+ return diff
+
+
+def mangle_svn_tree(*args):
+ result = {}
+ for old_root, new_root, tree in args:
+ for k, v in tree.iteritems():
+ if not k.startswith(old_root):
+ continue
+ result[join(new_root, k[len(old_root) + 1:])] = v
+ return result
+
+
+def mangle_git_tree(*args):
+ result = {}
+ for new_root, tree in args:
+ for k, v in tree.iteritems():
+ result[join(new_root, k)] = v
+ return result
class GClientSmokeBase(unittest.TestCase):
# This subversion repository contains a test repository.
- ROOT_DIR = os.path.join(TRIAL_DIR, 'smoke')
+ ROOT_DIR = join(TRIAL_DIR, 'smoke')
def setUp(self):
# Vaguely inspired by twisted.
@@ -38,7 +85,7 @@ class GClientSmokeBase(unittest.TestCase):
self.env = os.environ.copy()
self.env['DEPOT_TOOLS_UPDATE'] = '0'
# Remove left overs
- self.root_dir = os.path.join(self.ROOT_DIR, self.id())
+ self.root_dir = join(self.ROOT_DIR, self.id())
rmtree(self.root_dir)
if not os.path.exists(self.ROOT_DIR):
os.mkdir(self.ROOT_DIR)
@@ -70,6 +117,15 @@ class GClientSmokeBase(unittest.TestCase):
checkString(expected[1], results[1])
self.assertEquals(expected[2], results[2])
+ def assertTree(self, tree):
+ actual = read_tree(self.root_dir)
+ diff = dict_diff(tree, actual)
+ if diff:
+ logging.debug('Actual %s\n%s' % (self.root_dir, pprint.pformat(actual)))
+ logging.debug('Expected\n%s' % pprint.pformat(tree))
+ logging.debug('Diff\n%s' % pprint.pformat(diff))
+ self.assertEquals(tree, actual)
+
class GClientSmoke(GClientSmokeBase):
def testCommands(self):
@@ -80,7 +136,7 @@ class GClientSmoke(GClientSmokeBase):
self.assertEquals(0, result[2])
def testNotConfigured(self):
- res = ("", "Error: client not configured; see 'gclient config'\n", 1)
+ res = ('', 'Error: client not configured; see \'gclient config\'\n', 1)
self.check(res, self.gclient(['cleanup']))
self.check(res, self.gclient(['diff']))
self.check(res, self.gclient(['export', 'foo']))
@@ -93,30 +149,169 @@ class GClientSmoke(GClientSmokeBase):
self.check(res, self.gclient(['update']))
-class GClientSmokeSync(GClientSmokeBase):
+class GClientSmokeSVN(GClientSmokeBase):
"""sync is the most important command. Hence test it more."""
- def testSyncSvn(self):
+ def testSync(self):
"""Test pure gclient svn checkout, example of Chromium checkout"""
self.gclient(['config', self.svn_base + 'trunk/src/'])
- results = self.gclient(['sync'])
+ # Test unversioned checkout.
+ results = self.gclient(['sync', '--deps', 'mac'])
+ logging.debug(results[0])
+ self.assertEquals('', results[1])
+ self.assertEquals(0, results[2])
+ tree = mangle_svn_tree(
+ (join('trunk', 'src'), 'src', FAKE.svn_revs[-1]),
+ (join('trunk', 'third_party', 'foo'), join('src', 'third_party', 'foo'),
+ FAKE.svn_revs[1]),
+ (join('trunk', 'other'), join('src', 'other'), FAKE.svn_revs[2]),
+ )
+ self.assertTree(tree)
+
+ # Test incremental versioned sync: sync backward.
+ results = self.gclient(['sync', '--revision', 'src@1', '--deps', 'mac',
+ '--delete_unversioned_trees'])
+ logging.debug(results[0])
+ self.assertEquals('', results[1])
self.assertEquals(0, results[2])
- results = self.gclient(['sync', '--revision', 'a@32'])
+ tree = mangle_svn_tree(
+ (join('trunk', 'src'), 'src', FAKE.svn_revs[1]),
+ (join('trunk', 'third_party', 'foo'), join('src', 'third_party', 'fpp'),
+ FAKE.svn_revs[2]),
+ (join('trunk', 'other'), join('src', 'other'), FAKE.svn_revs[2]),
+ (join('trunk', 'third_party', 'foo'),
+ join('src', 'third_party', 'prout'),
+ FAKE.svn_revs[2]),
+ )
+ self.assertTree(tree)
+ # Test incremental sync: delete-unversioned_trees isn't there.
+ results = self.gclient(['sync', '--deps', 'mac'])
+ logging.debug(results[0])
+ self.assertEquals('', results[1])
+ self.assertEquals(0, results[2])
+ tree = mangle_svn_tree(
+ (join('trunk', 'src'), 'src', FAKE.svn_revs[-1]),
+ (join('trunk', 'third_party', 'foo'), join('src', 'third_party', 'fpp'),
+ FAKE.svn_revs[2]),
+ (join('trunk', 'third_party', 'foo'), join('src', 'third_party', 'foo'),
+ FAKE.svn_revs[1]),
+ (join('trunk', 'other'), join('src', 'other'), FAKE.svn_revs[2]),
+ (join('trunk', 'third_party', 'foo'),
+ join('src', 'third_party', 'prout'),
+ FAKE.svn_revs[2]),
+ )
+ self.assertTree(tree)
+
+ def testRevertAndStatus(self):
+ self.gclient(['config', self.svn_base + 'trunk/src/'])
+ results = self.gclient(['sync', '--deps', 'mac'])
+ write(join(self.root_dir, 'src', 'third_party', 'foo', 'hi'), 'Hey!')
+
+ results = self.gclient(['status'])
+ out = results[0].splitlines(False)
+ self.assertEquals(7, len(out))
+ self.assertEquals(out[0], '')
+ self.assertTrue(out[1].startswith('________ running \'svn status\' in \''))
+ self.assertEquals(out[2], '? other')
+ self.assertEquals(out[3], '? third_party/foo')
+ self.assertEquals(out[4], '')
+ self.assertTrue(out[5].startswith('________ running \'svn status\' in \''))
+ self.assertEquals(out[6], '? hi')
+ self.assertEquals('', results[1])
self.assertEquals(0, results[2])
+ results = self.gclient(['revert'])
+ self.assertEquals('', results[1])
+ self.assertEquals(0, results[2])
+ tree = mangle_svn_tree(
+ (join('trunk', 'src'), 'src', FAKE.svn_revs[-1]),
+ (join('trunk', 'third_party', 'foo'), join('src', 'third_party', 'foo'),
+ FAKE.svn_revs[1]),
+ (join('trunk', 'other'), join('src', 'other'), FAKE.svn_revs[2]),
+ )
+ self.assertTree(tree)
+
+ results = self.gclient(['status'])
+ out = results[0].splitlines(False)
+ self.assertEquals(4, len(out))
+ self.assertEquals(out[0], '')
+ self.assertTrue(out[1].startswith('________ running \'svn status\' in \''))
+ self.assertEquals(out[2], '? other')
+ self.assertEquals(out[3], '? third_party/foo')
+ self.assertEquals('', results[1])
+ self.assertEquals(0, results[2])
+
+
+class GClientSmokeGIT(GClientSmokeBase):
def testSyncGit(self):
"""Test pure gclient git checkout, example of Chromium OS checkout"""
- self.gclient(['config', self.git_base + 'repo_1'])
- results = self.gclient(['sync'])
- print results[0]
- print results[1]
+ self.gclient(['config', self.git_base + 'repo_1', '--name', 'src'])
+ # Test unversioned checkout.
+ results = self.gclient(['sync', '--deps', 'mac'])
yaar1 2010/05/26 01:37:24 Is this only going to work on Mac?
M-A Ruel 2010/05/26 01:56:02 No but I'm enforcing the platform so the test beha
+ logging.debug(results[0])
+ self.assertTrue(results[1].startswith('Switched to a new branch \''))
self.assertEquals(0, results[2])
+ tree = mangle_git_tree(
+ ('src', FAKE.git_hashes['repo_1'][1][1]),
+ (join('src', 'repo2'), FAKE.git_hashes['repo_2'][0][1]),
+ (join('src', 'repo2', 'repo_renamed'), FAKE.git_hashes['repo_3'][1][1]),
+ )
+ self.assertTree(tree)
+ # Test incremental versioned sync: sync backward.
+ results = self.gclient(['sync', '--revision',
+ 'src@' + FAKE.git_hashes['repo_1'][0][0],
+ '--deps', 'mac', '--delete_unversioned_trees'])
+ logging.debug(results[0])
+ self.assertEquals('', results[1])
+ self.assertEquals(0, results[2])
+ tree = mangle_git_tree(
+ ('src', FAKE.git_hashes['repo_1'][0][1]),
+ (join('src', 'repo2'), FAKE.git_hashes['repo_2'][1][1]),
+ (join('src', 'repo2', 'repo3'), FAKE.git_hashes['repo_3'][1][1]),
+ (join('src', 'repo4'), FAKE.git_hashes['repo_4'][1][1]),
+ )
+ self.assertTree(tree)
+ # Test incremental sync: delete-unversioned_trees isn't there.
+ results = self.gclient(['sync', '--deps', 'mac'])
+ logging.debug(results[0])
+ self.assertEquals('', results[1])
+ self.assertEquals(0, results[2])
+ tree = mangle_git_tree(
+ ('src', FAKE.git_hashes['repo_1'][1][1]),
+ (join('src', 'repo2'), FAKE.git_hashes['repo_2'][1][1]),
+ (join('src', 'repo2', 'repo3'), FAKE.git_hashes['repo_3'][1][1]),
+ (join('src', 'repo2', 'repo_renamed'), FAKE.git_hashes['repo_3'][1][1]),
+ (join('src', 'repo4'), FAKE.git_hashes['repo_4'][1][1]),
+ )
+ self.assertTree(tree)
-class GClientSmokeRevert(GClientSmokeBase):
- """revert is the second most important command. Hence test it more."""
- def setUp(self):
- GClientSmokeBase.setUp(self)
- self.gclient(['config', self.URL_BASE])
+ def testRevertAndStatus(self):
+ """TODO(maruel): Remove this line once this test is fixed."""
+ self.gclient(['config', self.git_base + 'repo_1', '--name', 'src'])
+ results = self.gclient(['sync', '--deps', 'mac'])
+ write(join(self.root_dir, 'src', 'repo2', 'hi'), 'Hey!')
+
+ results = self.gclient(['status'])
+ out = results[0].splitlines(False)
+ # TODO(maruel): THIS IS WRONG.
+ self.assertEquals(0, len(out))
+
+ results = self.gclient(['revert'])
+ self.assertEquals('', results[1])
+ self.assertEquals(0, results[2])
+ tree = mangle_git_tree(
+ ('src', FAKE.git_hashes['repo_1'][1][1]),
+ (join('src', 'repo2'), FAKE.git_hashes['repo_2'][0][1]),
+ (join('src', 'repo2', 'repo_renamed'), FAKE.git_hashes['repo_3'][1][1]),
+ )
+ # TODO(maruel): THIS IS WRONG.
+ tree[join('src', 'repo2', 'hi')] = 'Hey!'
+ self.assertTree(tree)
+
+ results = self.gclient(['status'])
+ out = results[0].splitlines(False)
+ # TODO(maruel): THIS IS WRONG.
+ self.assertEquals(0, len(out))
class GClientSmokeRevInfo(GClientSmokeBase):
@@ -127,9 +322,14 @@ class GClientSmokeRevInfo(GClientSmokeBase):
if __name__ == '__main__':
- fake = FakeRepos(TRIAL_DIR, SHOULD_LEAK, True)
+ if '-v' in sys.argv:
+ logging.basicConfig(level=logging.DEBUG)
+ if '-l' in sys.argv:
+ SHOULD_LEAK = True
+ sys.argv.remove('-l')
+ FAKE = FakeRepos(TRIAL_DIR, SHOULD_LEAK, True)
try:
- fake.setUp()
+ FAKE.setUp()
unittest.main()
finally:
- fake.tearDown()
+ FAKE.tearDown()
« no previous file with comments | « tests/fake_repos.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698