Skip to content
Myr

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

3 files+11 added−11 removed

modified:tests/testserver/server.py+1 added-1 removed
3 unmodified lines
456def consume_socket_content(sock, timeout=0.5):7 chunks = 655368 content = ""8 content = b''9 more_to_read = select.select([sock], [], [], timeout)[0]1011 while more_to_read:12 new_content = sock.recv(chunks)
91 unmodified lines
modified:tests/test_lowlevel.py+1 added-1 removed
1import threading2import requests34from testserver.server import Server4from tests.testserver.server import Server567def test_chunked_upload():8 """can safely send generators"""
11 unmodified lines
modified:tests/test_testserver.py+9 added-9 removed
2 unmodified lines
3import time45import pytest6import requests7from testserver.server import Server7from tests.testserver.server import Server89class TestTestServer:10 def test_basic(self):11 """messages are sent and received properly"""
77 unmodified lines
8990 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'9596 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()103104 sock2.connect(address)105 sock2.sendall(second_request.encode())105 sock2.sendall(second_request)106 sock2.close()107108 assert server.handler_results[0] == first_request109 assert server.handler_results[1] == second_request
5 unmodified lines
115 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()121122 assert server.handler_results[0] == ''122 assert server.handler_results[0] == b''123124125 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'129130 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