Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test-python:

lint-python:
@echo "Linting Python files"
flake8 --exit-zero --ignore=E501 --exclude=.git,compat.py mocket
flake8 --ignore=E501,E731 --exclude=.git,compat.py mocket
@echo ""

develop: install-test-requirements install-dev-requirements
Expand Down
14 changes: 8 additions & 6 deletions mocket/mocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def __init__(self, family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0, deta
self.true_socket = true_socket(family, type, proto)
self.fd = MocketSocketCore()
self._connected = False
self._buflen = 65536
self._buflen = 4096
self._entry = None
self.family = int(family)
self.type = int(type)
Expand Down Expand Up @@ -303,14 +303,16 @@ def true_sendall(self, data, *args, **kwargs):
except KeyError:
self._connect()
self.true_socket.sendall(data, *args, **kwargs)
encoded_response = b''
encoded_response = None
# https://github.com/kennethreitz/requests/blob/master/tests/testserver/server.py#L13
while select.select([self.true_socket], [], [], 0.5)[0]:
while True:
more_to_read = select.select([self.true_socket], [], [], 0.5)[0]
if not more_to_read and encoded_response is not None:
break
recv = self.true_socket.recv(self._buflen)
if recv:
encoded_response += recv
else:
if not recv and encoded_response is not None:
break
encoded_response = encoded_response or b'' + recv

# dump the resulting dictionary to a JSON file
if Mocket.get_truesocket_recording_dir():
Expand Down
21 changes: 13 additions & 8 deletions mocket/mockredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,26 @@ class Redisizer(byte_type):
@staticmethod
def tokens(iterable):
iterable = [encode_to_bytes(x) for x in iterable]
return ['*{0}'.format(len(iterable)).encode('utf-8')] + list(chain(*zip(['${0}'.format(len(x)).encode('utf-8') for x in iterable], iterable)))
return [
'*{0}'.format(len(iterable)).encode('utf-8')
] + list(
chain(*zip(['${0}'.format(len(x)).encode('utf-8') for x in iterable], iterable))
)

@staticmethod
def redisize(data):
def get_conversion(t):
return {
dict: lambda x: b'\r\n'.join(Redisizer.tokens(list(chain(*tuple(x.items()))))),
int: lambda x: ':{0}'.format(x).encode('utf-8'),
text_type: lambda x: '${0}\r\n{1}'.format(len(x.encode('utf-8')), x).encode('utf-8'),
list: lambda x: b'\r\n'.join(Redisizer.tokens(x)),
}[t]
if isinstance(data, Redisizer):
return data
if isinstance(data, byte_type):
data = decode_from_bytes(data)
CONVERSION = {
dict: lambda x: b'\r\n'.join(Redisizer.tokens(list(chain(*tuple(x.items()))))),
int: lambda x: ':{0}'.format(x).encode('utf-8'),
text_type: lambda x: '${0}\r\n{1}'.format(len(x.encode('utf-8')), x).encode('utf-8'),
list: lambda x: b'\r\n'.join(Redisizer.tokens(x)),
}
return Redisizer(CONVERSION[type(data)](data) + b'\r\n')
return Redisizer(get_conversion(data.__class__)(data) + b'\r\n')

@staticmethod
def command(description, _type='+'):
Expand Down
2 changes: 1 addition & 1 deletion mocket/plugins/httpretty/core.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from mocket.compat import text_type, byte_type, decode_from_bytes
from mocket.compat import decode_from_bytes

decode_utf8 = decode_from_bytes
1 change: 0 additions & 1 deletion mocket/plugins/pook_mock_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,3 @@ def mocket_mock_fun(*args, **kwargs):
# mocking pook.mock()
self.pook_mock_fun = self.engine.mock
self.engine.mock = mocket_mock_fun

2 changes: 1 addition & 1 deletion shippable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ python:
- 3.4
- 3.5
- 3.6
- 3.7
#- 3.7
- pypy
- pypy3

Expand Down
1 change: 1 addition & 0 deletions tests/main/test_https.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_json(response):
recording_directory = tempfile.mkdtemp()


@pytest.mark.skipif('os.getenv("SKIP_TRUE_HTTP", False)')
@mocketize(truesocket_recording_dir=recording_directory)
def test_truesendall_with_recording_https():
url = 'https://httpbin.org/ip'
Expand Down