Commits

Patrick Mézard  committed 04729f3

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.

  • Participants
  • Parent commits 39d45f2

Comments (0)

Files changed (12)

File tests/test_externals.py

 
 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',
         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', """\

File tests/test_fetch_branches.py

 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)
         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
         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
         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()))
 
     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')
 
     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')
 
     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())
 
         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)
 
     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'])
 
     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']

File tests/test_fetch_command.py

 
 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()),
         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],

File tests/test_fetch_exec.py

 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)
         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')

File tests/test_fetch_symlinks.py

 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: {

File tests/test_pull.py

     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)
         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)
         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'})
         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()))

File tests/test_push_command.py

 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

File tests/test_push_eol.py

 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 = [

File tests/test_push_renames.py

 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

File tests/test_tags.py

 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)

File tests/test_util.py

     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):
         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'''

File tests/test_utility_commands.py

 
     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')