Exemplo n.º 1
0
 def setUp(self):
     self.server = MessageBusServer(port=TESTPORT)
     self.messageBus = MessageBusClient()
     self.messageBus.connectToServer("localhost", TESTPORT)
     self.process()
     self.assertEqual(len(self.server.clients), 1, "At least one client should be connected")
     self.assertTrue(self.messageBus.isConnected(), "MessageBus is not connected")
Exemplo n.º 2
0
class TestMessageBus(unittest.TestCase):

    server = None

    def setUp(self):
        self.server = MessageBusServer(port=TESTPORT)
        self.messageBus = MessageBusClient()
        self.messageBus.connectToServer("localhost", TESTPORT)
        self.process()
        self.assertEqual(len(self.server.clients), 1, "At least one client should be connected")
        self.assertTrue(self.messageBus.isConnected(), "MessageBus is not connected")

    def tearDown(self):
        self.messageBus.disconnectFromServer()
        self.messageBus = None
        del self.server.server
        del self.server
        self.server = None

    def process(self):
        for i in range(10):
            app.processEvents()
            self.messageBus.connection.waitForBytesWritten()
            for client in self.server.clients:
                client.connection.waitForBytesWritten()
            time.sleep(0.02)
            app.processEvents()
        pass

    def testPublish(self):
        # Assert
        self.messageBus.publishEvent('topic', [1]*20)

    def testSubscribe(self):
        """
        Ensure that subscription callback is handled correctly
        """
        # Arrange
        expected = ["This", "is", "just", 1, "Test"]

        # Assert
        def assertion(result):
            setattr(assertion, 'wasCalled', True)
            self.assertListEqual(result, expected, "Unexpected: %s != %s" % (result, expected))
        setattr(assertion, 'wasCalled', False)

        # Act
        self.messageBus.subscribe('topic', assertion)
        self.process()
        self.messageBus.publishEvent('topic', expected)
        self.process()

        self.assertTrue(assertion.wasCalled, "Assertion has not been called")
Exemplo n.º 3
0
        self.push(np=np, mbus=mbus,
                  subscribe=self.subscribe)

    def handleNewData(self, topic, data):
        self.push(data=data)

    def subscribe(self, topic):
        self.mbus.subscribe(topic, self.handleNewData)

    def push(self, **kwargs):
        self._console.kernel_manager.kernel.shell.push(kwargs)


if __name__ == "__main__":
    import argparse
    from qao.io.messageBus import MessageBusClient
    parser = argparse.ArgumentParser(description="Messagebus IPython Plugin")
    parser.add_argument("-host", type=str, help="Host", default="localhost")
    parser.add_argument("-port", type=int, help="Port", default=9090)

    args = parser.parse_args()

    mbus = MessageBusClient()
    mbus.connectToServer(args.host, args.port)

    args = parser.parse_args()
    app = QtWidgets.QApplication([])

    win = Main(mbus)
    win.show()
    app.exec_()