~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree.py

Merge working tree format registry branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
    bzrdir,
22
22
    conflicts,
23
23
    errors,
 
24
    symbol_versioning,
24
25
    transport,
25
26
    workingtree,
26
27
    )
62
63
class TestDefaultFormat(TestCaseWithTransport):
63
64
 
64
65
    def test_get_set_default_format(self):
65
 
        old_format = workingtree.WorkingTreeFormat.get_default_format()
 
66
        old_format = workingtree.format_registry.get_default()
66
67
        # default is 3
67
68
        self.assertTrue(isinstance(old_format, workingtree.WorkingTreeFormat3))
68
 
        workingtree.WorkingTreeFormat.set_default_format(SampleTreeFormat())
 
69
        workingtree.format_registry.set_default(SampleTreeFormat())
69
70
        try:
70
71
            # the default branch format is used by the meta dir format
71
72
            # which is not the default bzrdir format at this point
75
76
            result = dir.create_workingtree()
76
77
            self.assertEqual(result, 'A tree')
77
78
        finally:
78
 
            workingtree.WorkingTreeFormat.set_default_format(old_format)
79
 
        self.assertEqual(old_format, workingtree.WorkingTreeFormat.get_default_format())
 
79
            workingtree.format_registry.set_default(old_format)
 
80
        self.assertEqual(old_format, workingtree.format_registry.get_default())
80
81
 
81
82
    def test_open(self):
82
83
        tree = self.make_branch_and_tree('.')
184
185
        # make a branch
185
186
        format.initialize(dir)
186
187
        # register a format for it.
187
 
        workingtree.WorkingTreeFormat.register_format(format)
188
 
        self.assertTrue(format in workingtree.WorkingTreeFormat.get_formats())
 
188
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
 
189
            workingtree.WorkingTreeFormat.register_format, format)
 
190
        self.assertTrue(format in 
 
191
            self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
 
192
                workingtree.WorkingTreeFormat.get_formats))
189
193
        # which branch.Open will refuse (not supported)
190
194
        self.assertRaises(errors.UnsupportedFormatError, workingtree.WorkingTree.open, '.')
191
195
        # but open_downlevel will work
192
196
        self.assertEqual(format.open(dir), workingtree.WorkingTree.open_downlevel('.'))
193
197
        # unregister the format
194
 
        workingtree.WorkingTreeFormat.unregister_format(format)
195
 
        self.assertFalse(format in workingtree.WorkingTreeFormat.get_formats())
196
 
 
197
 
    def test_register_unregister_extra_format(self):
 
198
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
 
199
            workingtree.WorkingTreeFormat.unregister_format, format)
 
200
        self.assertFalse(format in
 
201
            self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
 
202
                workingtree.WorkingTreeFormat.get_formats))
 
203
 
 
204
 
 
205
class TestWorkingTreeFormatRegistry(TestCase):
 
206
 
 
207
    def setUp(self):
 
208
        super(TestWorkingTreeFormatRegistry, self).setUp()
 
209
        self.registry = workingtree.WorkingTreeFormatRegistry()
 
210
 
 
211
    def test_register_unregister_format(self):
 
212
        format = SampleTreeFormat()
 
213
        self.registry.register(format)
 
214
        self.assertEquals(format, self.registry.get("Sample tree format."))
 
215
        self.registry.remove(format)
 
216
        self.assertRaises(KeyError, self.registry.get, "Sample tree format.")
 
217
 
 
218
    def test_get_all(self):
 
219
        format = SampleTreeFormat()
 
220
        self.assertEquals([], self.registry._get_all())
 
221
        self.registry.register(format)
 
222
        self.assertEquals([format], self.registry._get_all())
 
223
 
 
224
    def test_register_extra(self):
198
225
        format = SampleExtraTreeFormat()
199
 
        workingtree.WorkingTreeFormat.register_extra_format(format)
200
 
        self.assertTrue(format in workingtree.WorkingTreeFormat.get_formats())
201
 
        workingtree.WorkingTreeFormat.unregister_extra_format(format)
202
 
        self.assertFalse(format in workingtree.WorkingTreeFormat.get_formats())
 
226
        self.assertEquals([], self.registry._get_all())
 
227
        self.registry.register_extra(format)
 
228
        self.assertEquals([format], self.registry._get_all())
 
229
 
 
230
    def test_register_extra_lazy(self):
 
231
        self.assertEquals([], self.registry._get_all())
 
232
        self.registry.register_extra_lazy("bzrlib.tests.test_workingtree",
 
233
            "SampleExtraTreeFormat")
 
234
        formats = self.registry._get_all()
 
235
        self.assertEquals(1, len(formats))
 
236
        self.assertIsInstance(formats[0], SampleExtraTreeFormat)
203
237
 
204
238
 
205
239
class TestWorkingTreeFormat3(TestCaseWithTransport):