comparison tests/test_utility_commands.py @ 331:75f082b5897e

Switch to using url scheme wrappers instead of duplicating each command we wrap. The 'hg svn url' command has been killed; the replacement is '.hg/hgrc'. More stuff related to its disappearance has been stripped, including two tests. HgChangeReceiver now takes a UUID argument, which it uses to ensure that remote repositories remain unchanged. This is a temporary solution, and I'm not entirely satisfied with how it's done either. Access to the UUID file has been isolated in a HgChangeReceiver property. Some more tests have been updated to use ui.pushbuffer()/popbuffer(), and to pass through the Mercurial API. Moved the arguments to wrappers.pull() to the UI configuration. Also, remove HgChangeReceiver.opts in favour of a 'usebranchnames' instance & configuration variable. The name is taken from the ConvertExtension.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Fri, 15 May 2009 19:18:43 +0200
parents 112d57bb736e
children 46e69be8e2c8
comparison
equal deleted inserted replaced
330:5f8f2fd4fd54 331:75f082b5897e
6 from mercurial import hg 6 from mercurial import hg
7 from mercurial import revlog 7 from mercurial import revlog
8 from mercurial import context 8 from mercurial import context
9 from mercurial import node 9 from mercurial import node
10 10
11 import util
11 import utility_commands 12 import utility_commands
12 import test_util 13 import test_util
13 import wrappers 14 import wrappers
14 15
15 expected_info_output = '''URL: %(repourl)s/%(branch)s 16 expected_info_output = '''URL: %(repourl)s/%(branch)s
21 Last Changed Rev: %(rev)s 22 Last Changed Rev: %(rev)s
22 Last Changed Date: %(date)s 23 Last Changed Date: %(date)s
23 ''' 24 '''
24 25
25 class UtilityTests(test_util.TestBase): 26 class UtilityTests(test_util.TestBase):
27 @property
28 def repourl(self):
29 return util.normalize_url(test_util.fileurl(self.repo_path))
30
26 def test_info_output(self): 31 def test_info_output(self):
27 self._load_fixture_and_fetch('two_heads.svndump') 32 self._load_fixture_and_fetch('two_heads.svndump')
28 hg.update(self.repo, 'the_branch') 33 hg.update(self.repo, 'the_branch')
29 u = ui.ui() 34 u = ui.ui()
35 u.pushbuffer()
30 utility_commands.info(u, self.repo, self.wc_path) 36 utility_commands.info(u, self.repo, self.wc_path)
37 actual = u.popbuffer()
31 expected = (expected_info_output % 38 expected = (expected_info_output %
32 {'date': '2008-10-08 01:39:05 +0000 (Wed, 08 Oct 2008)', 39 {'date': '2008-10-08 01:39:05 +0000 (Wed, 08 Oct 2008)',
33 'repourl': test_util.fileurl(self.repo_path), 40 'repourl': self.repourl,
34 'branch': 'branches/the_branch', 41 'branch': 'branches/the_branch',
35 'rev': 5, 42 'rev': 5,
36 }) 43 })
37 self.assertEqual(u.stream.getvalue(), expected) 44 self.assertEqual(actual, expected)
38 hg.update(self.repo, 'default') 45 hg.update(self.repo, 'default')
39 u = ui.ui() 46 u.pushbuffer()
40 utility_commands.info(u, self.repo, self.wc_path) 47 utility_commands.info(u, self.repo, self.wc_path)
48 actual = u.popbuffer()
41 expected = (expected_info_output % 49 expected = (expected_info_output %
42 {'date': '2008-10-08 01:39:29 +0000 (Wed, 08 Oct 2008)', 50 {'date': '2008-10-08 01:39:29 +0000 (Wed, 08 Oct 2008)',
43 'repourl': test_util.fileurl(self.repo_path), 51 'repourl': self.repourl,
44 'branch': 'trunk', 52 'branch': 'trunk',
45 'rev': 6, 53 'rev': 6,
46 }) 54 })
47 self.assertEqual(u.stream.getvalue(), expected) 55 self.assertEqual(actual, expected)
48 56
49 def test_parent_output(self): 57 def test_parent_output(self):
50 self._load_fixture_and_fetch('two_heads.svndump') 58 self._load_fixture_and_fetch('two_heads.svndump')
51 u = ui.ui() 59 u = ui.ui()
60 u.pushbuffer()
52 parents = (self.repo['the_branch'].node(), revlog.nullid, ) 61 parents = (self.repo['the_branch'].node(), revlog.nullid, )
53 def filectxfn(repo, memctx, path): 62 def filectxfn(repo, memctx, path):
54 return context.memfilectx(path=path, 63 return context.memfilectx(path=path,
55 data='added', 64 data='added',
56 islink=False, 65 islink=False,
65 '2008-12-21 16:32:00 -0500', 74 '2008-12-21 16:32:00 -0500',
66 {'branch': 'localbranch', }) 75 {'branch': 'localbranch', })
67 new = self.repo.commitctx(ctx) 76 new = self.repo.commitctx(ctx)
68 hg.update(self.repo, new) 77 hg.update(self.repo, new)
69 wrappers.parent(lambda x, y: None, u, self.repo, svn=True) 78 wrappers.parent(lambda x, y: None, u, self.repo, svn=True)
70 self.assertEqual(u.stream.getvalue(), 79 actual = u.popbuffer()
80 self.assertEqual(actual,
71 'changeset: 3:4e256962fc5d\n' 81 'changeset: 3:4e256962fc5d\n'
72 'branch: the_branch\n' 82 'branch: the_branch\n'
73 'user: durin@df2126f7-00ab-4d49-b42c-7e981dde0bcf\n' 83 'user: durin@df2126f7-00ab-4d49-b42c-7e981dde0bcf\n'
74 'date: Wed Oct 08 01:39:05 2008 +0000\n' 84 'date: Wed Oct 08 01:39:05 2008 +0000\n'
75 'summary: add delta on the branch\n\n') 85 'summary: add delta on the branch\n\n')
76 86
77 hg.update(self.repo, 'default') 87 hg.update(self.repo, 'default')
78 # Make sure styles work 88 # Make sure styles work
79 u = ui.ui() 89 u.pushbuffer()
80 wrappers.parent(lambda x, y: None, u, self.repo, svn=True, style='compact') 90 wrappers.parent(lambda x, y: None, u, self.repo, svn=True, style='compact')
81 self.assertEqual(u.stream.getvalue(), 91 actual = u.popbuffer()
92 self.assertEqual(actual,
82 '4:1 1083037b18d8 2008-10-08 01:39 +0000 durin\n' 93 '4:1 1083037b18d8 2008-10-08 01:39 +0000 durin\n'
83 ' Add gamma on trunk.\n\n') 94 ' Add gamma on trunk.\n\n')
84 # custom templates too 95 # custom templates too
85 u = ui.ui() 96 u.pushbuffer()
86 wrappers.parent(lambda x, y: None, u, self.repo, svn=True, template='{node}\n') 97 wrappers.parent(lambda x, y: None, u, self.repo, svn=True, template='{node}\n')
87 self.assertEqual(u.stream.getvalue(), '1083037b18d85cd84fa211c5adbaeff0fea2cd9f\n') 98 actual = u.popbuffer()
88 99 self.assertEqual(actual, '1083037b18d85cd84fa211c5adbaeff0fea2cd9f\n')
89 u = ui.ui() 100
101 u.pushbuffer()
90 wrappers.parent(lambda x, y: None, u, self.repo, svn=True) 102 wrappers.parent(lambda x, y: None, u, self.repo, svn=True)
91 self.assertEqual(u.stream.getvalue(), 103 actual = u.popbuffer()
104 self.assertEqual(actual,
92 'changeset: 4:1083037b18d8\n' 105 'changeset: 4:1083037b18d8\n'
93 'parent: 1:c95251e0dd04\n' 106 'parent: 1:c95251e0dd04\n'
94 'user: durin@df2126f7-00ab-4d49-b42c-7e981dde0bcf\n' 107 'user: durin@df2126f7-00ab-4d49-b42c-7e981dde0bcf\n'
95 'date: Wed Oct 08 01:39:29 2008 +0000\n' 108 'date: Wed Oct 08 01:39:29 2008 +0000\n'
96 'summary: Add gamma on trunk.\n\n') 109 'summary: Add gamma on trunk.\n\n')
97 110
98 def test_outgoing_output(self): 111 def test_outgoing_output(self):
99 self._load_fixture_and_fetch('two_heads.svndump') 112 self._load_fixture_and_fetch('two_heads.svndump')
100 u = ui.ui() 113 u = ui.ui()
114 u.pushbuffer()
101 parents = (self.repo['the_branch'].node(), revlog.nullid, ) 115 parents = (self.repo['the_branch'].node(), revlog.nullid, )
102 def filectxfn(repo, memctx, path): 116 def filectxfn(repo, memctx, path):
103 return context.memfilectx(path=path, 117 return context.memfilectx(path=path,
104 data='added', 118 data='added',
105 islink=False, 119 islink=False,
114 '2008-12-21 16:32:00 -0500', 128 '2008-12-21 16:32:00 -0500',
115 {'branch': 'localbranch', }) 129 {'branch': 'localbranch', })
116 new = self.repo.commitctx(ctx) 130 new = self.repo.commitctx(ctx)
117 hg.update(self.repo, new) 131 hg.update(self.repo, new)
118 wrappers.outgoing(lambda x,y,z: None, u, self.repo, svn=True) 132 wrappers.outgoing(lambda x,y,z: None, u, self.repo, svn=True)
119 self.assert_(node.hex(self.repo['localbranch'].node())[:8] in 133 actual = u.popbuffer()
120 u.stream.getvalue()) 134 self.assert_(node.hex(self.repo['localbranch'].node())[:8] in actual)
121 self.assertEqual(u.stream.getvalue(), ('changeset: 5:6de15430fa20\n' 135 self.assertEqual(actual, ('changeset: 5:6de15430fa20\n'
122 'branch: localbranch\n' 136 'branch: localbranch\n'
123 'tag: tip\n' 137 'tag: tip\n'
124 'parent: 3:4e256962fc5d\n' 138 'parent: 3:4e256962fc5d\n'
125 'user: testy\n' 139 'user: testy\n'
126 'date: Sun Dec 21 16:32:00 2008 -0500\n' 140 'date: Sun Dec 21 16:32:00 2008 -0500\n'
127 'summary: automated test\n' 141 'summary: automated test\n'
128 '\n')) 142 '\n'))
129 hg.update(self.repo, 'default') 143 hg.update(self.repo, 'default')
130 u = ui.ui() 144 u.pushbuffer()
131 wrappers.outgoing(lambda x,y,z: None, u, self.repo, svn=True) 145 wrappers.outgoing(lambda x,y,z: None, u, self.repo, svn=True)
132 self.assertEqual(u.stream.getvalue(), 'no changes found\n') 146 actual = u.popbuffer()
133 147 self.assertEqual(actual, 'no changes found\n')
134 def test_url_output(self):
135 self._load_fixture_and_fetch('two_revs.svndump')
136 hg.update(self.repo, 'tip')
137 u = ui.ui()
138 utility_commands.url(u, self.repo, self.wc_path)
139 expected = test_util.fileurl(self.repo_path) + '\n'
140 self.assertEqual(u.stream.getvalue(), expected)
141 148
142 def test_rebase(self): 149 def test_rebase(self):
143 self._load_fixture_and_fetch('two_revs.svndump') 150 self._load_fixture_and_fetch('two_revs.svndump')
144 parents = (self.repo[0].node(), revlog.nullid, ) 151 parents = (self.repo[0].node(), revlog.nullid, )
145 def filectxfn(repo, memctx, path): 152 def filectxfn(repo, memctx, path):
163 wrappers.rebase(rebase.rebase, ui.ui(), self.repo, svn=True) 170 wrappers.rebase(rebase.rebase, ui.ui(), self.repo, svn=True)
164 self.assertEqual(self.repo['tip'].branch(), 'localbranch') 171 self.assertEqual(self.repo['tip'].branch(), 'localbranch')
165 self.assertEqual(self.repo['tip'].parents()[0].parents()[0], self.repo[0]) 172 self.assertEqual(self.repo['tip'].parents()[0].parents()[0], self.repo[0])
166 self.assertNotEqual(beforerebasehash, self.repo['tip'].node()) 173 self.assertNotEqual(beforerebasehash, self.repo['tip'].node())
167 174
168 def test_url_is_normalized(self):
169 """Verify url gets normalized on initial clone.
170 """
171 test_util.load_svndump_fixture(self.repo_path, 'two_revs.svndump')
172 wrappers.clone(None, ui.ui(),
173 source=test_util.fileurl(self.repo_path) + '/',
174 dest=self.wc_path, stupid=False)
175 hg.update(self.repo, 'tip')
176 u = ui.ui()
177 utility_commands.url(u, self.repo, self.wc_path)
178 expected = test_util.fileurl(self.repo_path) + '\n'
179 self.assertEqual(u.stream.getvalue(), expected)
180
181 def test_genignore(self): 175 def test_genignore(self):
182 """Verify url gets normalized on initial clone. 176 """ Test generation of .hgignore file. """
183 """ 177 test_util.load_fixture_and_fetch('ignores.svndump', self.repo_path,
184 test_util.load_svndump_fixture(self.repo_path, 'ignores.svndump') 178 self.wc_path, noupdate=False)
185 wrappers.clone(None, ui.ui(), 179 u = ui.ui()
186 source=test_util.fileurl(self.repo_path) + '/', 180 u.pushbuffer()
187 dest=self.wc_path, stupid=False)
188 hg.update(self.repo, 'tip')
189 u = ui.ui()
190 utility_commands.genignore(u, self.repo, self.wc_path) 181 utility_commands.genignore(u, self.repo, self.wc_path)
191 self.assertEqual(open(os.path.join(self.wc_path, '.hgignore')).read(), 182 self.assertEqual(open(os.path.join(self.wc_path, '.hgignore')).read(),
192 '.hgignore\nsyntax:glob\nblah\notherblah\nbaz/magic\n') 183 '.hgignore\nsyntax:glob\nblah\notherblah\nbaz/magic\n')
193 184
194 def test_list_authors(self): 185 def test_list_authors(self):
195 test_util.load_svndump_fixture(self.repo_path, 186 test_util.load_svndump_fixture(self.repo_path,
196 'replace_trunk_with_branch.svndump') 187 'replace_trunk_with_branch.svndump')
197 u = ui.ui() 188 u = ui.ui()
189 u.pushbuffer()
198 utility_commands.listauthors(u, 190 utility_commands.listauthors(u,
199 args=[test_util.fileurl(self.repo_path)], 191 args=[test_util.fileurl(self.repo_path)],
200 authors=None) 192 authors=None)
201 self.assertEqual(u.stream.getvalue(), 'Augie\nevil\n') 193 actual = u.popbuffer()
194 self.assertEqual(actual, 'Augie\nevil\n')
202 195
203 196
204 def test_list_authors_map(self): 197 def test_list_authors_map(self):
205 test_util.load_svndump_fixture(self.repo_path, 198 test_util.load_svndump_fixture(self.repo_path,
206 'replace_trunk_with_branch.svndump') 199 'replace_trunk_with_branch.svndump')