~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_version_info.py

  • Committer: Martin Pool
  • Date: 2007-04-04 06:17:31 UTC
  • mto: This revision was merged to the branch mainline in revision 2397.
  • Revision ID: mbp@sourcefrog.net-20070404061731-tt2xrzllqhbodn83
Contents of TODO file moved into bug tracker

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import os
22
22
import sys
23
23
 
24
 
from bzrlib import (
25
 
    errors,
26
 
    symbol_versioning,
27
 
    tests,
28
 
    version_info_formats,
29
 
    )
30
24
from bzrlib.tests import TestCaseWithTransport
31
25
from bzrlib.rio import read_stanzas
32
26
 
33
 
from bzrlib.version_info_formats.format_custom import CustomVersionInfoBuilder
34
27
from bzrlib.version_info_formats.format_rio import RioVersionInfoBuilder
35
28
from bzrlib.version_info_formats.format_python import PythonVersionInfoBuilder
36
29
 
118
111
        stanza = regen(check_for_clean=True, include_file_revisions=True)
119
112
        self.assertEqual(['False'], stanza.get_all('clean'))
120
113
 
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.
124
114
        file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
125
115
        self.assertEqual(['', 'a', 'b', 'c'], file_rev_stanza.get_all('path'))
126
116
        self.assertEqual(['r3', 'r3', 'r2', 'unversioned'],
229
219
        self.assertEqual('unversioned', tvi.file_revisions['c'])
230
220
        self.assertEqual('removed', tvi.file_revisions['d'])
231
221
 
232
 
    def test_custom_version_text(self):
233
 
        wt = self.create_branch()
234
 
 
235
 
        def regen(tpl, **kwargs):
236
 
            sio = StringIO()
237
 
            builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
238
 
                                               template=tpl, **kwargs)
239
 
            builder.generate(sio)
240
 
            val = sio.getvalue()
241
 
            return val
242
 
 
243
 
        val = regen('build-date: "{build_date}"\ndate: "{date}"')
244
 
        self.assertContainsRe(val, 'build-date: "[0-9-+: ]+"')
245
 
        self.assertContainsRe(val, 'date: "[0-9-+: ]+"')
246
 
 
247
 
        val = regen('revno: {revno}')
248
 
        self.assertEqual(val, 'revno: 3')
249
 
 
250
 
        val = regen('revision-id: {revision_id}')
251
 
        self.assertEqual(val, 'revision-id: r3')
252
 
 
253
 
        val = regen('clean: {clean}', check_for_clean=True)
254
 
        self.assertEqual(val, 'clean: 1')
255
 
 
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')
260
 
 
261
 
    def test_custom_without_template(self):
262
 
        builder = CustomVersionInfoBuilder(None)
263
 
        sio = StringIO()
264
 
        self.assertRaises(errors.NoTemplate, builder.generate, sio)
265
 
 
266
 
 
267
 
class TestBuilder(version_info_formats.VersionInfoBuilder):
268
 
    pass
269
 
 
270
 
 
271
 
class TestVersionInfoFormatRegistry(tests.TestCase):
272
 
 
273
 
    def setUp(self):
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)
281
 
 
282
 
    def _cleanup(self):
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
289
 
 
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')
299
 
 
300
 
    def test_old_functions(self):
301
 
        self.applyDeprecated(symbol_versioning.one_zero,
302
 
            version_info_formats.register_builder,
303
 
            'test-builder', __name__, 'TestBuilder')
304
 
        formats = self.applyDeprecated(symbol_versioning.one_zero,
305
 
            version_info_formats.get_builder_formats)
306
 
        self.failUnless('test-builder' in formats)
307
 
        self.assertIs(TestBuilder,
308
 
            self.applyDeprecated(symbol_versioning.one_zero,
309
 
                version_info_formats.get_builder, 'test-builder'))
310
 
        version_info_formats.format_registry.remove('test-builder')
 
222