~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_version_info.py

  • Committer: John Arbash Meinel
  • Date: 2008-09-26 22:14:42 UTC
  • mto: This revision was merged to the branch mainline in revision 3747.
  • Revision ID: john@arbash-meinel.com-20080926221442-3r67j99sr9rwe9w0
Make message optional, don't check the memory flag directly.

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
    )
24
30
from bzrlib.tests import TestCaseWithTransport
25
31
from bzrlib.rio import read_stanzas
26
32
 
 
33
from bzrlib.version_info_formats.format_custom import CustomVersionInfoBuilder
27
34
from bzrlib.version_info_formats.format_rio import RioVersionInfoBuilder
28
35
from bzrlib.version_info_formats.format_python import PythonVersionInfoBuilder
29
36
 
111
118
        stanza = regen(check_for_clean=True, include_file_revisions=True)
112
119
        self.assertEqual(['False'], stanza.get_all('clean'))
113
120
 
 
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'])
221
231
 
222
 
 
 
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')