Skip to content

Commit

Permalink
Removed dependency on six as the package supports Python 3 only now
Browse files Browse the repository at this point in the history
  • Loading branch information
ntamas authored and lnoor committed Jul 26, 2023
1 parent 771ef83 commit 7be2929
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 42 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ pytest==6.2.4
pytest-cov==2.11.1
pyzmq==22.0.3
requests==2.25.1
six==1.16.0
Werkzeug==2.0.0

1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def read(fname):
maintainer_email='[email protected]',
url='http://github.com/mbr/tinyrpc',
license='MIT',
install_requires=['six'],
extras_require={
'gevent': ['gevent'],
'httpclient': ['requests', 'websocket-client', 'gevent-websocket'],
Expand Down
8 changes: 0 additions & 8 deletions tests/_compat.py

This file was deleted.

3 changes: 1 addition & 2 deletions tests/test_jsonrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import json

import six
import pytest

from tinyrpc import MethodNotFoundError, InvalidRequestError, ServerError, \
Expand Down Expand Up @@ -65,7 +64,7 @@ def prot():
def test_parsing_good_request_samples(prot, data, attrs):
req = prot.parse_request(data)

for k, v in six.iteritems(attrs):
for k, v in attrs.items():
assert getattr(req, k) == v


Expand Down
3 changes: 1 addition & 2 deletions tests/test_msgpackrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-

import msgpack
import six
import pytest

from tinyrpc import InvalidReplyError, MethodNotFoundError
Expand Down Expand Up @@ -48,7 +47,7 @@ def prot():
def test_parsing_good_request_samples(prot, data, attrs):
req = prot.parse_request(data)

for k, v in six.iteritems(attrs):
for k, v in attrs.items():
assert getattr(req, k) == v


Expand Down
18 changes: 6 additions & 12 deletions tests/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-

import pytest
import six

import zmq
import zmq.green
Expand All @@ -20,7 +19,7 @@ def receive_message(self):
return self.messages.pop()

def send_reply(self, context, message):
if not isinstance(message, sid.string_types):
if not isinstance(message, str):
raise TypeError('Message must be str().')
self.clients[context].messages.append(message)

Expand Down Expand Up @@ -60,11 +59,9 @@ def fin():
return ctx


if six.PY3:
# zmq and zmq.green fail on python3
SERVERS=['dummy']
else:
SERVERS=['dummy', 'zmq', 'zmq.green']
# zmq and zmq.green fail on python3
SERVERS=['dummy']

@pytest.fixture(params=SERVERS)
def transport(request, zmq_context, zmq_green_context):
if request.param == 'dummy':
Expand All @@ -86,11 +83,8 @@ def fin():
return (client, server)

SAMPLE_MESSAGES = ['asdf', 'loremipsum' * 1500, '', '\x00', 'b\x00a', '\r\n',
'\n', u'\u1234'.encode('utf8')]
if six.PY3:
BAD_MESSAGES = [b'asdf', b'', 1234, 1.2, None, True, False, ('foo',)]
else:
BAD_MESSAGES = [u'asdf', u'', 1234, 1.2, None, True, False, ('foo',)]
'\n', '\u1234'.encode('utf8')]
BAD_MESSAGES = [b'asdf', b'', 1234, 1.2, None, True, False, ('foo',)]


@pytest.fixture(scope='session',
Expand Down
25 changes: 13 additions & 12 deletions tests/test_wsgi_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import pytest


import six
import gevent
import gevent.queue
import gevent.monkey
from gevent.pywsgi import WSGIServer
import requests

from importlib import reload

from tinyrpc.transports.wsgi import WsgiServerTransport
from tinyrpc.transports.http import HttpPostClientTransport

Expand All @@ -33,7 +34,7 @@ def monkey_patches(request):
aggressive=False)

def fin():
six.moves.reload_module(socket)
reload(socket)

request.addfinalizer(fin)

Expand Down Expand Up @@ -70,21 +71,21 @@ def test_server_supports_post_only(wsgi_server):


