annotate tests/test_push_renames.py @ 80:83179a183927

test_push_command: fix test_push_existing_file_newly_execute() under Windows
author Patrick Mezard <pmezard@gmail.com>
date Fri, 14 Nov 2008 16:18:24 -0600
parents 072010a271c6
children 71de43e9f614
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
70
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
1 import os
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
2 import sys
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
3 import tempfile
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
4 import unittest
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
5
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
6 from mercurial import context
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
7 from mercurial import commands
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
8 from mercurial import hg
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
9 from mercurial import node
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
10 from mercurial import ui
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
11 from mercurial import revlog
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
12
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
13 import fetch_command
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
14 import push_cmd
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
15 import test_util
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
16
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
17 class TestPushRenames(unittest.TestCase):
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
18 def setUp(self):
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
19 self.oldwd = os.getcwd()
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
20 self.tmpdir = tempfile.mkdtemp('svnwrap_test')
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
21 self.repo_path = '%s/testrepo' % self.tmpdir
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
22 self.wc_path = '%s/testrepo_wc' % self.tmpdir
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 70
diff changeset
23 test_util.load_fixture_and_fetch('pushrenames.svndump',
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 70
diff changeset
24 self.repo_path,
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 70
diff changeset
25 self.wc_path,
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 70
diff changeset
26 True)
70
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
27
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
28 # define this as a property so that it reloads anytime we need it
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
29 @property
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
30 def repo(self):
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
31 return hg.repository(ui.ui(), self.wc_path)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
32
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
33 def tearDown(self):
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 70
diff changeset
34 test_util.rmtree(self.tmpdir)
70
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
35 os.chdir(self.oldwd)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
36
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
37 def _commitchanges(self, repo, changes):
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
38 parentctx = repo['tip']
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
39
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
40 changed, removed = [], []
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
41 for source, dest, newdata in changes:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
42 if dest is None:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
43 removed.append(source)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
44 else:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
45 changed.append(dest)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
46
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
47 def filectxfn(repo, memctx, path):
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
48 if path in removed:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
49 raise IOError()
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
50 entry = [e for e in changes if path == e[1]][0]
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
51 source, dest, newdata = entry
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
52 if newdata is None:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
53 newdata = parentctx[source].data()
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
54 copied = None
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
55 if source != dest:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
56 copied = source
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
57 return context.memfilectx(path=dest,
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
58 data=newdata,
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
59 islink=False,
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
60 isexec=False,
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
61 copied=copied)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
62
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
63 ctx = context.memctx(repo,
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
64 (parentctx.node(), node.nullid),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
65 'automated test',
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
66 changed + removed,
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
67 filectxfn,
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
68 'an_author',
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
69 '2008-10-07 20:59:48 -0500')
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
70 return repo.commitctx(ctx)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
71
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
72 def _debug_print_copies(self, ctx):
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
73 w = sys.stderr.write
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
74 for f in ctx.files():
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
75 if f not in ctx:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
76 w('R %s\n' % f)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
77 else:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
78 w('U %s %r\n' % (f, ctx[f].data()))
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
79 if ctx[f].renamed():
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
80 w('%s copied from %s\n' % (f, ctx[f].renamed()[0]))
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
81
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
82 def assertchanges(self, changes, ctx):
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
83 for source, dest, data in changes:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
84 if dest is None:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
85 self.assertTrue(source not in ctx)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
86 else:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
87 self.assertTrue(dest in ctx)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
88 if data is None:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
89 data = ctx.parents()[0][source].data()
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
90 self.assertEqual(data, ctx[dest].data())
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
91 if dest != source:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
92 copy = ctx[dest].renamed()
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
93 self.assertEqual(copy[0], source)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
94
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
95 def test_push_renames(self, commit=True):
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
96 repo = self.repo
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
97
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
98 changes = [
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
99 # Regular copy of a single file
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
100 ('a', 'a2', None),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
101 # Copy and update of target
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
102 ('a', 'a3', 'aa\n'),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
103 # Regular move of a single file
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
104 ('b', 'b2', None),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
105 ('b', None, None),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
106 # Regular move and update of target
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
107 ('c', 'c2', 'c\nc\n'),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
108 ('c', None, None),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
109 # Copy and update of source and targets
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
110 ('d', 'd2', 'd\nd2\n'),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
111 ('d', 'd', 'd\nd\n'),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
112 # Double copy and removal (aka copy and move)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
113 ('e', 'e2', 'e\ne2\n'),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
114 ('e', 'e3', 'e\ne3\n'),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
115 ('e', None, None),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
116 ]
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
117 self._commitchanges(repo, changes)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
118
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
119 hg.update(repo, repo['tip'].node())
78
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 70
diff changeset
120 push_cmd.push_revisions_to_subversion(
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 70
diff changeset
121 ui.ui(), repo=self.repo, hg_repo_path=self.wc_path,
072010a271c6 Fix basic issues with tests on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 70
diff changeset
122 svn_url=test_util.fileurl(self.repo_path))
70
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
123 tip = self.repo['tip']
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
124 # self._debug_print_copies(tip)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
125 self.assertchanges(changes, tip)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
126
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
127 def suite():
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
128 all = [unittest.TestLoader().loadTestsFromTestCase(TestPushRenames),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
129 ]
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
130 return unittest.TestSuite(all)