Mercurial > hgsubversion
changeset 84:01e747937d35
test_util: add commitchanges() to TestBase
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Fri, 14 Nov 2008 16:18:24 -0600 |
parents | 6c9b7cf1c5aa |
children | 05a0c4f6060f |
files | tests/test_push_dirs.py tests/test_push_renames.py tests/test_util.py |
diffstat | 3 files changed, 59 insertions(+), 101 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/test_push_dirs.py +++ b/tests/test_push_dirs.py @@ -1,11 +1,5 @@ -import os -import sys import unittest -from mercurial import context -from mercurial import hg -from mercurial import node - import test_util class TestPushDirectories(test_util.TestBase): @@ -15,45 +9,7 @@ class TestPushDirectories(test_util.Test self.repo_path, self.wc_path) - def _commitchanges(self, repo, changes): - parentctx = repo['tip'] - - changed, removed = [], [] - for source, dest, newdata in changes: - if dest is None: - removed.append(source) - else: - changed.append(dest) - - def filectxfn(repo, memctx, path): - if path in removed: - raise IOError() - entry = [e for e in changes if path == e[1]][0] - source, dest, newdata = entry - if newdata is None: - newdata = parentctx[source].data() - copied = None - if source != dest: - copied = source - return context.memfilectx(path=dest, - data=newdata, - islink=False, - isexec=False, - copied=copied) - - ctx = context.memctx(repo, - (parentctx.node(), node.nullid), - 'automated test', - changed + removed, - filectxfn, - 'an_author', - '2008-10-07 20:59:48 -0500') - nodeid = repo.commitctx(ctx) - repo = self.repo - hg.update(repo, nodeid) - return nodeid - - def test_push_dirs(self, commit=True): + def test_push_dirs(self): changes = [ # Single file in single directory ('d1/a', 'd1/a', 'a\n'), @@ -64,7 +20,7 @@ class TestPushDirectories(test_util.Test ('d31/d32/d33/d34/a', 'd31/d32/d33/d34/a', 'a\n'), ('d31/d32/a', 'd31/d32/a', 'a\n'), ] - self._commitchanges(self.repo, changes) + self.commitchanges(changes) self.pushrevisions() self.assertEqual(self.svnls('trunk'), ['d1', 'd1/a', 'd2', 'd2/a', 'd2/b', 'd31', @@ -79,7 +35,7 @@ class TestPushDirectories(test_util.Test # Removing this file should remove one empty parent dir too ('d31/d32/d33/d34/a', None, None), ] - self._commitchanges(self.repo, changes) + self.commitchanges(changes) self.pushrevisions() self.assertEqual(self.svnls('trunk'), ['d2', 'd2/b', 'd31', 'd31/d32', 'd31/d32/a', 'd31/d32/d33'])
--- a/tests/test_push_renames.py +++ b/tests/test_push_renames.py @@ -1,17 +1,6 @@ -import os import sys -import tempfile import unittest -from mercurial import context -from mercurial import commands -from mercurial import hg -from mercurial import node -from mercurial import ui -from mercurial import revlog - -import fetch_command -import push_cmd import test_util class TestPushRenames(test_util.TestBase): @@ -22,41 +11,6 @@ class TestPushRenames(test_util.TestBase self.wc_path, True) - def _commitchanges(self, repo, changes): - parentctx = repo['tip'] - - changed, removed = [], [] - for source, dest, newdata in changes: - if dest is None: - removed.append(source) - else: - changed.append(dest) - - def filectxfn(repo, memctx, path): - if path in removed: - raise IOError() - entry = [e for e in changes if path == e[1]][0] - source, dest, newdata = entry - if newdata is None: - newdata = parentctx[source].data() - copied = None - if source != dest: - copied = source - return context.memfilectx(path=dest, - data=newdata, - islink=False, - isexec=False, - copied=copied) - - ctx = context.memctx(repo, - (parentctx.node(), node.nullid), - 'automated test', - changed + removed, - filectxfn, - 'an_author', - '2008-10-07 20:59:48 -0500') - return repo.commitctx(ctx) - def _debug_print_copies(self, ctx): w = sys.stderr.write for f in ctx.files(): @@ -80,7 +34,7 @@ class TestPushRenames(test_util.TestBase copy = ctx[dest].renamed() self.assertEqual(copy[0], source) - def test_push_renames(self, commit=True): + def test_push_renames(self): repo = self.repo changes = [ @@ -102,12 +56,8 @@ class TestPushRenames(test_util.TestBase ('e', 'e3', 'e\ne3\n'), ('e', None, None), ] - self._commitchanges(repo, changes) - - hg.update(repo, repo['tip'].node()) - push_cmd.push_revisions_to_subversion( - ui.ui(), repo=self.repo, hg_repo_path=self.wc_path, - svn_url=test_util.fileurl(self.repo_path)) + self.commitchanges(changes) + self.pushrevisions() tip = self.repo['tip'] # self._debug_print_copies(tip) self.assertchanges(changes, tip)
--- a/tests/test_util.py +++ b/tests/test_util.py @@ -7,8 +7,10 @@ import tempfile import unittest import urllib -from mercurial import ui +from mercurial import context from mercurial import hg +from mercurial import node +from mercurial import ui import fetch_command import push_cmd @@ -95,3 +97,53 @@ class TestBase(unittest.TestCase): entries = [e.strip('/') for e in stdout.splitlines()] entries.sort() return entries + + def commitchanges(self, changes): + """Commit changes to mercurial directory + + 'changes' is a sequence of tuples (source, dest, data). It can look + like: + - (source, source, data) to set source content to data + - (source, dest, None) to set dest content to source one, and mark it as + copied from source. + - (source, dest, data) to set dest content to data, and mark it as copied + from source. + - (source, None, None) to remove source. + """ + repo = self.repo + parentctx = repo['tip'] + + changed, removed = [], [] + for source, dest, newdata in changes: + if dest is None: + removed.append(source) + else: + changed.append(dest) + + def filectxfn(repo, memctx, path): + if path in removed: + raise IOError() + entry = [e for e in changes if path == e[1]][0] + source, dest, newdata = entry + if newdata is None: + newdata = parentctx[source].data() + copied = None + if source != dest: + copied = source + return context.memfilectx(path=dest, + data=newdata, + islink=False, + isexec=False, + copied=copied) + + ctx = context.memctx(repo, + (parentctx.node(), node.nullid), + 'automated test', + changed + removed, + filectxfn, + 'an_author', + '2008-10-07 20:59:48 -0500') + nodeid = repo.commitctx(ctx) + repo = self.repo + hg.update(repo, nodeid) + return nodeid