Mercurial > hgsubversion
view tests/comprehensive/test_verify_and_startrev.py @ 1101:4a92eb1484ba
layouts: fix crash when importing hgsubversion itself (issue #402)
Mercurial extensions are a bit weird: they aren't normally in
sys.path, so you can't assume that "import hgsubversion" works.
Luckily, Mercurial sneaks a little treat into sys.modules so that
"import hgext_hgsubversion" does work. In fact, to get things working
*as a Mercurial extension*, all that's needed is that trivial change
to two import lines, in layouts/detect.py and layouts/standard.py.
Unfortunately, hgsubversion is also imported as a Python module, in
its own test suite. In that context, there is no "hgext_" trick --
unless we do it in ourselves, which I've done in TestBase.setUp().
That would work fine ... except that test_util imports from
hgsubversion, which ends up importing hgsubversion.layouts.{detect,standard},
which want the "hgext_" trick to work. But it hasn't been done yet
when we're still importing; it doesn't happen until setUp() runs.
So make those two imports happen late, in the functions that need them.
Incidentally, this is only necessary to support Mercurial <= 2.7.
Mercurial got a bit smarter in 2.8:
http://selenic.com/repo/hg/rev/621a26eb3a99
author | Greg Ward <greg@gerg.ca> |
---|---|
date | Thu, 02 Jan 2014 21:53:39 -0500 |
parents | cd0d14e25757 |
children | ff4e102932ed |
line wrap: on
line source
import os import pickle import sys import unittest # wrapped in a try/except because of weirdness in how # run.py works as compared to nose. try: import test_util except ImportError: sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) import test_util from mercurial import hg from mercurial import ui from hgsubversion import verify # these fixtures contain no files at HEAD and would result in empty clones _skipshallow = set([ 'binaryfiles.svndump', 'binaryfiles-broken.svndump', 'emptyrepo.svndump', 'correct.svndump', 'corrupt.svndump', ]) _skipall = set([ 'project_root_not_repo_root.svndump', 'movetotrunk.svndump', ]) _skipstandard = set([ 'subdir_is_file_prefix.svndump', 'correct.svndump', 'corrupt.svndump', 'emptyrepo2.svndump', ]) def _do_case(self, name, layout): subdir = test_util.subdir.get(name, '') config = {} for branch, path in test_util.custom.get(name, {}).iteritems(): config['hgsubversionbranch.%s' % branch] = path repo, svnpath = self.load_and_fetch(name, subdir=subdir, layout=layout, config=config) assert test_util.repolen(self.repo) > 0 for i in repo: ctx = repo[i] self.assertEqual(verify.verify(repo.ui, repo, rev=ctx.node(), stupid=True), 0) self.assertEqual(verify.verify(repo.ui, repo, rev=ctx.node(), stupid=False), 0) # check a startrev clone if layout == 'single' and name not in _skipshallow: self.wc_path += '_shallow' shallowrepo = self.fetch(svnpath, subdir=subdir, layout='single', startrev='HEAD') self.assertEqual(test_util.repolen(shallowrepo), 1, "shallow clone should have just one revision, not %d" % test_util.repolen(shallowrepo)) fulltip = repo['tip'] shallowtip = shallowrepo['tip'] repo.ui.pushbuffer() self.assertEqual(0, verify.verify(repo.ui, shallowrepo, rev=shallowtip.node(), stupid=True)) self.assertEqual(0, verify.verify(repo.ui, shallowrepo, rev=shallowtip.node(), stupid=False)) stupidui = ui.ui(repo.ui) stupidui.config('hgsubversion', 'stupid', True) self.assertEqual(verify.verify(stupidui, repo, rev=ctx.node(), stupid=True), 0) self.assertEqual(verify.verify(stupidui, repo, rev=ctx.node(), stupid=False), 0) # viewing diff's of lists of files is easier on the eyes self.assertMultiLineEqual('\n'.join(fulltip), '\n'.join(shallowtip), repo.ui.popbuffer()) for f in fulltip: self.assertMultiLineEqual(fulltip[f].data(), shallowtip[f].data()) def buildmethod(case, name, layout): m = lambda self: self._do_case(case, layout) m.__name__ = name m.__doc__ = 'Test verify on %s (%s)' % (case, layout) return m attrs = {'_do_case': _do_case, 'stupid_mode_tests': True} fixtures = [f for f in os.listdir(test_util.FIXTURES) if f.endswith('.svndump')] for case in fixtures: if case in _skipall: continue bname = 'test_' + case[:-len('.svndump')] if case not in _skipstandard: attrs[bname] = buildmethod(case, bname, 'standard') attrs[bname + '_single'] = buildmethod(case, bname + '_single', 'single') if case in test_util.custom: attrs[bname + '_custom'] = buildmethod(case, bname + '_custom', 'custom') VerifyTests = type('VerifyTests', (test_util.TestBase,), attrs)