Skip to content

Commit

Permalink
Merge branch 'master' into tornado42
Browse files Browse the repository at this point in the history
  • Loading branch information
thefab committed Aug 4, 2015
2 parents 7c56c1f + b171af9 commit 8f8c20c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
24 changes: 24 additions & 0 deletions tests/test_pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from tornadis.pubsub import PubSubClient
from tornadis.client import Client
from tornadis.exceptions import ClientError
from support import test_redis_or_raise_skiptest


Expand Down Expand Up @@ -67,3 +68,26 @@ def test_pubsub(self):
yield c.pubsub_punsubscribe("bar2*")
self.assertFalse(c.subscribed)
c.disconnect()

@tornado.testing.gen_test
def test_issue17(self):
c = PubSubClient()
yield c.connect()
res = yield c.pubsub_subscribe("foo")
self.assertTrue(res)
self.assertTrue(c.subscribed)
res = yield c.pubsub_unsubscribe()
self.assertTrue(res)
self.assertFalse(c.subscribed)
c.disconnect()

@tornado.testing.gen_test
def test_empty_subscribe(self):
c = PubSubClient()
yield c.connect()
try:
yield c.pubsub_subscribe()
raise Exception("ClientError not raised")
except ClientError:
pass
c.disconnect()
15 changes: 14 additions & 1 deletion tornadis/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def pubsub_subscribe(self, *args):
Returns:
Future: Future with True as result if the subscribe is ok.
Raises:
ClientError: if you don't provide at least one channel
Examples:
>>> yield client.pubsub_subscribe("channel1", "channel2")
Expand All @@ -56,6 +59,9 @@ def pubsub_psubscribe(self, *args):
Returns:
Future: Future with True as result if the subscribe is ok.
Raises:
ClientError: if you don't provide at least one pattern
Examples:
>>> yield client.pubsub_psubscribe("channel*", "foo*")
Expand All @@ -64,6 +70,8 @@ def pubsub_psubscribe(self, *args):

@tornado.gen.coroutine
def _pubsub_subscribe(self, command, *args):
if len(args) == 0:
raise ClientError("you must provide at least one argument")
results = yield Client.call(self, command, *args,
__multiple_replies=len(args))
for reply in results:
Expand Down Expand Up @@ -110,8 +118,13 @@ def pubsub_punsubscribe(self, *args):

@tornado.gen.coroutine
def _pubsub_unsubscribe(self, command, *args):
if len(args) == 0:
# see https://github.com/thefab/tornadis/issues/17
args_len = 1
else:
args_len = len(args)
results = yield Client.call(self, command, *args,
__multiple_replies=len(args))
__multiple_replies=args_len)
for reply in results:
if isinstance(reply, ConnectionError) or len(reply) != 3 or \
reply[0].lower() != command.lower():
Expand Down

0 comments on commit 8f8c20c

Please sign in to comment.