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"""
97
79
self.assertContainsRe(val, 'id: r3')
98
80
self.assertContainsRe(val, 'message: \xc3\xa52') # utf8 encoding '\xe5'
100
def test_rio_version_hook(self):
101
def update_stanza(rev, stanza):
102
stanza.add('bla', 'bloe')
103
RioVersionInfoBuilder.hooks.install_named_hook(
104
'revision', update_stanza, None)
105
wt = self.create_branch()
109
builder = RioVersionInfoBuilder(wt.branch, working_tree=wt,
111
builder.generate(sio)
113
stanzas = list(read_stanzas(sio))
114
self.assertEqual(1, len(stanzas))
118
self.assertEqual(['bloe'], stanza.get_all('bla'))
120
82
def test_rio_version(self):
121
83
wt = self.create_branch()
149
111
stanza = regen(check_for_clean=True, include_file_revisions=True)
150
112
self.assertEqual(['False'], stanza.get_all('clean'))
152
# This assumes it's being run against a tree that does not update the
153
# root revision on every commit.
154
114
file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
155
115
self.assertEqual(['', 'a', 'b', 'c'], file_rev_stanza.get_all('path'))
156
self.assertEqual(['r1', 'r3', 'r2', 'unversioned'],
116
self.assertEqual(['r3', 'r3', 'r2', 'unversioned'],
157
117
file_rev_stanza.get_all('revision'))
158
118
os.remove('branch/c')
169
129
wt.rename_one('b', 'd')
170
130
stanza = regen(check_for_clean=True, include_file_revisions=True)
171
131
file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
172
self.assertEqual(['', 'a', 'b', 'c', 'd'],
132
self.assertEqual(['', 'a', 'b', 'c', 'd'],
173
133
file_rev_stanza.get_all('path'))
174
self.assertEqual(['r1', 'modified', 'renamed to d', 'new',
134
self.assertEqual(['r3', 'modified', 'renamed to d', 'new',
175
135
'renamed from b'],
176
136
file_rev_stanza.get_all('revision'))
181
141
stanza = regen(check_for_clean=True, include_file_revisions=True)
182
142
file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
183
143
self.assertEqual(['', 'a', 'c', 'd'], file_rev_stanza.get_all('path'))
184
self.assertEqual(['r1', 'r4', 'unversioned', 'removed'],
144
self.assertEqual(['r4', 'r4', 'unversioned', 'removed'],
185
145
file_rev_stanza.get_all('revision'))
187
def test_python_null(self):
188
wt = self.make_branch_and_tree('branch')
191
builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt)
192
builder.generate(sio)
194
self.assertContainsRe(val, "'revision_id': None")
195
self.assertContainsRe(val, "'revno': 0")
197
147
def test_python_version(self):
198
148
wt = self.create_branch()
234
184
self.build_tree(['branch/c'])
235
185
tvi = regen(check_for_clean=True, include_file_revisions=True)
236
186
self.assertEqual(False, tvi.version_info['clean'])
237
self.assertEqual(['', 'a', 'b', 'c'],
187
self.assertEqual(['', 'a', 'b', 'c'],
238
188
sorted(tvi.file_revisions.keys()))
239
189
self.assertEqual('r3', tvi.file_revisions['a'])
240
190
self.assertEqual('r2', tvi.file_revisions['b'])
253
203
wt.rename_one('b', 'd')
254
204
tvi = regen(check_for_clean=True, include_file_revisions=True)
255
self.assertEqual(['', 'a', 'b', 'c', 'd'],
205
self.assertEqual(['', 'a', 'b', 'c', 'd'],
256
206
sorted(tvi.file_revisions.keys()))
257
207
self.assertEqual('modified', tvi.file_revisions['a'])
258
208
self.assertEqual('renamed to d', tvi.file_revisions['b'])
263
213
wt.remove(['c', 'd'])
264
214
os.remove('branch/d')
265
215
tvi = regen(check_for_clean=True, include_file_revisions=True)
266
self.assertEqual(['', 'a', 'c', 'd'],
216
self.assertEqual(['', 'a', 'c', 'd'],
267
217
sorted(tvi.file_revisions.keys()))
268
218
self.assertEqual('r4', tvi.file_revisions['a'])
269
219
self.assertEqual('unversioned', tvi.file_revisions['c'])
270
220
self.assertEqual('removed', tvi.file_revisions['d'])
272
def test_custom_null(self):
274
wt = self.make_branch_and_tree('branch')
275
builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
276
template='revno: {revno}')
277
builder.generate(sio)
278
self.assertEquals("revno: 0", sio.getvalue())
280
builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
281
template='{revno} revid: {revision_id}')
282
# revision_id is not available yet
283
self.assertRaises(errors.MissingTemplateVariable,
284
builder.generate, sio)
286
def test_custom_version_text(self):
287
wt = self.create_branch()
289
def regen(tpl, **kwargs):
291
builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
292
template=tpl, **kwargs)
293
builder.generate(sio)
297
val = regen('build-date: "{build_date}"\ndate: "{date}"')
298
self.assertContainsRe(val, 'build-date: "[0-9-+: ]+"')
299
self.assertContainsRe(val, 'date: "[0-9-+: ]+"')
301
val = regen('revno: {revno}')
302
self.assertEqual(val, 'revno: 3')
304
val = regen('revision-id: {revision_id}')
305
self.assertEqual(val, 'revision-id: r3')
307
val = regen('clean: {clean}', check_for_clean=True)
308
self.assertEqual(val, 'clean: 1')
310
self.build_tree(['branch/c'])
311
val = regen('clean: {clean}', check_for_clean=True)
312
self.assertEqual(val, 'clean: 0')
313
os.remove('branch/c')
315
def test_custom_without_template(self):
316
builder = CustomVersionInfoBuilder(None)
318
self.assertRaises(errors.NoTemplate, builder.generate, sio)
321
class TestBuilder(version_info_formats.VersionInfoBuilder):
325
class TestVersionInfoFormatRegistry(tests.TestCase):
328
super(TestVersionInfoFormatRegistry, self).setUp()
329
self.overrideAttr(version_info_formats,
330
'format_registry', registry.Registry())
332
def test_register_remove(self):
333
registry = version_info_formats.format_registry
334
registry.register('testbuilder',
335
TestBuilder, 'a simple test builder')
336
self.assertIs(TestBuilder, registry.get('testbuilder'))
337
self.assertEqual('a simple test builder',
338
registry.get_help('testbuilder'))
339
registry.remove('testbuilder')
340
self.assertRaises(KeyError, registry.get, 'testbuilder')