Пример #1
0
 def create(cls, name):
     """
     Creates an mGui.events.Event object with the supplied name. If the named Event already exists, return it.
     :param name: string name of the new Event
     :return: mGui.events.Event object
     """
     if not name in cls.REGISTRY:
         cls.REGISTRY[name] = events.Event()
     return cls.REGISTRY[name]
Пример #2
0
    def test_basic_event(self):
        sample_data = []

        def handle(*args, **kwargs):
            sample_data.append("OK")

        test = events.Event()
        test += handle
        test()
        assert "OK" in sample_data
Пример #3
0
    def test_bound_derefencing(self):
        sample_data = []
        b = self.bound_tester()

        test = events.Event()
        test += b.example
        test()
        assert "OK" in self.bound_tester.DATA
        test -= b.example
        self.bound_tester.DATA.remove("OK")
        test()
        assert not "OK" in self.bound_tester.DATA
Пример #4
0
    def test_derefencing(self):
        sample_data = []

        def handle(*args, **kwargs):
            sample_data.append("OK")

        test = events.Event()
        test += handle
        test()
        assert "OK" in sample_data
        test -= handle
        sample_data.remove("OK")
        test()
Пример #5
0
    def test_stash(self):
        sample_data = []

        def handle(*args, **kwargs):
            sample_data.append('OK')

        class Stash(object):
            pass

        stash = Stash()

        test = events.Event()
        test += handle, stash
        del handle
        test()
        assert 'OK' in sample_data
Пример #6
0
    def test_stash_derefencing(self):
        sample_data = []

        def handle(*args, **kwargs):
            sample_data.append('OK')

        handle_id = id(handle)

        class Stash(object):
            pass

        stash = Stash()

        test = events.Event()
        test += handle, stash
        del handle
        test()
        assert 'OK' in sample_data
        handle = getattr(stash, '_sh_{}'.format(handle_id))
        sample_data = []
        test -= handle, stash
        test()
        assert 'OK' not in sample_data