@pytest.mark.parametrize(('msg',),
[(six.b('foo'),), (six.b(''),), (six.b('bar'),), (six.b('1234'),), (six.b('{}'),), (six.b('{'),), (six.b('\x00\r\n'),)])
[(b'foo',), (b'',), (b'bar',), (b'1234',), (b'{}',), (b'{',), (b'\x00\r\n',)])
def test_server_receives_messages(wsgi_server, msg):
transport, addr = wsgi_server

def consumer():
context, received_msg = transport.receive_message()
assert received_msg == msg
reply = six.b('reply:') + msg
reply = b'reply:' + msg
transport.send_reply(context, reply)

gevent.spawn(consumer)

r = requests.post(addr, data=msg)

assert r.content == six.b('reply:') + msg
assert r.content == b'reply:' + msg


@pytest.fixture
Expand All @@ -106,20 +107,20 @@ def non_sessioned_client():


@pytest.mark.parametrize(('msg',),
[(six.b('foo'),), (six.b(''),), (six.b('bar'),), (six.b('1234'),), (six.b('{}'),), (six.b('{'),), (six.b('\x00\r\n'),)])
[(b'foo',), (b'',), (b'bar',), (b'1234',), (b'{}',), (b'{',), (b'\x00\r\n',)])
def test_sessioned_http_sessioned_client(wsgi_server, sessioned_client, msg):
transport, addr = wsgi_server

def consumer():
context, received_msg = transport.receive_message()
assert received_msg == msg
reply = six.b('reply:') + msg
reply = b'reply:' + msg
transport.send_reply(context, reply)

gevent.spawn(consumer)

result = sessioned_client.send_message(msg)
assert result == six.b('reply:') + msg
assert result == b'reply:' + msg


@pytest.mark.skip('somehow fails on travis')
Expand All @@ -137,22 +138,22 @@ def test_exhaust_ports(wsgi_server, non_sessioned_client):

def consumer():
context, received_msg = transport.receive_message()
reply = six.b('reply:') + received_msg
reply = b'reply:' + received_msg
transport.send_reply(context, reply)

def send_and_receive(i):
try:
gevent.spawn(consumer)
msg = six.b('msg_%s' % i)
msg = b'msg_%s' % i
result = non_sessioned_client.send_message(msg)
return result == six.b('reply:') + msg
return result == b'reply:' + msg
except Exception as e:
return e

pool = gevent.pool.Pool(500)

with pytest.raises(requests.ConnectionError):
for result in pool.imap_unordered(send_and_receive, six.moves.xrange(55000)):
for result in pool.imap_unordered(send_and_receive, range(55000)):
assert result
if isinstance(result, Exception):
raise result
7 changes: 3 additions & 4 deletions tinyrpc/protocols/msgpackrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
)

import msgpack
import six

from typing import Any, Dict, List, Optional, Tuple, Union, Generator

Expand Down Expand Up @@ -104,7 +103,7 @@ def serialize(self):


def _get_code_and_message(error):
assert isinstance(error, (Exception, six.string_types))
assert isinstance(error, (Exception, str))
if isinstance(error, Exception):
if hasattr(error, "msgpackrpc_error_code"):
code = error.msgpackrpc_error_code
Expand Down Expand Up @@ -390,7 +389,7 @@ def parse_request(self, data: bytes) -> "MSGPACKRPCRequest":
raise MSGPACKRPCInvalidRequestError()

def _parse_notification(self, req):
if not isinstance(req[1], six.string_types):
if not isinstance(req[1], str):
raise MSGPACKRPCInvalidRequestError()

request = MSGPACKRPCRequest()
Expand All @@ -408,7 +407,7 @@ def _parse_notification(self, req):
return request

def _parse_request(self, req):
if not isinstance(req[2], six.string_types):
if not isinstance(req[2], str):
raise MSGPACKRPCInvalidRequestError(request_id=req[1])

request = MSGPACKRPCRequest()
Expand Down

0 comments on commit 7be2929

Please sign in to comment.