Beispiel #1
0
    def test_only_one_instance_of_the_bus(self):
        bus_a = Bus.get_or_create('bus_a')
        bus_b = Bus.get_bus('bus_a')
        bus_c = Bus.get_or_create('bus_c')
        bus_d = Bus()

        assert bus_a is bus_b
        assert bus_a is not bus_c
        assert bus_d is not bus_a
Beispiel #2
0
    def test_only_one_instance_of_the_bus(self):
        bus_a = Bus.get_or_create('bus_a')
        bus_b = Bus.get_bus('bus_a')
        bus_c = Bus.get_or_create('bus_c')
        bus_d = Bus()

        assert bus_a is bus_b
        assert bus_a is not bus_c
        assert bus_d is not bus_a
Beispiel #3
0
 def __init__(self):
     super(ThreadClass3, self).__init__()
     self._should_stop = threading.Event()
     self._is_running = threading.Event()
     self._callback_counter = 0
     self._latest_argument = ""
     self._bus = Bus.get_or_create('bus_a')
Beispiel #4
0
    def test_delete_bus_instances(self):
        bus_x = Bus.get_or_create('bus_x')

        assert bus_x in Bus._instances.values()

        Bus.delete_bus('bus_x')

        assert bus_x not in Bus._instances.values()
Beispiel #5
0
    def test_delete_bus_instances(self):
        bus_x = Bus.get_or_create('bus_x')

        assert bus_x in Bus._instances.values()

        Bus.delete_bus('bus_x')

        assert bus_x not in Bus._instances.values()

        with self.assertRaises(KeyError):
            Bus.delete_bus('bus_x')
Beispiel #6
0
    def test_messages_across_threads_thread_subscribe1(self):
        # in this example we create a thread and then from outside that thread we create a subscription to one of the
        # threads functions
        bus_a = Bus.get_or_create('bus_a')
        new_thread = ThreadClass1()
        new_thread.start()

        bus_a.subscribe('level1a.level2a', new_thread.message_callback)

        # we have subscribed to a parent level thus we should receive this publish
        bus_a.publish('level1a.level2a.level3a', argument="hello")

        #assert self.has_run
        assert new_thread.get_latest_argument() == "hello"
        assert new_thread.get_bus() == bus_a
        assert new_thread.get_latest_counter() == 1

        new_thread.stop()
Beispiel #7
0
    def test_messages_across_threads_thread_publish(self):
        # in this example we create a thread and then from inside that thread we perform a publish which eventuates
        # in this main thread
        self.reset_test()
        bus_a = Bus.get_or_create('bus_a')
        bus_a.subscribe('level1a.level2a', self.callback)

        new_thread = ThreadClass3()
        new_thread.start()

        while not new_thread.running():
            time.sleep(0.05)
            
        new_thread.stop()

        assert self.has_run
        assert self.argument == "hello from thread"
        assert self.called_bus == bus_a
        assert self.callback_count == 1
Beispiel #8
0
    def test_messages_across_threads_thread_subscribe2(self):
        # in this example we create a thread and then from outside that thread we create a subscription to one of the
        # threads functions
        bus_a = Bus.get_or_create('bus_a')
        new_thread = ThreadClass2()
        new_thread.start()

        while not new_thread.running():
            time.sleep(0.05)

        # we have subscribed to a parent level thus we should receive this publish
        bus_a.publish('level1a.level2a.level3a', argument="hello_there")

        new_thread.stop()

        #assert self.has_run
        assert new_thread.get_latest_argument() == "hello_there"
        assert new_thread.get_bus() == bus_a
        assert new_thread.get_latest_counter() == 1
Beispiel #9
0
    def test_bus_is_not_specific(self):
        bus_y = Bus()
        bus_z = Bus.get_or_create('bus_z')

        assert bus_y is not bus_z
Beispiel #10
0
    def test_get_or_create_only_once(self):
        bus_a = Bus.get_or_create('bus_a')
        bus_b = Bus.get_or_create('bus_a')

        assert bus_a is bus_b
Beispiel #11
0
    def test_bus_is_not_specific(self):
        bus_y = Bus()
        bus_z = Bus.get_or_create('bus_z')

        assert bus_y is not bus_z