22
22
from bzrlib import (
30
class TestRegistry(tests.TestCase):
27
from bzrlib.tests import TestCase, TestCaseInTempDir
30
class TestRegistry(TestCase):
32
32
def register_stuff(self, a_registry):
33
33
a_registry.register('one', 1)
202
202
self.assertIs(sftp_object, found_object)
205
class TestRegistryIter(tests.TestCase):
206
"""Test registry iteration behaviors.
208
There are dark corner cases here when the registered objects trigger
209
addition in the iterated registry.
213
super(TestRegistryIter, self).setUp()
215
# We create a registry with "official" objects and "hidden"
216
# objects. The later represent the side effects that led to bug #277048
218
self.registry = registry.Registry()
221
self.registry.register('hidden', None)
223
self.registry.register('passive', None)
224
self.registry.register('active', register_more)
225
self.registry.register('passive-too', None)
227
class InvasiveGetter(registry._ObjectGetter):
229
def get_obj(inner_self):
230
# Surprise ! Getting a registered object (think lazy loaded
231
# module) register yet another object !
232
self.registry.register('more hidden', None)
233
return inner_self._obj
235
self.registry.register('hacky', None)
236
# We peek under the covers because the alternative is to use lazy
237
# registration and create a module that can reference our test registry
238
# it's too much work for such a corner case -- vila 090916
239
self.registry._dict['hacky'] = InvasiveGetter(None)
241
def _iter_them(self, iter_func_name):
242
iter_func = getattr(self.registry, iter_func_name, None)
243
self.assertIsNot(None, iter_func)
245
for name, func in iter_func():
247
self.assertFalse(name in ('hidden', 'more hidden'))
249
# Using an object register another one as a side effect
251
self.assertEqual(4, count)
253
def test_iteritems(self):
254
# the dict is modified during the iteration
255
self.assertRaises(RuntimeError, self._iter_them, 'iteritems')
257
def test_items(self):
258
# we should be able to iterate even if one item modify the dict
259
self._iter_them('items')
262
class TestRegistryWithDirs(tests.TestCaseInTempDir):
205
class TestRegistryWithDirs(TestCaseInTempDir):
263
206
"""Registry tests that require temporary dirs"""
265
208
def create_plugin_file(self, contents):