111
118
stanza = regen(check_for_clean=True, include_file_revisions=True)
112
119
self.assertEqual(['False'], stanza.get_all('clean'))
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.
114
124
file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
115
125
self.assertEqual(['', 'a', 'b', 'c'], file_rev_stanza.get_all('path'))
116
126
self.assertEqual(['r3', 'r3', 'r2', 'unversioned'],
219
229
self.assertEqual('unversioned', tvi.file_revisions['c'])
220
230
self.assertEqual('removed', tvi.file_revisions['d'])
232
def test_custom_version_text(self):
233
wt = self.create_branch()
235
def regen(tpl, **kwargs):
237
builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
238
template=tpl, **kwargs)
239
builder.generate(sio)
243
val = regen('build-date: "{build_date}"\ndate: "{date}"')
244
self.assertContainsRe(val, 'build-date: "[0-9-+: ]+"')
245
self.assertContainsRe(val, 'date: "[0-9-+: ]+"')
247
val = regen('revno: {revno}')
248
self.assertEqual(val, 'revno: 3')
250
val = regen('revision-id: {revision_id}')
251
self.assertEqual(val, 'revision-id: r3')
253
val = regen('clean: {clean}', check_for_clean=True)
254
self.assertEqual(val, 'clean: 1')
256
self.build_tree(['branch/c'])
257
val = regen('clean: {clean}', check_for_clean=True)
258
self.assertEqual(val, 'clean: 0')
259
os.remove('branch/c')
261
def test_custom_without_template(self):
262
builder = CustomVersionInfoBuilder(None)
264
self.assertRaises(errors.NoTemplate, builder.generate, sio)
267
class TestBuilder(version_info_formats.VersionInfoBuilder):
271
class TestVersionInfoFormatRegistry(tests.TestCase):
274
super(TestVersionInfoFormatRegistry, self).setUp()
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
290
def test_register_remove(self):
291
registry = version_info_formats.format_registry
292
registry.register('testbuilder',
293
TestBuilder, 'a simple test builder')
294
self.assertIs(TestBuilder, registry.get('testbuilder'))
295
self.assertEqual('a simple test builder',
296
registry.get_help('testbuilder'))
297
registry.remove('testbuilder')
298
self.assertRaises(KeyError, registry.get, 'testbuilder')