~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_version_info.py

Merge bzr.dev

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
    symbol_versioning,
 
26
    tests,
 
27
    version_info_formats,
 
28
    )
24
29
from bzrlib.tests import TestCaseWithTransport
25
30
from bzrlib.rio import read_stanzas
26
31
 
251
256
        val = regen('clean: {clean}', check_for_clean=True)
252
257
        self.assertEqual(val, 'clean: 0')
253
258
        os.remove('branch/c')
 
259
 
 
260
 
 
261
class TestBuilder(version_info_formats.VersionInfoBuilder):
 
262
    pass
 
263
 
 
264
 
 
265
class TestVersionInfoFormatRegistry(tests.TestCase):
 
266
 
 
267
    def setUp(self):
 
268
        super(TestVersionInfoFormatRegistry, self).setUp()
 
269
        registry = version_info_formats.format_registry
 
270
        self._default_key = registry._default_key
 
271
        self._dict = registry._dict.copy()
 
272
        self._help_dict = registry._help_dict.copy()
 
273
        self._info_dict = registry._info_dict.copy()
 
274
        self.addCleanup(self._cleanup)
 
275
 
 
276
    def _cleanup(self):
 
277
        # Restore the registry to pristine state after the test runs
 
278
        registry = version_info_formats.format_registry
 
279
        registry._default_key = self._default_key
 
280
        registry._dict = self._dict
 
281
        registry._help_dict = self._help_dict
 
282
        registry._info_dict = self._info_dict
 
283
 
 
284
    def test_register_remove(self):
 
285
        registry = version_info_formats.format_registry
 
286
        registry.register('testbuilder',
 
287
            TestBuilder, 'a simple test builder')
 
288
        self.assertIs(TestBuilder, registry.get('testbuilder'))
 
289
        self.assertEqual('a simple test builder',
 
290
                         registry.get_help('testbuilder'))
 
291
        registry.remove('testbuilder')
 
292
        self.assertRaises(KeyError, registry.get, 'testbuilder')
 
293
 
 
294
    def test_old_functions(self):
 
295
        self.applyDeprecated(symbol_versioning.one_zero,
 
296
            version_info_formats.register_builder,
 
297
            'test-builder', __name__, 'TestBuilder')
 
298
        formats = self.applyDeprecated(symbol_versioning.one_zero,
 
299
            version_info_formats.get_builder_formats)
 
300
        self.failUnless('test-builder' in formats)
 
301
        self.assertIs(TestBuilder,
 
302
            self.applyDeprecated(symbol_versioning.one_zero,
 
303
                version_info_formats.get_builder, 'test-builder'))
 
304
        version_info_formats.format_registry.remove('test-builder')