1
# Copyright (C) 2006, 2008-2012, 2016 Canonical Ltd
1
# Copyright (C) 2006, 2008-2011 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
203
201
self.assertEqual('//baz/qux', suffix)
204
202
self.assertIs(sftp_object, found_object)
206
def test_registry_alias(self):
207
a_registry = registry.Registry()
208
a_registry.register('one', 1, info='string info')
209
a_registry.register_alias('two', 'one')
210
a_registry.register_alias('three', 'one', info='own info')
211
self.assertEqual(a_registry.get('one'), a_registry.get('two'))
212
self.assertEqual(a_registry.get_help('one'), a_registry.get_help('two'))
213
self.assertEqual(a_registry.get_info('one'), a_registry.get_info('two'))
214
self.assertEqual('own info', a_registry.get_info('three'))
215
self.assertEqual({'two': 'one', 'three': 'one'}, a_registry.aliases())
216
self.assertEqual({'one': ['three', 'two']},
217
{k: sorted(v) for (k, v) in viewitems(a_registry.alias_map())})
219
def test_registry_alias_exists(self):
220
a_registry = registry.Registry()
221
a_registry.register('one', 1, info='string info')
222
a_registry.register('two', 2)
223
self.assertRaises(KeyError, a_registry.register_alias, 'one', 'one')
225
def test_registry_alias_targetmissing(self):
226
a_registry = registry.Registry()
227
self.assertRaises(KeyError, a_registry.register_alias, 'one', 'two')
230
205
class TestRegistryIter(tests.TestCase):
231
206
"""Test registry iteration behaviors.
316
291
def test_lazy_import_registry_foo(self):
317
292
a_registry = registry.Registry()
318
a_registry.register_lazy('foo', 'breezy.branch', 'Branch')
319
a_registry.register_lazy('bar', 'breezy.branch', 'Branch.hooks')
293
a_registry.register_lazy('foo', 'bzrlib.branch', 'Branch')
294
a_registry.register_lazy('bar', 'bzrlib.branch', 'Branch.hooks')
320
295
self.assertEqual(branch.Branch, a_registry.get('foo'))
321
296
self.assertEqual(branch.Branch.hooks, a_registry.get('bar'))
336
311
# By default the plugin won't be in the search path
337
312
self.assertRaises(ImportError, a_registry.get, 'obj')
339
plugin_path = self.test_dir + '/tmp'
314
plugin_path = os.getcwd() + '/tmp'
340
315
sys.path.append(plugin_path)
342
317
obj = a_registry.get('obj')
368
343
def test_lazy_import_get_module(self):
369
344
a_registry = registry.Registry()
370
a_registry.register_lazy('obj', "breezy.tests.test_registry",
345
a_registry.register_lazy('obj', "bzrlib.tests.test_registry",
372
self.assertEqual("breezy.tests.test_registry",
347
self.assertEquals("bzrlib.tests.test_registry",
373
348
a_registry._get_module("obj"))
375
350
def test_normal_get_module(self):
378
353
a_registry = registry.Registry()
379
354
a_registry.register("obj", AThing())
380
self.assertEqual("breezy.tests.test_registry",
355
self.assertEquals("bzrlib.tests.test_registry",
381
356
a_registry._get_module("obj"))