Fix kombu.messaging.Consumer.__exit__, which didn’t conform to PEP 0343’s calling convention, and thus rendered Consumer unusable in a with statement.

This commit is contained in:
Ian Eure 2011-03-31 13:34:05 -07:00
parent f7ba3d2ea0
commit 862531f120
2 changed files with 5 additions and 2 deletions

View File

@ -256,8 +256,9 @@ class Consumer(object):
self.consume()
return self
def __exit__(self):
def __exit__(self, exc_type, exc_val, traceback):
self.cancel()
return False
def consume(self, no_ack=None):
"""Register consumer on server.

View File

@ -217,7 +217,9 @@ class test_Consumer(unittest.TestCase):
context = consumer.__enter__()
self.assertIs(context, consumer)
self.assertTrue(consumer._active_tags)
consumer.__exit__()
self.assertRaises(TypeError, consumer.__exit__)
res = consumer.__exit__(None, None, None)
self.assertFalse(res)
self.assertIn("basic_cancel", channel)
self.assertFalse(consumer._active_tags)