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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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

            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