test_util: merge load_fixture_and_fetch() into TestBase method

The middle-term goal is to make TestBase repo_path and wc_path private, so they
can be changed for every load call. This is not required to use nosetests
multiprocess facility as the fixtures create temporary directories but it makes
things much clearer and avoid weird cases where a repository was loaded several
times at the same location in a single test (cf test_startrev). That way we
will be more confident the tests can be parallelized.

The long term goal is to make hgsubversion compatible with nosetests
--processes option.
This commit is contained in:
Patrick Mezard 2012-04-19 18:29:25 +02:00
parent 455e06fa63
commit 76b3efe6d9
12 changed files with 64 additions and 100 deletions

View File

@ -278,9 +278,7 @@ d3/ext3 = [hgsubversion] d3:^/trunk/common/ext ext3
class TestPushExternals(test_util.TestBase):
def test_push_externals(self, stupid=False):
test_util.load_fixture_and_fetch('pushexternals.svndump',
self.repo_path,
self.wc_path)
repo = self._load_fixture_and_fetch('pushexternals.svndump')
# Add a new reference on an existing and non-existing directory
changes = [
('.hgsvnexternals', '.hgsvnexternals',
@ -331,10 +329,8 @@ class TestPushExternals(test_util.TestBase):
if subrepo is None:
return
test_util.load_fixture_and_fetch('pushexternals.svndump',
self.repo_path,
self.wc_path,
externals='subrepos')
self._load_fixture_and_fetch('pushexternals.svndump',
externals='subrepos')
# Add a new reference on an existing and non-existing directory
changes = [
('.hgsub', '.hgsub', """\

View File

@ -7,12 +7,6 @@ from mercurial import node
from mercurial import util as hgutil
class TestFetchBranches(test_util.TestBase):
def _load_fixture_and_fetch(self, fixture_name, stupid, noupdate=True,
subdir=''):
return test_util.load_fixture_and_fetch(fixture_name, self.repo_path,
self.wc_path, stupid=stupid,
noupdate=noupdate, subdir=subdir)
def _load_fixture_and_fetch_with_anchor(self, fixture_name, anchor):
test_util.load_svndump_fixture(self.repo_path, fixture_name)
source = '%s#%s' % (test_util.fileurl(self.repo_path), anchor)
@ -31,7 +25,8 @@ class TestFetchBranches(test_util.TestBase):
return self.branches(repo)[0]
def test_rename_branch_parent(self, stupid=False):
repo = self._load_fixture_and_fetch('rename_branch_parent_dir.svndump', stupid)
repo = self._load_fixture_and_fetch('rename_branch_parent_dir.svndump',
stupid=stupid)
heads = [repo[n] for n in repo.heads()]
heads = dict([(ctx.branch(), ctx) for ctx in heads])
# Let these tests disabled yet as the fix is not obvious
@ -41,7 +36,8 @@ class TestFetchBranches(test_util.TestBase):
self.test_rename_branch_parent(stupid=True)
def test_unrelatedbranch(self, stupid=False):
repo = self._load_fixture_and_fetch('unrelatedbranch.svndump', stupid)
repo = self._load_fixture_and_fetch('unrelatedbranch.svndump',
stupid=stupid)
heads = [repo[n] for n in repo.heads()]
heads = dict([(ctx.branch(), ctx) for ctx in heads])
# Let these tests disabled yet as the fix is not obvious
@ -52,7 +48,8 @@ class TestFetchBranches(test_util.TestBase):
self.test_unrelatedbranch(True)
def test_unorderedbranch(self, stupid=False):
repo = self._load_fixture_and_fetch('unorderedbranch.svndump', stupid)
repo = self._load_fixture_and_fetch('unorderedbranch.svndump',
stupid=stupid)
r = repo['branch']
self.assertEqual(0, r.parents()[0].rev())
self.assertEqual(['a', 'c', 'z'], sorted(r.manifest()))
@ -62,7 +59,7 @@ class TestFetchBranches(test_util.TestBase):
def test_renamed_branch_to_trunk(self, stupid=False):
repo = self._load_fixture_and_fetch('branch_rename_to_trunk.svndump',
stupid)
stupid=stupid)
self.assertEqual(repo['default'].parents()[0].branch(), 'dev_branch')
self.assert_('iota' in repo['default'])
self.assertEqual(repo['old_trunk'].parents()[0].branch(), 'default')
@ -75,14 +72,15 @@ class TestFetchBranches(test_util.TestBase):
def test_replace_trunk_with_branch(self, stupid=False):
repo = self._load_fixture_and_fetch('replace_trunk_with_branch.svndump',
stupid)
stupid=stupid)
self.assertEqual(repo['default'].parents()[0].branch(), 'test')
self.assertEqual(repo['tip'].branch(), 'default')
self.assertEqual(repo['tip'].extra().get('close'), '1')
self.assertEqual(self.openbranches(repo), ['default'])
def test_copybeforeclose(self, stupid=False):
repo = self._load_fixture_and_fetch('copybeforeclose.svndump', stupid)
repo = self._load_fixture_and_fetch('copybeforeclose.svndump',
stupid=stupid)
self.assertEqual(repo['tip'].branch(), 'test')
self.assertEqual(repo['test'].extra().get('close'), '1')
self.assertEqual(repo['test']['b'].data(), 'a\n')
@ -95,13 +93,13 @@ class TestFetchBranches(test_util.TestBase):
def test_branch_create_with_dir_delete_works(self, stupid=False):
repo = self._load_fixture_and_fetch('branch_create_with_dir_delete.svndump',
stupid)
stupid=stupid)
self.assertEqual(repo['tip'].manifest().keys(),
['alpha', 'beta', 'iota', 'gamma', ])
def test_branch_tip_update_to_default(self, stupid=False):
repo = self._load_fixture_and_fetch('unorderedbranch.svndump',
stupid, noupdate=False)
stupid=stupid, noupdate=False)
self.assertEqual(repo[None].branch(), 'default')
self.assertTrue('tip' not in repo[None].tags())
@ -117,7 +115,8 @@ class TestFetchBranches(test_util.TestBase):
self.assertTrue('c' not in repo.branchtags())
def test_branches_weird_moves(self, stupid=False):
repo = self._load_fixture_and_fetch('renamedproject.svndump', stupid,
repo = self._load_fixture_and_fetch('renamedproject.svndump',
stupid=stupid,
subdir='project')
heads = [repo[n] for n in repo.heads()]
heads = dict((ctx.branch(), ctx) for ctx in heads)
@ -131,7 +130,7 @@ class TestFetchBranches(test_util.TestBase):
def test_branch_delete_parent_dir(self, stupid=False):
repo = self._load_fixture_and_fetch('branch_delete_parent_dir.svndump',
stupid)
stupid=stupid)
openb, closedb = self.branches(repo)
self.assertEqual(openb, [])
self.assertEqual(closedb, ['dev_branch'])
@ -139,7 +138,7 @@ class TestFetchBranches(test_util.TestBase):
def test_replace_branch_with_branch(self, stupid=False):
repo = self._load_fixture_and_fetch('replace_branch_with_branch.svndump',
stupid)
stupid=stupid)
self.assertEqual(7, len(repo))
# tip is former topological branch1 being closed
ctx = repo['tip']

View File

@ -189,10 +189,7 @@ class TestBasicRepoLayout(test_util.TestBase):
class TestStupidPull(test_util.TestBase):
def test_stupid(self):
repo = test_util.load_fixture_and_fetch('two_heads.svndump',
self.repo_path,
self.wc_path,
True)
repo = self._load_fixture_and_fetch('two_heads.svndump', stupid=True)
self.assertEqual(node.hex(repo[0].node()),
'434ed487136c1b47c1e8f952edb4dc5a8e6328df')
self.assertEqual(node.hex(repo['tip'].node()),
@ -210,12 +207,9 @@ class TestStupidPull(test_util.TestBase):
self.assertEqual(len(repo.heads()), 2)
def test_oldest_not_trunk_and_tag_vendor_branch(self):
repo = test_util.load_fixture_and_fetch(
repo = self._load_fixture_and_fetch(
'tagged_vendor_and_oldest_not_trunk.svndump',
self.repo_path,
self.wc_path,
True)
repo = hg.repository(ui.ui(), self.wc_path)
stupid=True)
self.assertEqual(node.hex(repo['oldest'].node()),
'926671740dec045077ab20f110c1595f935334fa')
self.assertEqual(repo['tip'].parents()[0].parents()[0],

View File

@ -5,16 +5,12 @@ import unittest
from mercurial import node
class TestFetchExec(test_util.TestBase):
def _load_fixture_and_fetch(self, fixture_name, stupid):
return test_util.load_fixture_and_fetch(fixture_name, self.repo_path,
self.wc_path, stupid=stupid)
def assertexec(self, ctx, files, isexec=True):
for f in files:
self.assertEqual(isexec, 'x' in ctx[f].flags())
def test_exec(self, stupid=False):
repo = self._load_fixture_and_fetch('executebit.svndump', stupid)
repo = self._load_fixture_and_fetch('executebit.svndump', stupid=stupid)
self.assertexec(repo[0], ['text1', 'binary1', 'empty1'], True)
self.assertexec(repo[0], ['text2', 'binary2', 'empty2'], False)
self.assertexec(repo[1], ['text1', 'binary1', 'empty1'], False)
@ -24,7 +20,8 @@ class TestFetchExec(test_util.TestBase):
self.test_exec(True)
def test_empty_prop_val_executable(self, stupid=False):
repo = self._load_fixture_and_fetch('executable_file_empty_prop.svndump', stupid)
repo = self._load_fixture_and_fetch('executable_file_empty_prop.svndump',
stupid=stupid)
self.assertEqual(node.hex(repo['tip'].node()),
'08e6b380bf291b361a418203a1cb9427213cd1fd')
self.assertEqual(repo['tip']['foo'].flags(), 'x')

View File

@ -3,12 +3,8 @@ import test_util
import unittest
class TestFetchSymlinks(test_util.TestBase):
def _load_fixture_and_fetch(self, fixture_name, stupid):
return test_util.load_fixture_and_fetch(fixture_name, self.repo_path,
self.wc_path, stupid=stupid)
def test_symlinks(self, stupid=False):
repo = self._load_fixture_and_fetch('symlinks.svndump', stupid)
repo = self._load_fixture_and_fetch('symlinks.svndump', stupid=stupid)
# Check symlinks throughout history
links = {
0: {

View File

@ -11,19 +11,18 @@ class TestPull(test_util.TestBase):
def setUp(self):
super(TestPull, self).setUp()
def _load_fixture_and_fetch(self, fixture_name):
return test_util.load_fixture_and_fetch(fixture_name, self.repo_path,
self.wc_path, stupid=False,
noupdate=False)
def _loadupdate(self, fixture_name):
return self._load_fixture_and_fetch(fixture_name, stupid=False,
noupdate=False)
def test_nochanges(self):
self._load_fixture_and_fetch('single_rev.svndump')
self._loadupdate('single_rev.svndump')
state = self.repo.parents()
commands.pull(self.repo.ui, self.repo)
self.assertEqual(state, self.repo.parents())
def test_onerevision_noupdate(self):
repo = self._load_fixture_and_fetch('single_rev.svndump')
repo = self._loadupdate('single_rev.svndump')
state = repo.parents()
self._add_svn_rev({'trunk/alpha': 'Changed'})
commands.pull(self.repo.ui, repo)
@ -31,7 +30,7 @@ class TestPull(test_util.TestBase):
self.assertTrue('tip' not in repo[None].tags())
def test_onerevision_doupdate(self):
repo = self._load_fixture_and_fetch('single_rev.svndump')
repo = self._loadupdate('single_rev.svndump')
state = repo.parents()
self._add_svn_rev({'trunk/alpha': 'Changed'})
commands.pull(self.repo.ui, repo, update=True)
@ -39,7 +38,7 @@ class TestPull(test_util.TestBase):
self.assertTrue('tip' in repo[None].tags())
def test_onerevision_divergent(self):
repo = self._load_fixture_and_fetch('single_rev.svndump')
repo = self._loadupdate('single_rev.svndump')
self.commitchanges((('alpha', 'alpha', 'Changed another way'),))
state = repo.parents()
self._add_svn_rev({'trunk/alpha': 'Changed one way'})
@ -53,7 +52,7 @@ class TestPull(test_util.TestBase):
self.assertEqual(len(repo.heads()), 2)
def test_tag_repull_doesnt_happen(self):
repo = self._load_fixture_and_fetch('branchtagcollision.svndump')
repo = self._loadupdate('branchtagcollision.svndump')
oldheads = map(node.hex, repo.heads())
commands.pull(repo.ui, repo)
self.assertEqual(oldheads, map(node.hex, repo.heads()))

View File

@ -23,9 +23,7 @@ import time
class PushTests(test_util.TestBase):
def setUp(self):
test_util.TestBase.setUp(self)
test_util.load_fixture_and_fetch('simple_branch.svndump',
self.repo_path,
self.wc_path)
self._load_fixture_and_fetch('simple_branch.svndump')
def test_cant_push_empty_ctx(self):
repo = self.repo

View File

@ -5,9 +5,7 @@ import unittest
class TestPushEol(test_util.TestBase):
def setUp(self):
test_util.TestBase.setUp(self)
test_util.load_fixture_and_fetch('emptyrepo.svndump',
self.repo_path,
self.wc_path)
self._load_fixture_and_fetch('emptyrepo.svndump')
def _test_push_dirs(self, stupid):
changes = [

View File

@ -6,10 +6,8 @@ import unittest
class TestPushRenames(test_util.TestBase):
def setUp(self):
test_util.TestBase.setUp(self)
test_util.load_fixture_and_fetch('pushrenames.svndump',
self.repo_path,
self.wc_path,
True)
self._load_fixture_and_fetch('pushrenames.svndump',
stupid=True)
def _debug_print_copies(self, ctx):
w = sys.stderr.write

View File

@ -12,10 +12,6 @@ from hgsubversion import svncommands
from hgsubversion import svnrepo
class TestTags(test_util.TestBase):
def _load_fixture_and_fetch(self, fixture_name, stupid=False):
return test_util.load_fixture_and_fetch(fixture_name, self.repo_path,
self.wc_path, stupid=stupid)
def test_tags(self, stupid=False):
repo = self._load_fixture_and_fetch('basic_tag_tests.svndump',
stupid=stupid)

View File

@ -177,31 +177,6 @@ def dispatch(cmd):
except AttributeError, e:
dispatchmod.dispatch(cmd)
def load_fixture_and_fetch(fixture_name, repo_path, wc_path, stupid=False,
subdir='', noupdate=True, layout='auto',
startrev=0, externals=None):
load_svndump_fixture(repo_path, fixture_name)
if subdir:
repo_path += '/' + subdir
cmd = [
'clone',
'--layout=%s' % layout,
'--startrev=%s' % startrev,
fileurl(repo_path),
wc_path,
]
if stupid:
cmd.append('--stupid')
if noupdate:
cmd.append('--noupdate')
if externals:
cmd[:0] = ['--config', 'hgsubversion.externals=%s' % externals]
dispatch(cmd)
return hg.repository(testui(), wc_path)
def rmtree(path):
# Read-only files cannot be removed under Windows
for root, dirs, files in os.walk(path):
@ -292,16 +267,35 @@ class TestBase(unittest.TestCase):
return testui(stupid, layout)
def _load_fixture_and_fetch(self, fixture_name, subdir=None, stupid=False,
layout='auto', startrev=0, externals=None):
layout='auto', startrev=0, externals=None,
noupdate=True):
if layout == 'single':
if subdir is None:
subdir = 'trunk'
elif subdir is None:
subdir = ''
return load_fixture_and_fetch(fixture_name, self.repo_path,
self.wc_path, subdir=subdir,
stupid=stupid, layout=layout,
startrev=startrev, externals=externals)
load_svndump_fixture(self.repo_path, fixture_name)
projectpath = self.repo_path
if subdir:
projectpath += '/' + subdir
cmd = [
'clone',
'--layout=%s' % layout,
'--startrev=%s' % startrev,
fileurl(projectpath),
self.wc_path,
]
if stupid:
cmd.append('--stupid')
if noupdate:
cmd.append('--noupdate')
if externals:
cmd[:0] = ['--config', 'hgsubversion.externals=%s' % externals]
dispatch(cmd)
return hg.repository(testui(), self.wc_path)
def _add_svn_rev(self, changes):
'''changes is a dict of filename -> contents'''

View File

@ -211,11 +211,10 @@ class UtilityTests(test_util.TestBase):
def test_genignore(self):
""" Test generation of .hgignore file. """
test_util.load_fixture_and_fetch('ignores.svndump', self.repo_path,
self.wc_path, noupdate=False)
repo = self._load_fixture_and_fetch('ignores.svndump', noupdate=False)
u = self.ui()
u.pushbuffer()
svncommands.genignore(u, self.repo, self.wc_path)
svncommands.genignore(u, repo, self.wc_path)
self.assertMultiLineEqual(open(os.path.join(self.wc_path, '.hgignore')).read(),
'.hgignore\nsyntax:glob\nblah\notherblah\nbaz/magic\n')