fixing tests

This commit is contained in:
Gabriel Falcao
2013-03-24 19:58:17 -04:00
parent 0aa349c52a
commit 6ea5d7311c
2 changed files with 11 additions and 4 deletions

View File

@@ -130,4 +130,4 @@ def test_using_httpretty_with_other_tcp_protocols(context):
expect(got1).to.equal(b'BAR')
expect(context.client.send("foobar")).to.equal("RECEIVED: foobar")
expect(context.client.send("foobar")).to.equal(b"RECEIVED: foobar")

View File

@@ -27,6 +27,7 @@
from __future__ import unicode_literals
import os
import sys
try:
import io
@@ -45,6 +46,11 @@ from multiprocessing import Process
true_socket = socket.socket
PY3 = sys.version_info[0] == 3
if not PY3:
bytes = lambda s, *args: str(s)
class BubblesHandler(RequestHandler):
def get(self):
@@ -111,7 +117,7 @@ class TCPServer(object):
while True:
data = conn.recv(1024)
conn.send("RECEIVED: " + data)
conn.send(b"RECEIVED: " + bytes(data))
conn.close()
@@ -136,8 +142,9 @@ class TCPClient(object):
self.sock.connect(('localhost', self.port))
def send(self, what):
self.sock.sendall(str(what))
return self.sock.recv(len(what) + 11)
data = bytes(what, 'utf-8')
self.sock.sendall(data)
return self.sock.recv(len(data) + 11)
def close(self):
try: