1
# Copyright (C) 2005-2011 Canonical Ltd
1
# Copyright (C) 2005, 2006 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""Tests for version_info"""
56
def create_tree_with_dotted_revno(self):
57
wt = self.make_branch_and_tree('branch')
58
self.build_tree(['branch/a'])
60
wt.commit('a', rev_id='r1')
62
other = wt.bzrdir.sprout('other').open_workingtree()
63
self.build_tree(['other/b.a'])
65
other.commit('b.a', rev_id='o2')
68
self.run_bzr('merge ../other')
69
wt.commit('merge', rev_id='merge')
71
wt.update(revision='o2')
75
def test_rio_null(self):
76
wt = self.make_branch_and_tree('branch')
79
builder = RioVersionInfoBuilder(wt.branch, working_tree=wt)
82
self.assertContainsRe(val, 'build-date:')
83
self.assertContainsRe(val, 'revno: 0')
85
def test_rio_dotted_revno(self):
86
wt = self.create_tree_with_dotted_revno()
89
builder = RioVersionInfoBuilder(wt.branch, working_tree=wt)
92
self.assertContainsRe(val, 'revno: 1.1.1')
94
56
def test_rio_version_text(self):
95
57
wt = self.create_branch()
124
86
self.assertContainsRe(val, 'id: r3')
125
87
self.assertContainsRe(val, 'message: \xc3\xa52') # utf8 encoding '\xe5'
127
def test_rio_version_hook(self):
128
def update_stanza(rev, stanza):
129
stanza.add('bla', 'bloe')
130
RioVersionInfoBuilder.hooks.install_named_hook(
131
'revision', update_stanza, None)
132
wt = self.create_branch()
136
builder = RioVersionInfoBuilder(wt.branch, working_tree=wt,
138
builder.generate(sio)
140
stanzas = list(read_stanzas(sio))
141
self.assertEqual(1, len(stanzas))
145
self.assertEqual(['bloe'], stanza.get_all('bla'))
147
89
def test_rio_version(self):
148
90
wt = self.create_branch()
164
106
return new_stanzas[0]
167
self.assertTrue('date' in stanza)
168
self.assertTrue('build-date' in stanza)
109
self.failUnless('date' in stanza)
110
self.failUnless('build-date' in stanza)
169
111
self.assertEqual(['3'], stanza.get_all('revno'))
170
112
self.assertEqual(['r3'], stanza.get_all('revision-id'))
176
118
stanza = regen(check_for_clean=True, include_file_revisions=True)
177
119
self.assertEqual(['False'], stanza.get_all('clean'))
179
# This assumes it's being run against a tree that does not update the
180
# root revision on every commit.
121
# XXX: This assumes it's being run against a repository that updates
122
# the root revision on every commit. Newer ones that use
123
# RootCommitBuilder won't update it on each commit.
181
124
file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
182
125
self.assertEqual(['', 'a', 'b', 'c'], file_rev_stanza.get_all('path'))
183
self.assertEqual(['r1', 'r3', 'r2', 'unversioned'],
126
self.assertEqual(['r3', 'r3', 'r2', 'unversioned'],
184
127
file_rev_stanza.get_all('revision'))
185
128
os.remove('branch/c')
196
139
wt.rename_one('b', 'd')
197
140
stanza = regen(check_for_clean=True, include_file_revisions=True)
198
141
file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
199
self.assertEqual(['', 'a', 'b', 'c', 'd'],
142
self.assertEqual(['', 'a', 'b', 'c', 'd'],
200
143
file_rev_stanza.get_all('path'))
201
self.assertEqual(['r1', 'modified', 'renamed to d', 'new',
144
self.assertEqual(['r3', 'modified', 'renamed to d', 'new',
202
145
'renamed from b'],
203
146
file_rev_stanza.get_all('revision'))
208
151
stanza = regen(check_for_clean=True, include_file_revisions=True)
209
152
file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
210
153
self.assertEqual(['', 'a', 'c', 'd'], file_rev_stanza.get_all('path'))
211
self.assertEqual(['r1', 'r4', 'unversioned', 'removed'],
154
self.assertEqual(['r4', 'r4', 'unversioned', 'removed'],
212
155
file_rev_stanza.get_all('revision'))
214
def test_python_null(self):
215
wt = self.make_branch_and_tree('branch')
218
builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt)
219
builder.generate(sio)
221
self.assertContainsRe(val, "'revision_id': None")
222
self.assertContainsRe(val, "'revno': '0'")
223
self.assertNotContainsString(val, '\n\n\n\n')
225
def test_python_dotted_revno(self):
226
wt = self.create_tree_with_dotted_revno()
229
builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt)
230
builder.generate(sio)
232
self.assertContainsRe(val, "'revno': '1.1.1'")
234
157
def test_python_version(self):
235
158
wt = self.create_branch()
263
self.assertEqual('3', tvi.version_info['revno'])
186
self.assertEqual(3, tvi.version_info['revno'])
264
187
self.assertEqual('r3', tvi.version_info['revision_id'])
265
self.assertTrue(tvi.version_info.has_key('date'))
188
self.failUnless(tvi.version_info.has_key('date'))
266
189
self.assertEqual(None, tvi.version_info['clean'])
268
191
tvi = regen(check_for_clean=True)
271
194
self.build_tree(['branch/c'])
272
195
tvi = regen(check_for_clean=True, include_file_revisions=True)
273
196
self.assertEqual(False, tvi.version_info['clean'])
274
self.assertEqual(['', 'a', 'b', 'c'],
197
self.assertEqual(['', 'a', 'b', 'c'],
275
198
sorted(tvi.file_revisions.keys()))
276
199
self.assertEqual('r3', tvi.file_revisions['a'])
277
200
self.assertEqual('r2', tvi.file_revisions['b'])
290
213
wt.rename_one('b', 'd')
291
214
tvi = regen(check_for_clean=True, include_file_revisions=True)
292
self.assertEqual(['', 'a', 'b', 'c', 'd'],
215
self.assertEqual(['', 'a', 'b', 'c', 'd'],
293
216
sorted(tvi.file_revisions.keys()))
294
217
self.assertEqual('modified', tvi.file_revisions['a'])
295
218
self.assertEqual('renamed to d', tvi.file_revisions['b'])
300
223
wt.remove(['c', 'd'])
301
224
os.remove('branch/d')
302
225
tvi = regen(check_for_clean=True, include_file_revisions=True)
303
self.assertEqual(['', 'a', 'c', 'd'],
226
self.assertEqual(['', 'a', 'c', 'd'],
304
227
sorted(tvi.file_revisions.keys()))
305
228
self.assertEqual('r4', tvi.file_revisions['a'])
306
229
self.assertEqual('unversioned', tvi.file_revisions['c'])
307
230
self.assertEqual('removed', tvi.file_revisions['d'])
309
def test_custom_null(self):
311
wt = self.make_branch_and_tree('branch')
312
builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
313
template='revno: {revno}')
314
builder.generate(sio)
315
self.assertEquals("revno: 0", sio.getvalue())
317
builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
318
template='{revno} revid: {revision_id}')
319
# revision_id is not available yet
320
self.assertRaises(errors.MissingTemplateVariable,
321
builder.generate, sio)
323
def test_custom_dotted_revno(self):
325
wt = self.create_tree_with_dotted_revno()
326
builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
327
template='{revno} revid: {revision_id}')
328
builder.generate(sio)
329
self.assertEquals("1.1.1 revid: o2", sio.getvalue())
331
232
def test_custom_version_text(self):
332
233
wt = self.create_branch()
373
274
super(TestVersionInfoFormatRegistry, self).setUp()
374
self.overrideAttr(version_info_formats,
375
'format_registry', registry.Registry())
275
registry = version_info_formats.format_registry
276
self._default_key = registry._default_key
277
self._dict = registry._dict.copy()
278
self._help_dict = registry._help_dict.copy()
279
self._info_dict = registry._info_dict.copy()
280
self.addCleanup(self._cleanup)
283
# Restore the registry to pristine state after the test runs
284
registry = version_info_formats.format_registry
285
registry._default_key = self._default_key
286
registry._dict = self._dict
287
registry._help_dict = self._help_dict
288
registry._info_dict = self._info_dict
377
290
def test_register_remove(self):
378
291
registry = version_info_formats.format_registry