Exemple #1
0
    def test_protocol(self):
        ext_reg = ExtensionRegistry()

        a_obj = A()

        def b_loader(ext):
            return B(name=ext.name)

        a_ext = ext_reg.add_extension(component=a_obj, point='A', name='test')
        b_ext = ext_reg.add_extension(loader=b_loader, point='B', name='test')

        self.assertEqual(True, ext_reg.has_extension('A', 'test'))
        self.assertIsInstance(a_ext, Extension)
        self.assertEqual('test', a_ext.name)
        self.assertEqual('A', a_ext.point)
        self.assertEqual(False, a_ext.is_lazy)
        self.assertIs(a_obj, a_ext.component)
        self.assertIs(a_obj, a_ext.component)
        self.assertIs(a_obj, ext_reg.get_component('A', 'test'))
        self.assertIs(a_ext, ext_reg.get_extension('A', 'test'))

        self.assertEqual(True, ext_reg.has_extension('B', 'test'))
        self.assertIsInstance(b_ext, Extension)
        self.assertEqual('test', b_ext.name)
        self.assertEqual('B', b_ext.point)
        self.assertEqual(True, b_ext.is_lazy)
        b_obj = b_ext.component
        self.assertIs(b_obj, b_ext.component)
        self.assertIs(b_obj, ext_reg.get_component('B', 'test'))
        self.assertIs(b_ext, ext_reg.get_extension('B', 'test'))
        self.assertEqual({'name': 'test'}, b_obj.kwargs)

        self.assertEqual([a_ext], ext_reg.find_extensions('A'))
        self.assertEqual([b_ext], ext_reg.find_extensions('B'))
        self.assertEqual([], ext_reg.find_extensions('C'))

        self.assertEqual([a_obj], ext_reg.find_components('A'))
        self.assertEqual([b_obj], ext_reg.find_components('B'))
        self.assertEqual([], ext_reg.find_components('C'))

        ext_reg.remove_extension('A', 'test')
        self.assertEqual(False, ext_reg.has_extension('A', 'test'))

        ext_reg.remove_extension('B', 'test')
        self.assertEqual(False, ext_reg.has_extension('B', 'test'))
Exemple #2
0
 def test_get_extension_illegal(self):
     ext_reg = ExtensionRegistry()
     self.assertEqual(False, ext_reg.has_extension('A', 'test'))
     self.assertEqual(None, ext_reg.get_extension('A', 'test'))