def test_getCommand(self):
     """Test wether getting commands from the network works.
        Sends command through TCP/IP and check wether the same command is received on the other end."""
     self.assertTrue(self.communicator.wait_listen(2), "Communicator not listening")
     CommandSocket = ThreadedSocket('localhost', self.testport, giveup=0, retry_timeout=0.1)
     self.assertTrue(CommandSocket.wait_connect(4), "Could not connect to communicator")
     CommandSocket.send(self.TestCommand)
     time.sleep(0.1) # Wait a bit for the socket to be available
     received, conn_id = self.communicator.get_command()
     self.assertEqual(received, self.TestCommand) #,"Oh no, we received something else than we sent!")
示例#2
0
 def test_getCommand(self):
     """Test wether getting commands from the network works.
        Sends command through TCP/IP and check wether the same command is received on the other end."""
     self.assertTrue(self.communicator.wait_listen(2),
                     "Communicator not listening")
     CommandSocket = ThreadedSocket('localhost',
                                    self.testport,
                                    giveup=0,
                                    retry_timeout=0.1)
     self.assertTrue(CommandSocket.wait_connect(4),
                     "Could not connect to communicator")
     CommandSocket.send(self.TestCommand)
     time.sleep(0.1)  # Wait a bit for the socket to be available
     received, conn_id = self.communicator.get_command()
     self.assertEqual(
         received, self.TestCommand
     )  #,"Oh no, we received something else than we sent!")
示例#3
0
    def test_send_command(self):
        # Set up test communicator
        comm_s = None
        mod_s = None
        client = None
        try:
            #comm_s = ThreadedSocket("", self.communicatorPort)
            comm_s = ThreadedSocket("", "communicator")
            self.assertTrue(comm_s.wait_listen(),
                            "Fake Communicator socket did not open")

            self.config.add_option("vision_controller", "modules",
                                   "localhost = mod1")
            self.config.add_option("vision_controller", "modules_settings",
                                   "mod1 = test")
            self.controller = visioncontroller.VisionController()
            self.controller.set_config(self.config)

            # On the fake communicator, receive the module to start and the port
            # to start it on, because we need that port to connect to.
            client = comm_s.wait_connect()
            self.assertTrue(client != None, "Did not get a connection")

            recv = client.wait_data()
            self.assertTrue(recv, "Did not receive any data")

            port = None
            for i in recv:
                if "port" in i:
                    port = i['port']

            self.assertTrue(port != None,
                            "Did not receive a port number to connect to")

            # Set up a connection to the port specified by the vision
            # controller, it should be listening on that by now.
            mod_s = ThreadedSocket("localhost", port)
            mod_s.start()
            self.assertTrue(mod_s.wait_connect(),
                            "Fake vision module did not connect")

            # First receive the send_capabilities command that should be send
            # automatically.
            recv = mod_s.wait_data()
            self.assertEquals(len(recv), 1, "Should have received one command")
            data = recv[0]
            self.assertTrue(
                "command" in data,
                "There should be a command in the received dictionary")
            self.assertEquals(data["command"], "send_capabilities",
                              "Testcommand should be send_capabilities")
            self.assertTrue(
                "params" in data,
                "There should be command parameters in the received dictionary"
            )
            self.assertEquals(data["params"], {},
                              "Test parameters should be an empty dictionary")

            # Try sending a test command and receive it
            testCommand = "test_command"
            testParams = {"param1": "test_param"}
            self.controller.send_command("localhost", "mod1", testCommand,
                                         testParams)

            # See if the test command has been received
            recv = mod_s.wait_data()
            self.assertEquals(len(recv), 1, "Should have received one command")
            data = recv[0]
            self.assertTrue(
                "command" in data,
                "There should be a command in the received dictionary")
            self.assertEquals(data["command"], testCommand,
                              "Testcommand should be %s" % testCommand)
            self.assertTrue(
                "params" in data,
                "There should be command parameters in the received dictionary"
            )
            self.assertEquals(
                data["params"], testParams,
                "Test parameters should be %s" % repr(testParams))

        finally:
            if comm_s:
                comm_s.close()
            if mod_s:
                mod_s.close()
            if client:
                client.close()
            self.controller.stop_connections()
    def test_send_command(self):
        # Set up test communicator
        comm_s = None
        mod_s = None
        client = None
        try:
            #comm_s = ThreadedSocket("", self.communicatorPort)
            comm_s = ThreadedSocket("", "communicator")
            self.assertTrue(comm_s.wait_listen(), "Fake Communicator socket did not open")
            
            self.config.add_option("vision_controller", "modules", "localhost = mod1")
            self.config.add_option("vision_controller", "modules_settings", "mod1 = test")
            self.controller = visioncontroller.VisionController()
            self.controller.set_config(self.config)

            # On the fake communicator, receive the module to start and the port
            # to start it on, because we need that port to connect to.
            client = comm_s.wait_connect()
            self.assertTrue(client != None, "Did not get a connection")
            
            recv = client.wait_data()
            self.assertTrue(recv, "Did not receive any data")

            port = None
            for i in recv:
                if "port" in i:
                    port = i['port']
            
            self.assertTrue(port != None, "Did not receive a port number to connect to")

            # Set up a connection to the port specified by the vision
            # controller, it should be listening on that by now.
            mod_s = ThreadedSocket("localhost", port)
            mod_s.start()
            self.assertTrue(mod_s.wait_connect(), "Fake vision module did not connect")

            # First receive the send_capabilities command that should be send
            # automatically.
            recv = mod_s.wait_data()
            self.assertEquals(len(recv), 1, "Should have received one command")
            data = recv[0]
            self.assertTrue("command" in data, "There should be a command in the received dictionary")
            self.assertEquals(data["command"], "send_capabilities", "Testcommand should be send_capabilities")
            self.assertTrue("params" in data, "There should be command parameters in the received dictionary")
            self.assertEquals(data["params"], {}, "Test parameters should be an empty dictionary")

            # Try sending a test command and receive it
            testCommand = "test_command"
            testParams = {"param1": "test_param"}
            self.controller.send_command("localhost", "mod1", testCommand, testParams)

            # See if the test command has been received
            recv = mod_s.wait_data()
            self.assertEquals(len(recv), 1, "Should have received one command")
            data = recv[0]
            self.assertTrue("command" in data, "There should be a command in the received dictionary")
            self.assertEquals(data["command"], testCommand, "Testcommand should be %s" % testCommand)
            self.assertTrue("params" in data, "There should be command parameters in the received dictionary")
            self.assertEquals(data["params"], testParams, "Test parameters should be %s" % repr(testParams))

        finally:
            if comm_s:
                comm_s.close()
            if mod_s:
                mod_s.close()
            if client:
                client.close()
            self.controller.stop_connections()