예제 #1
0
파일: test_utils.py 프로젝트: mcclurmc/juju
    def test_listen_on_connect_returns(self):
        """On a successful connect, the function returns None."""
        mock_socket = self.mocker.patch(socket.socket)
        mock_socket.bind(("127.0.0.1", 800))
        self.mocker.result(True)
        mock_socket.close()

        self.mocker.replay()
        watcher = PortWatcher("127.0.0.1", 800, 30, True)
        self.assertEqual(watcher.sync_wait(), True)
예제 #2
0
파일: test_utils.py 프로젝트: mcclurmc/juju
    def test_listen_on_connect_returns(self):
        """On a successful connect, the function returns None."""
        mock_socket = self.mocker.patch(socket.socket)
        mock_socket.bind(("127.0.0.1", 800))
        self.mocker.result(True)
        mock_socket.close()

        self.mocker.replay()
        watcher = PortWatcher("127.0.0.1", 800, 30, True)
        self.assertEqual(watcher.sync_wait(), True)
예제 #3
0
파일: test_utils.py 프로젝트: mcclurmc/juju
    def test_wait_stops_when_watcher_stopped(self):
        """
        If the watcher is stopped, no more attempts are made to attempt
        connect to the socket.
        """
        watcher = PortWatcher("127.0.0.1", 800, 30)

        mock_socket = self.mocker.patch(socket.socket)
        sleep = self.mocker.replace("time.sleep")

        mock_socket.connect(("127.0.0.1", 800))
        self.mocker.throw(socket.error(errno.ECONNREFUSED))
        sleep(0.5)
        self.mocker.call(watcher.stop)
        self.mocker.replay()
        self.assertEquals(watcher.sync_wait(), None)
예제 #4
0
파일: test_utils.py 프로젝트: mcclurmc/juju
    def test_wait_stops_when_watcher_stopped(self):
        """
        If the watcher is stopped, no more attempts are made to attempt
        connect to the socket.
        """
        watcher = PortWatcher("127.0.0.1", 800, 30)

        mock_socket = self.mocker.patch(socket.socket)
        sleep = self.mocker.replace("time.sleep")

        mock_socket.connect(("127.0.0.1", 800))
        self.mocker.throw(socket.error(errno.ECONNREFUSED))
        sleep(0.5)
        self.mocker.call(watcher.stop)
        self.mocker.replay()
        self.assertEquals(watcher.sync_wait(), None)