From 17cdf76123c98b1148ec566492fb314ff48f1ec0 Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Fri, 28 May 2010 17:30:52 +0000 Subject: [PATCH] Make FakeRepos more reusable. Make it work with 'coverage'. Make FakeRepos initialization lazy. Only generate the repository when needed. It's in part intended for gclient_scm_tests.py but I left it out of this review. To use: easy_install coverage ./tests/gclient_smoke.py -c coverage report Current coverage with gclient_smoke: Name Stmts Exec Cover ----------------------------------------------- gclient 557 416 74% gclient_scm 496 270 54% gclient_utils 195 117 60% scm 439 180 41% (ignoring irrelevant files) It's quite good in fact, 74% of gclient.py being executed with the smoke test. Review URL: http://codereview.chromium.org/2352002 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@48501 0039d316-1c4b-4281-b951-d872f2087c98 --- gclient.py | 1 + tests/fake_repos.py | 239 ++++++++++++++++++++++++++--------- tests/gclient_smoketest.py | 252 ++++++++++++------------------------- 3 files changed, 265 insertions(+), 227 deletions(-) diff --git a/gclient.py b/gclient.py index 581302986..c3863d39c 100644 --- a/gclient.py +++ b/gclient.py @@ -691,6 +691,7 @@ solutions = [ gclient_utils.RemoveDirectory(e_dir) # record the current list of entries for next time self._SaveEntries(entries) + return 0 def PrintRevInfo(self): """Output revision info mapping for the client and its dependencies. diff --git a/tests/fake_repos.py b/tests/fake_repos.py index 920742e47..bef8fa82f 100755 --- a/tests/fake_repos.py +++ b/tests/fake_repos.py @@ -5,12 +5,17 @@ """Generate fake repositories for testing.""" +import atexit import logging import os import re import shutil import subprocess import sys +import unittest + + +## Utility functions def addKill(): @@ -44,11 +49,6 @@ def write(path, content): join = os.path.join -def call(*args, **kwargs): - logging.debug(args[0]) - subprocess.call(*args, **kwargs) - - def check_call(*args, **kwargs): logging.debug(args[0]) subprocess.check_call(*args, **kwargs) @@ -61,6 +61,48 @@ def Popen(*args, **kwargs): return subprocess.Popen(*args, **kwargs) +def read_tree(tree_root): + """Returns a dict of all the files in a tree. Defaults to self.root_dir.""" + 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 + + def commit_svn(repo): """Commits the changes and returns the new revision number.""" # Basic parsing. @@ -96,6 +138,8 @@ def commit_git(repo): return rev +_FAKE_LOADED = False + class FakeRepos(object): """Generate both svn and git repositories to test gclient functionality. @@ -104,38 +148,71 @@ class FakeRepos(object): And types of dependencies: Relative urls, Full urls, both svn and git.""" - def __init__(self, trial_dir, leak, local_only): - self.trial_dir = trial_dir - self.repos_dir = os.path.join(self.trial_dir, 'repos') - self.git_root = join(self.repos_dir, 'git') - self.svn_root = join(self.repos_dir, 'svn_checkout') - self.leak = leak - self.local_only = local_only - self.svnserve = [] - self.gitdaemon = [] - addKill() - rmtree(self.trial_dir) - os.mkdir(self.trial_dir) - os.mkdir(self.repos_dir) + # Should leak the repositories. + SHOULD_LEAK = False + # Override if unhappy. + TRIAL_DIR = None + # Hostname + HOST = '127.0.0.1' + + def __init__(self, trial_dir=None, leak=None, host=None): + global _FAKE_LOADED + if _FAKE_LOADED: + raise Exception('You can only start one FakeRepos at a time.') + _FAKE_LOADED = True + # Quick hack. + if '-v' in sys.argv: + logging.basicConfig(level=logging.DEBUG) + if '-l' in sys.argv: + self.SHOULD_LEAK = True + sys.argv.remove('-l') + elif leak is not None: + self.SHOULD_LEAK = leak + if host: + self.HOST = host + if trial_dir: + self.TRIAL_DIR = trial_dir + # Format is [ None, tree, tree, ...] self.svn_revs = [None] # Format is { repo: [ (hash, tree), (hash, tree), ... ], ... } self.git_hashes = {} + self.svnserve = None + self.gitdaemon = None + self.common_init = False + + def trial_dir(self): + if not self.TRIAL_DIR: + self.TRIAL_DIR = os.path.join( + os.path.dirname(os.path.abspath(__file__)), '_trial') + return self.TRIAL_DIR def setUp(self): - self.setUpSVN() - self.setUpGIT() + """All late initialization comes here. + + Note that it deletes all trial_dir() and not only repos_dir.""" + if not self.common_init: + self.common_init = True + self.repos_dir = os.path.join(self.trial_dir(), 'repos') + self.git_root = join(self.repos_dir, 'git') + self.svn_root = join(self.repos_dir, 'svn_checkout') + addKill() + rmtree(self.trial_dir()) + os.makedirs(self.repos_dir) + atexit.register(self.tearDown) def tearDown(self): - for i in self.svnserve: - logging.debug('Killing svnserve pid %s' % i.pid) - i.kill() - for i in self.gitdaemon: - logging.debug('Killing git-daemon pid %s' % i.pid) - i.kill() - if not self.leak: - logging.debug('Removing %s' % self.trial_dir) - rmtree(self.trial_dir) + if self.svnserve: + logging.debug('Killing svnserve pid %s' % self.svnserve.pid) + self.svnserve.kill() + self.svnserve = None + if self.gitdaemon: + logging.debug('Killing git-daemon pid %s' % self.gitdaemon.pid) + self.gitdaemon.kill() + self.gitdaemon = None + if not self.SHOULD_LEAK: + logging.debug('Removing %s' % self.trial_dir()) + rmtree(self.trial_dir()) def _genTree(self, root, tree_dict): """For a dictionary of file contents, generate a filesystem.""" @@ -155,9 +232,10 @@ class FakeRepos(object): def setUpSVN(self): """Creates subversion repositories and start the servers.""" - assert not self.svnserve + if self.svnserve: + return + self.setUp() root = join(self.repos_dir, 'svn') - rmtree(root) check_call(['svnadmin', 'create', root]) write(join(root, 'conf', 'svnserve.conf'), '[general]\n' @@ -171,10 +249,10 @@ class FakeRepos(object): # Start the daemon. cmd = ['svnserve', '-d', '--foreground', '-r', self.repos_dir] - if self.local_only: + if self.HOST == '127.0.0.1': cmd.append('--listen-host=127.0.0.1') logging.debug(cmd) - self.svnserve.append(Popen(cmd, cwd=root)) + self.svnserve = Popen(cmd, cwd=root) self.populateSvn() def populateSvn(self): @@ -224,7 +302,7 @@ deps_os = { 'mac': { 'src/third_party/prout': '/trunk/third_party/prout', }, -}""" % { 'host': '127.0.0.1' })) +}""" % { 'host': self.HOST })) self._commit_svn(file_system(2, """ deps = { @@ -246,12 +324,13 @@ hooks = [ 'open(\\'src/svn_hooked2\\', \\'w\\').write(\\'svn_hooked2\\')'], }, ] -""" % { 'host': '127.0.0.1' })) +""" % { 'host': self.HOST })) def setUpGIT(self): """Creates git repositories and start the servers.""" - assert not self.gitdaemon - rmtree(self.git_root) + if self.gitdaemon: + return + self.setUp() for repo in ['repo_%d' % r for r in range(1, 5)]: check_call(['git', 'init', '-q', join(self.git_root, repo)]) self.git_hashes[repo] = [] @@ -281,7 +360,7 @@ deps_os = { 'mac': { 'src/repo4': '/repo_4', }, -}""" % { 'host': '127.0.0.1' }, +}""" % { 'host': self.HOST }, 'origin': 'git/repo_1@1\n', }) @@ -331,17 +410,19 @@ hooks = [ }, ] """ % { - # TODO(maruel): http://crosbug.com/3591 We need to strip the hash.. duh. - 'host': '127.0.0.1', 'hash': self.git_hashes['repo_2'][0][0][:7] }, + # TODO(maruel): http://crosbug.com/3591 We need to strip the hash.. duh. + 'host': self.HOST, + 'hash': self.git_hashes['repo_2'][0][0][:7] + }, 'origin': "git/repo_1@2\n" }) # Start the daemon. cmd = ['git', 'daemon', '--export-all', '--base-path=' + self.repos_dir] - if self.local_only: + if self.HOST == '127.0.0.1': cmd.append('--listen=127.0.0.1') logging.debug(cmd) - self.gitdaemon.append(Popen(cmd, cwd=self.repos_dir)) + self.gitdaemon = Popen(cmd, cwd=self.repos_dir) def _commit_svn(self, tree): self._genTree(self.svn_root, tree) @@ -365,27 +446,71 @@ hooks = [ self.git_hashes[repo].append((hash, new_tree)) +class FakeReposTestBase(unittest.TestCase): + """This is vaguely inspired by twisted.""" + + # Replace this in your subclass. + CLASS_ROOT_DIR = None + + # static FakeRepos instance. + FAKE_REPOS = FakeRepos() + + def setUp(self): + unittest.TestCase.setUp(self) + self.FAKE_REPOS.setUp() + + # Remove left overs and start fresh. + if not self.CLASS_ROOT_DIR: + self.CLASS_ROOT_DIR = join(self.FAKE_REPOS.trial_dir(), 'smoke') + self.root_dir = join(self.CLASS_ROOT_DIR, self.id()) + rmtree(self.root_dir) + os.makedirs(self.root_dir) + self.svn_base = 'svn://%s/svn/' % self.FAKE_REPOS.HOST + self.git_base = 'git://%s/git/' % self.FAKE_REPOS.HOST + + def tearDown(self): + if not self.FAKE_REPOS.SHOULD_LEAK: + rmtree(self.root_dir) + + def checkString(self, expected, result): + """Prints the diffs to ease debugging.""" + if expected != result: + # Strip the begining + while expected and result and expected[0] == result[0]: + expected = expected[1:] + result = result[1:] + # The exception trace makes it hard to read so dump it too. + if '\n' in result: + print result + self.assertEquals(expected, result) + + def check(self, expected, results): + """Checks stdout, stderr, retcode.""" + self.checkString(expected[0], results[0]) + self.checkString(expected[1], results[1]) + self.assertEquals(expected[2], results[2]) + + def assertTree(self, tree, tree_root=None): + """Diff the checkout tree with a dict.""" + if not tree_root: + tree_root = self.root_dir + actual = read_tree(tree_root) + diff = dict_diff(tree, actual) + if diff: + logging.debug('Actual %s\n%s' % (tree_root, pprint.pformat(actual))) + logging.debug('Expected\n%s' % pprint.pformat(tree)) + logging.debug('Diff\n%s' % pprint.pformat(diff)) + + def main(argv): - leak = '-l' in argv - if leak: - argv.remove('-l') - verbose = '-v' in argv - if verbose: - logging.basicConfig(level=logging.DEBUG) - argv.remove('-v') - assert len(argv) == 1, argv - trial_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), - '_trial') - print 'Using %s' % trial_dir - fake = FakeRepos(trial_dir, leak, True) + fake = FakeRepos() + print 'Using %s' % fake.trial_dir() try: fake.setUp() print('Fake setup, press enter to quit or Ctrl-C to keep the checkouts.') sys.stdin.readline() except KeyboardInterrupt: - fake.leak = True - finally: - fake.tearDown() + fake.SHOULD_LEAK = True return 0 diff --git a/tests/gclient_smoketest.py b/tests/gclient_smoketest.py index 1a34b335a..6cff653b4 100755 --- a/tests/gclient_smoketest.py +++ b/tests/gclient_smoketest.py @@ -12,126 +12,40 @@ This test assumes GClientSmokeBase.URL_BASE is valid. import logging import os -import pprint import re -import shutil import subprocess import sys import unittest -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 = join(os.path.dirname(UNITTEST_DIR), 'gclient') -# all tests outputs goes there. -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 = join(TRIAL_DIR, 'smoke') +from fake_repos import join, mangle_svn_tree, mangle_git_tree, write +from fake_repos import FakeReposTestBase +GCLIENT_PATH = join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), + 'gclient') +COVERAGE = False + + +class GClientSmokeBase(FakeReposTestBase): def setUp(self): - # Vaguely inspired by twisted. + FakeReposTestBase.setUp(self) # Make sure it doesn't try to auto update when testing! self.env = os.environ.copy() self.env['DEPOT_TOOLS_UPDATE'] = '0' - # Remove left overs - 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) - os.mkdir(self.root_dir) - self.svn_base = 'svn://%s/svn/' % HOST - self.git_base = 'git://%s/git/' % HOST - - def tearDown(self): - if not SHOULD_LEAK: - rmtree(self.root_dir) def gclient(self, cmd, cwd=None): if not cwd: cwd = self.root_dir - process = subprocess.Popen([GCLIENT_PATH] + cmd, cwd=cwd, env=self.env, - stdout=subprocess.PIPE, stderr=subprocess.PIPE, - shell=sys.platform.startswith('win')) + if COVERAGE: + # Don't use the wrapper script. + cmd_base = ['coverage', 'run', '-a', GCLIENT_PATH + '.py'] + else: + cmd_base = [GCLIENT_PATH] + process = subprocess.Popen(cmd_base + cmd, cwd=cwd, env=self.env, + stdout=subprocess.PIPE, stderr=subprocess.PIPE, + shell=sys.platform.startswith('win')) (stdout, stderr) = process.communicate() return (stdout, stderr, process.returncode) - def checkString(self, expected, result): - if expected != result: - # Strip the begining - while expected and result and expected[0] == result[0]: - expected = expected[1:] - result = result[1:] - # The exception trace makes it hard to read so dump it too. - if '\n' in result: - print result - self.assertEquals(expected, result) - - def check(self, expected, results): - self.checkString(expected[0], results[0]) - self.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 testHelp(self): @@ -208,6 +122,10 @@ class GClientSmoke(GClientSmokeBase): class GClientSmokeSVN(GClientSmokeBase): + def setUp(self): + GClientSmokeBase.setUp(self) + self.FAKE_REPOS.setUpSVN() + def testSync(self): # TODO(maruel): safesync. self.gclient(['config', self.svn_base + 'trunk/src/']) @@ -219,10 +137,11 @@ class GClientSmokeSVN(GClientSmokeBase): self.checkString('', results[1]) self.assertEquals(0, results[2]) tree = mangle_svn_tree( - (join('trunk', 'src'), 'src', FAKE.svn_revs[-1]), + (join('trunk', 'src'), 'src', self.FAKE_REPOS.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.FAKE_REPOS.svn_revs[1]), + (join('trunk', 'other'), join('src', 'other'), + self.FAKE_REPOS.svn_revs[2]), ) tree[join('src', 'svn_hooked1')] = 'svn_hooked1' self.assertTree(tree) @@ -240,13 +159,14 @@ class GClientSmokeSVN(GClientSmokeBase): self.checkString('', results[1]) self.assertEquals(0, results[2]) tree = mangle_svn_tree( - (join('trunk', 'src'), 'src', FAKE.svn_revs[1]), + (join('trunk', 'src'), 'src', self.FAKE_REPOS.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]), + self.FAKE_REPOS.svn_revs[2]), + (join('trunk', 'other'), join('src', 'other'), + self.FAKE_REPOS.svn_revs[2]), (join('trunk', 'third_party', 'foo'), join('src', 'third_party', 'prout'), - FAKE.svn_revs[2]), + self.FAKE_REPOS.svn_revs[2]), ) self.assertTree(tree) # Test incremental sync: delete-unversioned_trees isn't there. @@ -257,15 +177,16 @@ class GClientSmokeSVN(GClientSmokeBase): self.checkString('', results[1]) self.assertEquals(0, results[2]) tree = mangle_svn_tree( - (join('trunk', 'src'), 'src', FAKE.svn_revs[-1]), + (join('trunk', 'src'), 'src', self.FAKE_REPOS.svn_revs[-1]), (join('trunk', 'third_party', 'foo'), join('src', 'third_party', 'fpp'), - FAKE.svn_revs[2]), + self.FAKE_REPOS.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]), + self.FAKE_REPOS.svn_revs[1]), + (join('trunk', 'other'), join('src', 'other'), + self.FAKE_REPOS.svn_revs[2]), (join('trunk', 'third_party', 'foo'), join('src', 'third_party', 'prout'), - FAKE.svn_revs[2]), + self.FAKE_REPOS.svn_revs[2]), ) tree[join('src', 'svn_hooked1')] = 'svn_hooked1' self.assertTree(tree) @@ -322,10 +243,11 @@ class GClientSmokeSVN(GClientSmokeBase): self.checkString('', results[1]) self.assertEquals(0, results[2]) tree = mangle_svn_tree( - (join('trunk', 'src'), 'src', FAKE.svn_revs[-1]), + (join('trunk', 'src'), 'src', self.FAKE_REPOS.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.FAKE_REPOS.svn_revs[1]), + (join('trunk', 'other'), join('src', 'other'), + self.FAKE_REPOS.svn_revs[2]), ) tree[join('src', 'svn_hooked1')] = 'svn_hooked1' tree[join('src', 'svn_hooked2')] = 'svn_hooked2' @@ -371,13 +293,14 @@ class GClientSmokeSVN(GClientSmokeBase): self.checkString('', results[1]) self.assertEquals(0, results[2]) tree = mangle_svn_tree( - (join('trunk', 'src'), 'src', FAKE.svn_revs[1]), + (join('trunk', 'src'), 'src', self.FAKE_REPOS.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]), + self.FAKE_REPOS.svn_revs[2]), + (join('trunk', 'other'), join('src', 'other'), + self.FAKE_REPOS.svn_revs[2]), (join('trunk', 'third_party', 'prout'), join('src', 'third_party', 'prout'), - FAKE.svn_revs[2]), + self.FAKE_REPOS.svn_revs[2]), ) self.assertTree(tree) @@ -410,24 +333,6 @@ class GClientSmokeSVN(GClientSmokeBase): self.checkString('', results[1]) self.assertEquals(0, results[2]) - def testRunHooks(self): - self.gclient(['config', self.svn_base + 'trunk/src/']) - self.gclient(['sync', '--deps', 'mac']) - results = self.gclient(['runhooks']) - out = results[0].splitlines(False) - self.assertEquals(4, len(out)) - self.assertEquals(out[0], '') - self.assertTrue(re.match(r'^________ running \'.*?python -c ' - r'open\(\'src/svn_hooked1\', \'w\'\)\.write\(\'svn_hooked1\'\)\' in \'.*', - out[1])) - self.assertEquals(out[2], '') - # runhooks runs all hooks even if not matching by design. - self.assertTrue(re.match(r'^________ running \'.*?python -c ' - r'open\(\'src/svn_hooked2\', \'w\'\)\.write\(\'svn_hooked2\'\)\' in \'.*', - out[3])) - self.checkString('', results[1]) - self.assertEquals(0, results[2]) - def testRunHooksDepsOs(self): self.gclient(['config', self.svn_base + 'trunk/src/']) self.gclient(['sync', '--deps', 'mac', '--revision', 'src@1']) @@ -447,6 +352,10 @@ class GClientSmokeSVN(GClientSmokeBase): class GClientSmokeGIT(GClientSmokeBase): + def setUp(self): + GClientSmokeBase.setUp(self) + self.FAKE_REPOS.setUpGIT() + def testSync(self): # TODO(maruel): safesync. self.gclient(['config', self.git_base + 'repo_1', '--name', 'src']) @@ -459,9 +368,10 @@ class GClientSmokeGIT(GClientSmokeBase): 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]), + ('src', self.FAKE_REPOS.git_hashes['repo_1'][1][1]), + (join('src', 'repo2'), self.FAKE_REPOS.git_hashes['repo_2'][0][1]), + (join('src', 'repo2', 'repo_renamed'), + self.FAKE_REPOS.git_hashes['repo_3'][1][1]), ) tree[join('src', 'git_hooked1')] = 'git_hooked1' tree[join('src', 'git_hooked2')] = 'git_hooked2' @@ -473,7 +383,7 @@ class GClientSmokeGIT(GClientSmokeBase): # Test incremental versioned sync: sync backward. results = self.gclient(['sync', '--revision', - 'src@' + FAKE.git_hashes['repo_1'][0][0], + 'src@' + self.FAKE_REPOS.git_hashes['repo_1'][0][0], '--deps', 'mac', '--delete_unversioned_trees']) logging.debug(results[0]) out = results[0].splitlines(False) @@ -481,10 +391,11 @@ class GClientSmokeGIT(GClientSmokeBase): self.checkString('', 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]), + ('src', self.FAKE_REPOS.git_hashes['repo_1'][0][1]), + (join('src', 'repo2'), self.FAKE_REPOS.git_hashes['repo_2'][1][1]), + (join('src', 'repo2', 'repo3'), + self.FAKE_REPOS.git_hashes['repo_3'][1][1]), + (join('src', 'repo4'), self.FAKE_REPOS.git_hashes['repo_4'][1][1]), ) tree[join('src', 'git_hooked2')] = 'git_hooked2' self.assertTree(tree) @@ -496,11 +407,13 @@ class GClientSmokeGIT(GClientSmokeBase): self.checkString('', 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]), + ('src', self.FAKE_REPOS.git_hashes['repo_1'][1][1]), + (join('src', 'repo2'), self.FAKE_REPOS.git_hashes['repo_2'][1][1]), + (join('src', 'repo2', 'repo3'), + self.FAKE_REPOS.git_hashes['repo_3'][1][1]), + (join('src', 'repo2', 'repo_renamed'), + self.FAKE_REPOS.git_hashes['repo_3'][1][1]), + (join('src', 'repo4'), self.FAKE_REPOS.git_hashes['repo_4'][1][1]), ) tree[join('src', 'git_hooked1')] = 'git_hooked1' tree[join('src', 'git_hooked2')] = 'git_hooked2' @@ -528,9 +441,10 @@ class GClientSmokeGIT(GClientSmokeBase): self.checkString('', 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]), + ('src', self.FAKE_REPOS.git_hashes['repo_1'][1][1]), + (join('src', 'repo2'), self.FAKE_REPOS.git_hashes['repo_2'][0][1]), + (join('src', 'repo2', 'repo_renamed'), + self.FAKE_REPOS.git_hashes['repo_3'][1][1]), ) # TODO(maruel): http://crosbug.com/3583 This file should have been removed. tree[join('src', 'repo2', 'hi')] = 'Hey!' @@ -573,9 +487,9 @@ class GClientSmokeGIT(GClientSmokeBase): 'src/repo2/repo_renamed: %(base)srepo_3@%(hash3)s\n' % { 'base': self.git_base, - 'hash1': FAKE.git_hashes['repo_1'][1][0], - 'hash2': FAKE.git_hashes['repo_2'][0][0], - 'hash3': FAKE.git_hashes['repo_3'][1][0], + 'hash1': self.FAKE_REPOS.git_hashes['repo_1'][1][0], + 'hash2': self.FAKE_REPOS.git_hashes['repo_2'][0][0], + 'hash3': self.FAKE_REPOS.git_hashes['repo_3'][1][0], }) self.check((out, '', 0), results) @@ -646,14 +560,12 @@ class GClientSmokeBoth(GClientSmokeBase): if __name__ == '__main__': - 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() - unittest.main() - finally: - FAKE.tearDown() + if '-c' in sys.argv: + COVERAGE = True + sys.argv.remove('-c') + if os.path.exists('.coverage'): + os.remove('.coverage') + os.environ['COVERAGE_FILE'] = os.path.join( + os.path.dirname(os.path.dirname(os.path.abspath(__file__))), + '.coverage') + unittest.main()