def test_disconnect(self):
        """ disconnect """

        def on_class_loaded(cls):
            """ Called when a class is loaded. """

            on_class_loaded.cls = cls

            return

        # To register with 'MetaHasTraits' we use 'module_name.class_name'.
        hook = ClassLoadHook(
            class_name = ClassLoadHookTestCase.__module__ + '.Foo',
            on_load    = on_class_loaded
        )
        hook.connect()

        class Foo(HasTraits):
            pass

        self.assertEqual(Foo, on_class_loaded.cls)

        # 'Reset' the listener,
        on_class_loaded.cls = None

        # Now disconnect.
        hook.disconnect()

        class Foo(HasTraits):
            pass

        self.assertEqual(None, on_class_loaded.cls)

        return
Esempio n. 2
0
    def test_class_already_loaded(self):
        """ class already loaded """
        def on_class_loaded(cls):
            """ Called when a class is loaded. """

            on_class_loaded.cls = cls

        # To register with 'MetaHasTraits' we use 'module_name.class_name'.
        hook = ClassLoadHook(
            class_name=self._get_full_class_name(ClassLoadHookTestCase),
            on_load=on_class_loaded,
        )
        hook.connect()

        # Make sure the 'on_load' got called immediately because the class is
        # already loaded.
        self.assertEqual(ClassLoadHookTestCase, on_class_loaded.cls)
Esempio n. 3
0
    def test_connect(self):
        """ connect """
        def on_class_loaded(cls):
            """ Called when a class is loaded. """

            on_class_loaded.cls = cls

        # To register with 'MetaHasTraits' we use 'module_name.class_name'.
        hook = ClassLoadHook(
            class_name=ClassLoadHookTestCase.__module__ + ".Foo",
            on_load=on_class_loaded,
        )
        hook.connect()

        class Foo(HasTraits):
            pass

        self.assertEqual(Foo, on_class_loaded.cls)
Esempio n. 4
0
        class PluginA(Plugin):
            id = 'A'

            class_load_hooks = List([
                ClassLoadHook(
                    class_name=CorePluginTestCase.__module__ + '.Baz',
                    on_load=on_class_loaded,
                )
            ],
                                    contributes_to='envisage.class_load_hooks')
Esempio n. 5
0
        class PluginA(Plugin):
            id = "A"

            class_load_hooks = List(
                [
                    ClassLoadHook(
                        class_name=CorePluginTestCase.__module__ + ".Baz",
                        on_load=on_class_loaded,
                    )
                ],
                contributes_to="envisage.class_load_hooks",
            )
    def test_disconnect(self):
        """ disconnect """

        def on_class_loaded(cls):
            """ Called when a class is loaded. """

            on_class_loaded.cls = cls

            return

        # To register with 'MetaHasTraits' we use 'module_name.class_name'.
        hook = ClassLoadHook(
            class_name=ClassLoadHookTestCase.__module__ + '.Foo',
            on_load=on_class_loaded)
        hook.connect()

        class Foo(HasTraits):
            pass

        self.assertEqual(Foo, on_class_loaded.cls)

        # 'Reset' the listener,
        on_class_loaded.cls = None

        # Now disconnect.
        hook.disconnect()

        class Foo(HasTraits):
            pass

        self.assertEqual(None, on_class_loaded.cls)

        return
    def test_class_already_loaded(self):
        """ class already loaded """

        def on_class_loaded(cls):
            """ Called when a class is loaded. """

            on_class_loaded.cls = cls

            return

        # To register with 'MetaHasTraits' we use 'module_name.class_name'.
        hook = ClassLoadHook(
            class_name = self._get_full_class_name(ClassLoadHookTestCase),
            on_load    = on_class_loaded
        )
        hook.connect()

        # Make sure the 'on_load' got called immediately because the class is
        # already loaded.
        self.assertEqual(ClassLoadHookTestCase, on_class_loaded.cls)

        return