/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_registry.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-08 23:30:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170608233031-3qavls2o7a1pqllj
Update imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
    )
28
28
 
29
29
 
30
 
 
31
30
class TestRegistry(tests.TestCase):
32
31
 
33
32
    def register_stuff(self, a_registry):
83
82
        a_registry.register('one', 'one')
84
83
        self.assertRaises(KeyError, a_registry.register, 'one', 'two')
85
84
        self.assertRaises(KeyError, a_registry.register, 'one', 'two',
86
 
                          override_existing=False)
 
85
                                    override_existing=False)
87
86
 
88
87
        a_registry.register('one', 'two', override_existing=True)
89
88
        self.assertEqual('two', a_registry.get('one'))
104
103
 
105
104
        # We should be able to handle a callable to get information
106
105
        help_calls = []
107
 
 
108
106
        def generic_help(reg, key):
109
107
            help_calls.append(key)
110
108
            return 'generic help for %s' % (key,)
146
144
                          ('six', 'this is my help'),
147
145
                          ('three', 'generic help for three'),
148
146
                          ('two', 'help text for two'),
149
 
                          ], sorted((key, a_registry.get_help(key))
 
147
                         ], sorted((key, a_registry.get_help(key))
150
148
                                    for key in a_registry.keys()))
151
149
 
152
150
        # We don't know what order it was called in, but we should get
186
184
                          ('one', 'string info'),
187
185
                          ('three', ['a', 'list']),
188
186
                          ('two', 2),
189
 
                          ], sorted((key, a_registry.get_info(key))
 
187
                         ], sorted((key, a_registry.get_info(key))
190
188
                                    for key in a_registry.keys()))
191
189
 
192
190
    def test_get_prefix(self):
203
201
        self.assertEqual('//baz/qux', suffix)
204
202
        self.assertIs(sftp_object, found_object)
205
203
 
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'),
213
 
                         a_registry.get_help('two'))
214
 
        self.assertEqual(a_registry.get_info('one'),
215
 
                         a_registry.get_info('two'))
216
 
        self.assertEqual('own info', a_registry.get_info('three'))
217
 
        self.assertEqual({'two': 'one', 'three': 'one'}, a_registry.aliases())
218
 
        self.assertEqual(
219
 
            {'one': ['three', 'two']},
220
 
            {k: sorted(v) for (k, v) in a_registry.alias_map().items()})
221
 
 
222
 
    def test_registry_alias_exists(self):
223
 
        a_registry = registry.Registry()
224
 
        a_registry.register('one', 1, info='string info')
225
 
        a_registry.register('two', 2)
226
 
        self.assertRaises(KeyError, a_registry.register_alias, 'one', 'one')
227
 
 
228
 
    def test_registry_alias_targetmissing(self):
229
 
        a_registry = registry.Registry()
230
 
        self.assertRaises(KeyError, a_registry.register_alias, 'one', 'two')
231
 
 
232
204
 
233
205
class TestRegistryIter(tests.TestCase):
234
206
    """Test registry iteration behaviors.
246
218
        _registry = registry.Registry()
247
219
 
248
220
        def register_more():
249
 
            _registry.register('hidden', None)
 
221
           _registry.register('hidden', None)
250
222
 
251
223
        # Avoid closing over self by binding local variable
252
224
        self.registry = _registry
300
272
        """
301
273
        os.mkdir('tmp')
302
274
        plugin_name = 'bzr_plugin_a_%s' % (osutils.rand_chars(4),)
303
 
        with open('tmp/' + plugin_name + '.py', 'wb') as f:
304
 
            f.write(contents)
 
275
        with open('tmp/'+plugin_name+'.py', 'wb') as f: f.write(contents)
305
276
        return plugin_name
306
277
 
307
278
    def create_simple_plugin(self):
308
279
        return self.create_plugin_file(
309
 
            b'object1 = "foo"\n'
310
 
            b'\n\n'
311
 
            b'def function(a,b,c):\n'
312
 
            b'    return a,b,c\n'
313
 
            b'\n\n'
314
 
            b'class MyClass(object):\n'
315
 
            b'    def __init__(self, a):\n'
316
 
            b'      self.a = a\n'
317
 
            b'\n\n'
 
280
            'object1 = "foo"\n'
 
281
            '\n\n'
 
282
            'def function(a,b,c):\n'
 
283
            '    return a,b,c\n'
 
284
            '\n\n'
 
285
            'class MyClass(object):\n'
 
286
            '    def __init__(self, a):\n'
 
287
            '      self.a = a\n'
 
288
            '\n\n'
318
289
        )
319
290
 
320
291
    def test_lazy_import_registry_foo(self):
372
343
    def test_lazy_import_get_module(self):
373
344
        a_registry = registry.Registry()
374
345
        a_registry.register_lazy('obj', "breezy.tests.test_registry",
375
 
                                 'object1')
 
346
            'object1')
376
347
        self.assertEqual("breezy.tests.test_registry",
377
 
                         a_registry._get_module("obj"))
 
348
            a_registry._get_module("obj"))
378
349
 
379
350
    def test_normal_get_module(self):
380
351
        class AThing(object):
382
353
        a_registry = registry.Registry()
383
354
        a_registry.register("obj", AThing())
384
355
        self.assertEqual("breezy.tests.test_registry",
385
 
                         a_registry._get_module("obj"))
 
356
            a_registry._get_module("obj"))