def test_send(self, mock_socket): with pyboinc.BoincSocket('3323', 1234, 3) as bc: bc.send(b'asdfasdf') mock_socket.assert_called_with(('3323', 1234), timeout=3) mock_socket.return_value.sendall.assert_called_with(b'asdfasdf\x03') mock_socket.return_value.close.assert_called_with()
def test_call_multipart(self, mock_socket): mock_socket.return_value.recv.side_effect = [b'some_', b'data\x03'] with pyboinc.BoincSocket() as bc: expected = b'some_data' result = bc.call(b'<ssddff />') assert expected == result mock_socket.assert_called_with((None, 31416), timeout=None) mock_socket.return_value.sendall.assert_called_with(b'<ssddff/>\x03') mock_socket.return_value.close.assert_called_with()
def test_clean_message(self, mock_socket): bs = pyboinc.BoincSocket() assert b'<a><b/></a>' == bs.clean_message(b'<a><b/></a>') assert b'<a><b/></a>' == bs.clean_message(b'<a><b /></a>') assert b'<a><b/></a>' == bs.clean_message(b'<a><b \t/></a>') assert b'<a><b/></a>' == bs.clean_message(b'<a><b \n\t/></a>')
def test_receive_error(self, mock_socket): mock_socket.return_value.recv.return_value = b'' with pyboinc.BoincSocket() as bc: with pytest.raises(RuntimeError): bc.receive()
def test_receive_multipart(self, mock_socket): mock_socket.return_value.recv.side_effect = [b'some_', b'data\x03'] with pyboinc.BoincSocket() as bc: expected = b'some_data' result = bc.receive() assert expected == result
def test_receive(self, mock_socket): mock_socket.return_value.recv.return_value = b'some_data\x03' with pyboinc.BoincSocket() as bc: expected = b'some_data' result = bc.receive() assert expected == result