comparison tests/test_push_renames.py @ 84:01e747937d35

test_util: add commitchanges() to TestBase
author Patrick Mezard <pmezard@gmail.com>
date Fri, 14 Nov 2008 16:18:24 -0600
parents 71de43e9f614
children 9b5e528f67f8
comparison
equal deleted inserted replaced
83:6c9b7cf1c5aa 84:01e747937d35
1 import os
2 import sys 1 import sys
3 import tempfile
4 import unittest 2 import unittest
5 3
6 from mercurial import context
7 from mercurial import commands
8 from mercurial import hg
9 from mercurial import node
10 from mercurial import ui
11 from mercurial import revlog
12
13 import fetch_command
14 import push_cmd
15 import test_util 4 import test_util
16 5
17 class TestPushRenames(test_util.TestBase): 6 class TestPushRenames(test_util.TestBase):
18 def setUp(self): 7 def setUp(self):
19 test_util.TestBase.setUp(self) 8 test_util.TestBase.setUp(self)
20 test_util.load_fixture_and_fetch('pushrenames.svndump', 9 test_util.load_fixture_and_fetch('pushrenames.svndump',
21 self.repo_path, 10 self.repo_path,
22 self.wc_path, 11 self.wc_path,
23 True) 12 True)
24
25 def _commitchanges(self, repo, changes):
26 parentctx = repo['tip']
27
28 changed, removed = [], []
29 for source, dest, newdata in changes:
30 if dest is None:
31 removed.append(source)
32 else:
33 changed.append(dest)
34
35 def filectxfn(repo, memctx, path):
36 if path in removed:
37 raise IOError()
38 entry = [e for e in changes if path == e[1]][0]
39 source, dest, newdata = entry
40 if newdata is None:
41 newdata = parentctx[source].data()
42 copied = None
43 if source != dest:
44 copied = source
45 return context.memfilectx(path=dest,
46 data=newdata,
47 islink=False,
48 isexec=False,
49 copied=copied)
50
51 ctx = context.memctx(repo,
52 (parentctx.node(), node.nullid),
53 'automated test',
54 changed + removed,
55 filectxfn,
56 'an_author',
57 '2008-10-07 20:59:48 -0500')
58 return repo.commitctx(ctx)
59 13
60 def _debug_print_copies(self, ctx): 14 def _debug_print_copies(self, ctx):
61 w = sys.stderr.write 15 w = sys.stderr.write
62 for f in ctx.files(): 16 for f in ctx.files():
63 if f not in ctx: 17 if f not in ctx:
78 self.assertEqual(data, ctx[dest].data()) 32 self.assertEqual(data, ctx[dest].data())
79 if dest != source: 33 if dest != source:
80 copy = ctx[dest].renamed() 34 copy = ctx[dest].renamed()
81 self.assertEqual(copy[0], source) 35 self.assertEqual(copy[0], source)
82 36
83 def test_push_renames(self, commit=True): 37 def test_push_renames(self):
84 repo = self.repo 38 repo = self.repo
85 39
86 changes = [ 40 changes = [
87 # Regular copy of a single file 41 # Regular copy of a single file
88 ('a', 'a2', None), 42 ('a', 'a2', None),
100 # Double copy and removal (aka copy and move) 54 # Double copy and removal (aka copy and move)
101 ('e', 'e2', 'e\ne2\n'), 55 ('e', 'e2', 'e\ne2\n'),
102 ('e', 'e3', 'e\ne3\n'), 56 ('e', 'e3', 'e\ne3\n'),
103 ('e', None, None), 57 ('e', None, None),
104 ] 58 ]
105 self._commitchanges(repo, changes) 59 self.commitchanges(changes)
106 60 self.pushrevisions()
107 hg.update(repo, repo['tip'].node())
108 push_cmd.push_revisions_to_subversion(
109 ui.ui(), repo=self.repo, hg_repo_path=self.wc_path,
110 svn_url=test_util.fileurl(self.repo_path))
111 tip = self.repo['tip'] 61 tip = self.repo['tip']
112 # self._debug_print_copies(tip) 62 # self._debug_print_copies(tip)
113 self.assertchanges(changes, tip) 63 self.assertchanges(changes, tip)
114 64
115 def suite(): 65 def suite():