Fix tests in python 3
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Braulio Valdivielso Martínez · committed by Braulio Valdivielso Martínez · parent 03743b1 · Browse files · 3 files·+11 added−11 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+11 added−11 removed
- tests:+11 added−11 removed
Provenance
- Commit
b473440- Tree
ef90c79- Author
Braulio Valdivielso Martínez <brlvldvlsmrtnz@gmail.com>- Committer
Braulio Valdivielso Martínez <brlvldvlsmrtnz@gmail.com>- Parent
03743b1
3 files changed+11 added−11 removed
modified:tests/testserver/server.py+1 added-1 removed
3 unmodified lines4 5 6 def consume_socket_content(sock, timeout=0.5):7 chunks = 655368- content = ""8+ content = b''9 more_to_read = select.select([sock], [], [], timeout)[0]10 11 while more_to_read:12 new_content = sock.recv(chunks)91 unmodified linesmodified:tests/test_lowlevel.py+1 added-1 removed
1 import threading2 import requests3 4-from testserver.server import Server4+from tests.testserver.server import Server5 6 7 def test_chunked_upload():8 """can safely send generators"""11 unmodified linesmodified:tests/test_testserver.py+9 added-9 removed
2 unmodified lines3 import time4 5 import pytest6 import requests7-from testserver.server import Server7+from tests.testserver.server import Server8 9 class TestTestServer:10 def test_basic(self):11 """messages are sent and received properly"""77 unmodified lines89 90 def test_request_recovery(self):91 """can check the requests content"""92 server = Server.basic_response_server(requests_to_handle=2)93- first_request = "put your hands up in the air"94- second_request = "put your hand down in the floor"93+ first_request = b'put your hands up in the air'94+ second_request = b'put your hand down in the floor'95 96 with server as address:97 sock1 = socket.socket()98 sock2 = socket.socket()99 100 sock1.connect(address)101- sock1.sendall(first_request.encode())101+ sock1.sendall(first_request)102 sock1.close()103 104 sock2.connect(address)105- sock2.sendall(second_request.encode())105+ sock2.sendall(second_request)106 sock2.close()107 108 assert server.handler_results[0] == first_request109 assert server.handler_results[1] == second_request5 unmodified lines115 with server as address:116 sock = socket.socket()117 sock.connect(address)118 time.sleep(1.5)119- sock.sendall(b"hehehe, not received")119+ sock.sendall(b'hehehe, not received')120 sock.close()121 122- assert server.handler_results[0] == ''122+ assert server.handler_results[0] == b''123 124 125 def test_request_recovery_with_bigger_timeout(self):126 """a biggest timeout can be specified"""127 server = Server.basic_response_server(request_timeout=3)128- data = "bananadine"128+ data = b'bananadine'129 130 with server as address:131 sock = socket.socket() 132 sock.connect(address)133 time.sleep(1.5)134- sock.sendall(data.encode())134+ sock.sendall(data)135 sock.close()136 137 assert server.handler_results[0] == data