view tests/comprehensive/test_verify_and_startrev.py @ 933:a9f315eae67c

push: use native rebase instead of our rebase wrapper Our rebase wrapper doesn't quite do the right thing with repect to a just-pushed revision. In particular, it will try to rebase the just-pushed revision on top of the version of that revision we just pulled down from svn. This will sometimes result in a local revision with an identical commit message as the revision from svn, but no file changes. This changes the rebase portion of the push command to instead use the native rebase with a revset that excludes the revision we just pushed to svn from the set to be rebased. It also moves to a single strip operation that removes all of the revisions based on a pre-push or partially pushed revision. This moves to a separate rebase and strip operation since we now need to strip revisions we are not rebasing.
author David Schleimer <dschleimer@fb.com>
date Mon, 24 Sep 2012 10:18:28 -0700
parents 7f90bb48c9de
children f9014e28721b
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',
])

_skipstandard = set([
    'subdir_is_file_prefix.svndump',
    'correct.svndump',
    'corrupt.svndump',
])

def _do_case(self, name, stupid, layout):
    subdir = test_util.subdir.get(name, '')
    repo, svnpath = self.load_and_fetch(name, subdir=subdir, stupid=stupid,
                                        layout=layout)
    assert len(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, stupid=stupid,
                                 layout='single', startrev='HEAD')

        self.assertEqual(len(shallowrepo), 1,
                         "shallow clone should have just one revision, not %d"
                         % len(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, stupid, layout):
    m = lambda self: self._do_case(case, stupid, layout)
    m.__name__ = name
    bits = case, stupid and 'stupid' or 'real', layout
    m.__doc__ = 'Test verify on %s with %s replay. (%s)' % bits
    return m

attrs = {'_do_case': _do_case}
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, False, 'standard')
        name = bname + '_stupid'
        attrs[name] = buildmethod(case, name, True, 'standard')
    name = bname + '_single'
    attrs[name] = buildmethod(case, name, False, 'single')
    # Disabled because the "stupid and real are the same" tests
    # verify this plus even more.
    # name = bname + '_single_stupid'
    # attrs[name] = buildmethod(case, name, True, 'single')

VerifyTests = type('VerifyTests', (test_util.TestBase,), attrs)

def suite():
    all_tests = [unittest.TestLoader().loadTestsFromTestCase(VerifyTests)]
    return unittest.TestSuite(all_tests)