Ejemplo n.º 1
0
    def test_registry(self):

        from zope.interface import Interface, implementer
        from aiorm import registry

        class IAdaptable(Interface):
            pass

        class IAdapter(Interface):
            pass

        class IAdapter2(Interface):
            pass

        @implementer(IAdaptable)
        class Adaptable:
            pass

        @implementer(IAdapter)
        class Adapter:
            pass

        @implementer(IAdapter2)
        class Adapter2:
            pass

        self.assertRaises(NotImplementedError, registry.get, IAdapter)
        registry.register(Adapter, adapt=IAdaptable)  # introspect iface
        self.assertRaises(ValueError,
                          registry.register, Adapter, adapt=IAdaptable)
        registry.register(Adaptable, IAdaptable, adapt=IAdaptable) # explicit
        registry.register(Adapter2, adapt=Adaptable)

        # 3 "types" accepted for the adapt parameter
        self.assertEqual(registry.get(IAdapter, adapt=IAdaptable), Adapter)
        self.assertEqual(registry.get(IAdapter, adapt=Adaptable), Adapter)
        self.assertEqual(registry.get(IAdapter, adapt=Adaptable()), Adapter)

        self.assertEqual(registry.get(IAdaptable, adapt=IAdaptable), Adaptable)
        self.assertEqual(registry.get(IAdaptable, adapt=Adaptable), Adaptable)

        registry.unregister(Adapter, IAdaptable)
        self.assertRaises(NotImplementedError,
                          registry.get, IAdapter, adapt=IAdaptable)
        registry.unregister(Adapter)
        registry.unregister(Adapter2)
Ejemplo n.º 2
0
    def test_registry(self):

        from zope.interface import Interface, implementer
        from aiorm import registry

        class IAdaptable(Interface):
            pass

        class IAdapter(Interface):
            pass

        class IAdapter2(Interface):
            pass

        @implementer(IAdaptable)
        class Adaptable:
            pass

        @implementer(IAdapter)
        class Adapter:
            pass

        @implementer(IAdapter2)
        class Adapter2:
            pass

        self.assertRaises(NotImplementedError, registry.get, IAdapter)
        registry.register(Adapter, adapt=IAdaptable)  # introspect iface
        self.assertRaises(ValueError, registry.register, Adapter, adapt=IAdaptable)
        registry.register(Adaptable, IAdaptable, adapt=IAdaptable)  # explicit
        registry.register(Adapter2, adapt=Adaptable)

        # 3 "types" accepted for the adapt parameter
        self.assertEqual(registry.get(IAdapter, adapt=IAdaptable), Adapter)
        self.assertEqual(registry.get(IAdapter, adapt=Adaptable), Adapter)
        self.assertEqual(registry.get(IAdapter, adapt=Adaptable()), Adapter)

        self.assertEqual(registry.get(IAdaptable, adapt=IAdaptable), Adaptable)
        self.assertEqual(registry.get(IAdaptable, adapt=Adaptable), Adaptable)

        registry.unregister(Adapter, IAdaptable)
        self.assertRaises(NotImplementedError, registry.get, IAdapter, adapt=IAdaptable)
        registry.unregister(Adapter)
        registry.unregister(Adapter2)
Ejemplo n.º 3
0
 def tearDown(self):
     registry.unregister(DummyDialect)
     DummyDialect._instance = None
Ejemplo n.º 4
0
 def tearDownClass(cls):
     registry.unregister(DummyDriver)
Ejemplo n.º 5
0
 def aioTearDown(self):
     from aiorm import registry
     from aiorm.orm.dialect.postgresql import Dialect, CreateTableDialect
     registry.unregister(Dialect)
     registry.unregister(CreateTableDialect)
     yield from registry.disconnect('sample')
Ejemplo n.º 6
0
 def aioTearDown(self):
     from aiorm import registry
     from aiorm.orm.dialect.postgresql import Dialect, CreateTableDialect
     registry.unregister(Dialect)
     registry.unregister(CreateTableDialect)
     yield from registry.disconnect('sample')
Ejemplo n.º 7
0
 def tearDownClass(cls):
     registry.unregister(DummyDriver)