コード例 #1
0
    def test__connect_socket_error(self, mock_connect):
        """test socket connection with socket error."""
        mock_connect.side_effect = socket.error

        test_inst = pyinst.SocketInstrument('192.168.1.11', '5050')

        with self.assertRaises(pyinst.SocketInstrumentError):
            test_inst._connect_socket()
コード例 #2
0
    def test__connect_socket(self, mock_connect):
        """test socket connection normal completion."""
        mock_connect.return_value.recv.return_value = b'Dummy Instrument\n'

        test_inst = pyinst.SocketInstrument('192.168.1.11', '5050')
        test_inst._connect_socket()

        mock_connect.assert_called_with(('192.168.1.11', '5050'), timeout=120)
コード例 #3
0
    def test__recv_timeout(self):
        """test recv function with timeout."""
        test_inst = pyinst.SocketInstrument('192.168.1.11', '5050')

        test_inst._socket = Mock()
        test_inst._socket.recv.side_effect = socket.timeout

        with self.assertRaises(pyinst.SocketInstrumentError):
            test_inst._recv()
コード例 #4
0
    def test__send_error(self):
        """test send function with error."""
        test_inst = pyinst.SocketInstrument('192.168.1.11', '5050')

        test_inst._socket = Mock()
        test_inst._socket.sendall.side_effect = socket.error

        with self.assertRaises(pyinst.SocketInstrumentError):
            test_inst._send('TestCommand')
コード例 #5
0
    def test__send(self):
        """test send function with normal completion."""
        test_inst = pyinst.SocketInstrument('192.168.1.11', '5050')

        test_inst._socket = Mock()

        test_inst._send('TestCommand')

        test_inst._socket.sendall.assert_called_with(b'TestCommand\n')
コード例 #6
0
    def test__recv(self):
        """test recv function with normal completion."""
        test_inst = pyinst.SocketInstrument('192.168.1.11', '5050')

        test_inst._socket = Mock()
        test_inst._socket.recv.return_value = b'TestResponse\n'

        mock_resp = test_inst._recv()

        self.assertEqual(mock_resp, 'TestResponse')
コード例 #7
0
    def test__close_socket(self, mock_connect):
        """test socket close normal completion."""
        mock_connect.return_value.recv.return_value = b'Dummy Instrument\n'

        test_inst = pyinst.SocketInstrument('192.168.1.11', '5050')
        test_inst._connect_socket()
        test_inst._close_socket()

        mock_connect.return_value.shutdown.assert_called_with(socket.SHUT_RDWR)
        mock_connect.return_value.close.assert_called_with()
コード例 #8
0
    def test__query(self):
        """test query function with normal completion."""
        test_inst = pyinst.SocketInstrument('192.168.1.11', '5050')

        test_inst._socket = Mock()
        test_inst._socket.recv.return_value = b'TestResponse\n'

        mock_resp = test_inst._query('TestCommand')

        test_inst._socket.sendall.assert_called_with(b'TestCommand;*OPC?\n')
        self.assertEqual(mock_resp, 'TestResponse')