Skip to content

Commit

Permalink
Merge pull request #65 from lyschoening/fix/python3.5
Browse files Browse the repository at this point in the history
Fix tests for Python 3.5
(closes #64)
  • Loading branch information
popravich committed Apr 26, 2016
2 parents 6c89049 + b5bc55e commit 9f56fc5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
7 changes: 6 additions & 1 deletion aiozmq/rpc/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
from .packer import _Packer
from aiozmq import interface

if hasattr(asyncio, 'ensure_future'):
ensure_future = asyncio.ensure_future
else: # Deprecated since Python version 3.4.4.
ensure_future = asyncio.async


class Error(Exception):
"""Base RPC exception"""
Expand Down Expand Up @@ -248,7 +253,7 @@ def try_log(self, fut, name, args, kwargs):
pprint.pformat(args), pprint.pformat(kwargs)) # noqa

def add_pending(self, coro):
fut = asyncio.async(coro, loop=self.loop)
fut = ensure_future(coro, loop=self.loop)
self.pending_waiters.add(fut)
return fut

Expand Down
14 changes: 12 additions & 2 deletions tests/rpc_func_annotations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import unittest
import asyncio

import sys

import aiozmq
import aiozmq.rpc
from aiozmq._test_util import find_unused_port
Expand Down Expand Up @@ -121,13 +123,21 @@ def communicate():
with self.assertRaisesRegex(aiozmq.rpc.ParametersError, msg):
yield from client.call.single_param(None)

msg = "TypeError.*'arg' parameter lacking default value"
if sys.version_info >= (3, 5):
msg = "TypeError.*missing a required argument: 'arg'"
else:
msg = "TypeError.*'arg' parameter lacking default value"

with self.assertRaisesRegex(aiozmq.rpc.ParametersError, msg):
yield from client.call.single_param()
with self.assertRaisesRegex(aiozmq.rpc.ParametersError, msg):
yield from client.call.single_param(bad='value')

msg = "TypeError.*too many keyword arguments"
if sys.version_info >= (3, 5):
msg = "TypeError.*got an unexpected keyword argument 'bad'"
else:
msg = "TypeError.*too many keyword arguments"

with self.assertRaisesRegex(aiozmq.rpc.ParametersError, msg):
yield from client.call.single_param(1, bad='value')

Expand Down
22 changes: 11 additions & 11 deletions tests/zmq_stream_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from aiozmq.core import SocketEvent
from aiozmq._test_util import check_errno, find_unused_port

from aiozmq.rpc.base import ensure_future

ZMQ_EVENTS = [
getattr(zmq, attr) for attr in dir(zmq) if attr.startswith('EVENT_')]
Expand Down Expand Up @@ -230,7 +230,7 @@ def go():
def f():
yield from s1.read()

t1 = asyncio.async(f(), loop=self.loop)
t1 = ensure_future(f(), loop=self.loop)
# to run f() up to yield from
yield from asyncio.sleep(0.001, loop=self.loop)

Expand Down Expand Up @@ -259,7 +259,7 @@ def go():
def f():
yield from s1.read()

t1 = asyncio.async(f(), loop=self.loop)
t1 = ensure_future(f(), loop=self.loop)
# to run f() up to yield from
yield from asyncio.sleep(0.001, loop=self.loop)

Expand All @@ -286,7 +286,7 @@ def go():
def f():
yield from s1.read()

t1 = asyncio.async(f(), loop=self.loop)
t1 = ensure_future(f(), loop=self.loop)
# to run f() up to yield from
yield from asyncio.sleep(0.001, loop=self.loop)

Expand All @@ -310,7 +310,7 @@ def go():
def f():
yield from s1.read()

t1 = asyncio.async(f(), loop=self.loop)
t1 = ensure_future(f(), loop=self.loop)
# to run f() up to yield from
yield from asyncio.sleep(0.001, loop=self.loop)

Expand All @@ -335,7 +335,7 @@ def go():
def f():
yield from s1.read()

t1 = asyncio.async(f(), loop=self.loop)
t1 = ensure_future(f(), loop=self.loop)
# to run f() up to yield from
yield from asyncio.sleep(0.001, loop=self.loop)

Expand All @@ -361,7 +361,7 @@ def go():
def f():
yield from s1.read()

t1 = asyncio.async(f(), loop=self.loop)
t1 = ensure_future(f(), loop=self.loop)
# to run f() up to yield from
yield from asyncio.sleep(0.001, loop=self.loop)

Expand Down Expand Up @@ -447,7 +447,7 @@ def go():
def f():
yield from s1.drain()

fut = asyncio.async(f(), loop=self.loop)
fut = ensure_future(f(), loop=self.loop)
yield from asyncio.sleep(0.01, loop=self.loop)

self.assertTrue(s1._protocol._paused)
Expand Down Expand Up @@ -492,7 +492,7 @@ def go():
def f():
yield from s1.drain()

fut = asyncio.async(f(), loop=self.loop)
fut = ensure_future(f(), loop=self.loop)
yield from asyncio.sleep(0.01, loop=self.loop)

s1.close()
Expand Down Expand Up @@ -535,7 +535,7 @@ def go():
def f():
yield from s1.drain()

fut = asyncio.async(f(), loop=self.loop)
fut = ensure_future(f(), loop=self.loop)
yield from asyncio.sleep(0.01, loop=self.loop)

exc = RuntimeError("exception")
Expand Down Expand Up @@ -596,7 +596,7 @@ def f(s, events):
loop=self.loop)

events = []
t = asyncio.async(f(s2, events), loop=self.loop)
t = ensure_future(f(s2, events), loop=self.loop)

yield from s2.transport.enable_monitor()
yield from s2.transport.connect(addr)
Expand Down

0 comments on commit 9f56fc5

Please sign in to comment.