From 02cd13bc9eec102bf0752a9e4ab3fe7cae078cd8 Mon Sep 17 00:00:00 2001 From: Ask Solem Date: Thu, 17 Jan 2013 13:16:32 +0000 Subject: [PATCH 1/9] reverts broken merge --- kombu/tests/__init__.py | 22 +- kombu/tests/compat.py | 8 +- kombu/tests/mocks.py | 15 +- kombu/tests/test_common.py | 20 +- kombu/tests/test_compat.py | 26 +- kombu/tests/test_connection.py | 81 +++--- kombu/tests/test_entities.py | 27 +- kombu/tests/test_log.py | 15 +- kombu/tests/test_messaging.py | 26 +- kombu/tests/test_pidbox.py | 15 +- kombu/tests/test_pools.py | 2 +- kombu/tests/test_serialization.py | 231 ++++++++---------- kombu/tests/test_simple.py | 4 +- kombu/tests/test_utils.py | 72 +++--- kombu/tests/transport/test_amqplib.py | 7 +- kombu/tests/transport/test_base.py | 6 +- kombu/tests/transport/test_filesystem.py | 1 + kombu/tests/transport/test_memory.py | 1 + kombu/tests/transport/test_pyamqp.py | 14 +- kombu/tests/transport/test_redis.py | 49 ++-- kombu/tests/transport/test_sqlalchemy.py | 1 + kombu/tests/transport/test_transport.py | 1 + kombu/tests/transport/virtual/test_base.py | 18 +- .../tests/transport/virtual/test_exchange.py | 91 +++---- .../transport/virtual/test_scheduling.py | 17 +- kombu/tests/utilities/test_amq_manager.py | 11 +- kombu/tests/utilities/test_debug.py | 1 + kombu/tests/utilities/test_encoding.py | 13 +- kombu/tests/utilities/test_functional.py | 12 +- kombu/tests/utils.py | 26 +- kombu/utils/amq_manager.py | 2 +- 31 files changed, 384 insertions(+), 451 deletions(-) diff --git a/kombu/tests/__init__.py b/kombu/tests/__init__.py index f6db3faa..730d9404 100644 --- a/kombu/tests/__init__.py +++ b/kombu/tests/__init__.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, print_function +from __future__ import absolute_import import anyjson import os @@ -33,8 +33,7 @@ def find_distribution_modules(name=__name__, file=__file__): def import_all_modules(name=__name__, file=__file__, skip=[]): for module in find_distribution_modules(name, file): if module not in skip: - print('preimporting {0} for coverage...'.format(module), - file=sys.stderr) + print('preimporting %r for coverage...' % (module, )) try: __import__(module) except (ImportError, VersionMismatch, AttributeError): @@ -53,17 +52,12 @@ def setup_django_env(): return if not settings.configured: - settings.configure( - DATABASES={ - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': ':memory:', - }, - }, - DATABASE_ENGINE='sqlite3', - DATABASE_NAME=':memory:', - INSTALLED_APPS=('kombu.transport.django', ), - ) + settings.configure(DATABASES={'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:'}}, + DATABASE_ENGINE='sqlite3', + DATABASE_NAME=':memory:', + INSTALLED_APPS=('kombu.transport.django', )) def setup(): diff --git a/kombu/tests/compat.py b/kombu/tests/compat.py index e750552b..391b7f1a 100644 --- a/kombu/tests/compat.py +++ b/kombu/tests/compat.py @@ -10,8 +10,8 @@ class WarningMessage(object): _WARNING_DETAILS = ('message', 'category', 'filename', 'lineno', 'file', 'line') - def __init__(self, message, category, filename, lineno, - file=None, line=None): + def __init__(self, message, category, filename, lineno, file=None, + line=None): local_values = locals() for attr in self._WARNING_DETAILS: setattr(self, attr, local_values[attr]) @@ -20,8 +20,8 @@ class WarningMessage(object): def __str__(self): return ('{message : %r, category : %r, filename : %r, lineno : %s, ' - 'line : %r}' % (self.message, self._category_name, - self.filename, self.lineno, self.line)) + 'line : %r}' % (self.message, self._category_name, + self.filename, self.lineno, self.line)) class catch_warnings(object): diff --git a/kombu/tests/mocks.py b/kombu/tests/mocks.py index 5366226a..16aa4389 100644 --- a/kombu/tests/mocks.py +++ b/kombu/tests/mocks.py @@ -27,7 +27,7 @@ class Channel(base.StdChannel): def __init__(self, connection): self.connection = connection self.called = [] - self.deliveries = count(1) + self.deliveries = count(1).next self.to_deliver = [] self.events = {'basic_return': set()} self.channel_id = self._ids() @@ -42,7 +42,7 @@ class Channel(base.StdChannel): self._called('exchange_declare') def prepare_message(self, body, priority=0, content_type=None, - content_encoding=None, headers=None, properties={}): + content_encoding=None, headers=None, properties={}): self._called('prepare_message') return dict(body=body, headers=headers, @@ -52,7 +52,7 @@ class Channel(base.StdChannel): content_encoding=content_encoding) def basic_publish(self, message, exchange='', routing_key='', - mandatory=False, immediate=False, **kwargs): + mandatory=False, immediate=False, **kwargs): self._called('basic_publish') return message, exchange, routing_key @@ -105,10 +105,9 @@ class Channel(base.StdChannel): def message_to_python(self, message, *args, **kwargs): self._called('message_to_python') return Message(self, body=anyjson.dumps(message), - delivery_tag=next(self.deliveries), - throw_decode_error=self.throw_decode_error, - content_type='application/json', - content_encoding='utf-8') + delivery_tag=self.deliveries(), + throw_decode_error=self.throw_decode_error, + content_type='application/json', content_encoding='utf-8') def flow(self, active): self._called('flow') @@ -119,7 +118,7 @@ class Channel(base.StdChannel): return self._called('basic_reject') def basic_qos(self, prefetch_size=0, prefetch_count=0, - apply_global=False): + apply_global=False): self._called('basic_qos') diff --git a/kombu/tests/test_common.py b/kombu/tests/test_common.py index 6f1311d3..c97fe4ef 100644 --- a/kombu/tests/test_common.py +++ b/kombu/tests/test_common.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from __future__ import with_statement import socket @@ -156,13 +157,13 @@ class test_replies(TestCase): body, message = Mock(), Mock() itermessages.return_value = [(body, message)] it = collect_replies(conn, channel, queue, no_ack=False) - m = next(it) + m = it.next() self.assertIs(m, body) itermessages.assert_called_with(conn, channel, queue, no_ack=False) message.ack.assert_called_with() with self.assertRaises(StopIteration): - next(it) + it.next() channel.after_reply_message_received.assert_called_with(queue.name) @@ -172,7 +173,7 @@ class test_replies(TestCase): body, message = Mock(), Mock() itermessages.return_value = [(body, message)] it = collect_replies(conn, channel, queue) - m = next(it) + m = it.next() self.assertIs(m, body) itermessages.assert_called_with(conn, channel, queue, no_ack=True) self.assertFalse(message.ack.called) @@ -183,7 +184,7 @@ class test_replies(TestCase): itermessages.return_value = [] it = collect_replies(conn, channel, queue) with self.assertRaises(StopIteration): - next(it) + it.next() self.assertFalse(channel.after_reply_message_received.called) @@ -225,8 +226,7 @@ class test_insured(TestCase): ret = common.insured(pool, fun, (2, 2), {'foo': 'bar'}) self.assertEqual(ret, 'works') conn.ensure_connection.assert_called_with( - errback=common._ensure_errback, - ) + errback=common._ensure_errback) self.assertTrue(insured.called) i_args, i_kwargs = insured.call_args @@ -317,11 +317,11 @@ class test_itermessages(TestCase): it = common.itermessages(conn, channel, 'q', limit=1, Consumer=MockConsumer) - ret = next(it) + ret = it.next() self.assertTupleEqual(ret, ('body', 'message')) with self.assertRaises(StopIteration): - next(it) + it.next() def test_when_raises_socket_timeout(self): conn = self.MockConnection() @@ -332,7 +332,7 @@ class test_itermessages(TestCase): Consumer=MockConsumer) with self.assertRaises(StopIteration): - next(it) + it.next() @patch('kombu.common.deque') def test_when_raises_IndexError(self, deque): @@ -344,7 +344,7 @@ class test_itermessages(TestCase): Consumer=MockConsumer) with self.assertRaises(StopIteration): - next(it) + it.next() class test_entry_to_queue(TestCase): diff --git a/kombu/tests/test_compat.py b/kombu/tests/test_compat.py index 790e76ce..36a60d39 100644 --- a/kombu/tests/test_compat.py +++ b/kombu/tests/test_compat.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from __future__ import with_statement from mock import patch @@ -30,7 +31,7 @@ class test_misc(TestCase): conn = MyConnection() consumer = Consumer() it = compat._iterconsume(conn, consumer) - self.assertEqual(next(it), 1) + self.assertEqual(it.next(), 1) self.assertTrue(consumer.active) it2 = compat._iterconsume(conn, consumer, limit=10) @@ -101,7 +102,7 @@ class test_Publisher(TestCase): self.assertFalse(pub2.exchange.durable) explicit = Exchange('test_Publisher_constructor_explicit', - type='topic') + type='topic') pub3 = compat.Publisher(self.connection, exchange=explicit) self.assertEqual(pub3.exchange, explicit) @@ -240,9 +241,9 @@ class test_Consumer(TestCase): for i in range(limit): yield i - c = C(self.connection, - queue=n, exchange=n, routing_key='rkey') - self.assertEqual(c.wait(10), list(range(10))) + c = C(self.connection, queue=n, exchange=n, + routing_key='rkey') + self.assertEqual(c.wait(10), range(10)) c.close() def test_iterqueue(self, n='test_iterqueue'): @@ -255,9 +256,9 @@ class test_Consumer(TestCase): i[0] += 1 return z - c = C(self.connection, - queue=n, exchange=n, routing_key='rkey') - self.assertEqual(list(c.iterqueue(limit=10)), list(range(10))) + c = C(self.connection, queue=n, exchange=n, + routing_key='rkey') + self.assertEqual(list(c.iterqueue(limit=10)), range(10)) c.close() @@ -288,7 +289,7 @@ class test_ConsumerSet(TestCase): 'routing_key': 'xyz'}} consumers = [compat.Consumer(self.connection, queue=prefix + str(i), exchange=prefix + str(i)) - for i in range(3)] + for i in range(3)] c = compat.ConsumerSet(self.connection, consumers=consumers) c2 = compat.ConsumerSet(self.connection, from_dict=dcon) @@ -302,12 +303,9 @@ class test_ConsumerSet(TestCase): for cq in c.queues: self.assertIs(cq.channel, c.channel) - c2.add_consumer_from_dict({ - '%s.xxx' % prefix: { + c2.add_consumer_from_dict({'%s.xxx' % prefix: { 'exchange': '%s.xxx' % prefix, - 'routing_key': 'xxx', - }, - }) + 'routing_key': 'xxx'}}) self.assertEqual(len(c2.queues), 3) for c2q in c2.queues: self.assertIs(c2q.channel, c2.channel) diff --git a/kombu/tests/test_connection.py b/kombu/tests/test_connection.py index d0aac2ed..6997be69 100644 --- a/kombu/tests/test_connection.py +++ b/kombu/tests/test_connection.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from __future__ import with_statement import errno import pickle @@ -10,7 +11,6 @@ from nose import SkipTest from kombu import Connection, Consumer, Producer, parse_url from kombu.connection import Resource -from kombu.five import items from .mocks import Transport from .utils import TestCase @@ -43,7 +43,7 @@ class test_connection_utils(TestCase): def test_parse_generated_as_uri(self): conn = Connection(self.url) info = conn.info() - for k, v in items(self.expected): + for k, v in self.expected.items(): self.assertEqual(info[k], v) # by default almost the same- no password self.assertEqual(conn.as_uri(), self.nopass) @@ -60,7 +60,7 @@ class test_connection_utils(TestCase): def assert_info(self, conn, **fields): info = conn.info() - for field, expected in items(fields): + for field, expected in fields.iteritems(): self.assertEqual(info[field], expected) def test_rabbitmq_example_urls(self): @@ -68,78 +68,77 @@ class test_connection_utils(TestCase): self.assert_info( Connection('amqp://user:pass@host:10000/vhost'), - userid='user', password='pass', hostname='host', - port=10000, virtual_host='vhost', - ) + userid='user', password='pass', hostname='host', + port=10000, virtual_host='vhost') self.assert_info( Connection('amqp://user%61:%61pass@ho%61st:10000/v%2fhost'), - userid='usera', password='apass', hostname='hoast', - port=10000, virtual_host='v/host', - ) + userid='usera', password='apass', + hostname='hoast', port=10000, + virtual_host='v/host') self.assert_info( Connection('amqp://'), - userid='guest', password='guest', hostname='localhost', - port=5672, virtual_host='/', - ) + userid='guest', password='guest', + hostname='localhost', port=5672, + virtual_host='/') self.assert_info( Connection('amqp://:@/'), - userid='guest', password='guest', hostname='localhost', - port=5672, virtual_host='/', - ) + userid='guest', password='guest', + hostname='localhost', port=5672, + virtual_host='/') self.assert_info( Connection('amqp://user@/'), - userid='user', password='guest', hostname='localhost', - port=5672, virtual_host='/', - ) + userid='user', password='guest', + hostname='localhost', port=5672, + virtual_host='/') self.assert_info( Connection('amqp://user:pass@/'), - userid='user', password='pass', hostname='localhost', - port=5672, virtual_host='/', - ) + userid='user', password='pass', + hostname='localhost', port=5672, + virtual_host='/') self.assert_info( Connection('amqp://host'), - userid='guest', password='guest', hostname='host', - port=5672, virtual_host='/', - ) + userid='guest', password='guest', + hostname='host', port=5672, + virtual_host='/') self.assert_info( Connection('amqp://:10000'), - userid='guest', password='guest', hostname='localhost', - port=10000, virtual_host='/', - ) + userid='guest', password='guest', + hostname='localhost', port=10000, + virtual_host='/') self.assert_info( Connection('amqp:///vhost'), - userid='guest', password='guest', hostname='localhost', - port=5672, virtual_host='vhost', - ) + userid='guest', password='guest', + hostname='localhost', port=5672, + virtual_host='vhost') self.assert_info( Connection('amqp://host/'), - userid='guest', password='guest', hostname='host', - port=5672, virtual_host='/', - ) + userid='guest', password='guest', + hostname='host', port=5672, + virtual_host='/') self.assert_info( Connection('amqp://host/%2f'), - userid='guest', password='guest', hostname='host', - port=5672, virtual_host='/', - ) + userid='guest', password='guest', + hostname='host', port=5672, + virtual_host='/') def test_url_IPV6(self): raise SkipTest("urllib can't parse ipv6 urls") self.assert_info( Connection('amqp://[::1]'), - userid='guest', password='guest', hostname='[::1]', - port=5672, virtual_host='/', - ) + userid='guest', password='guest', + hostname='[::1]', port=5672, + virtual_host='/') class test_Connection(TestCase): @@ -505,7 +504,7 @@ class ResourceCase(TestCase): return P = self.create_resource(10, 0) self.assertState(P, 10, 0) - chans = [P.acquire() for _ in range(10)] + chans = [P.acquire() for _ in xrange(10)] self.assertState(P, 0, 10) with self.assertRaises(P.LimitExceeded): P.acquire() @@ -636,7 +635,7 @@ class test_ChannelPool(ResourceCase): def create_resource(self, limit, preload): return Connection(port=5672, transport=Transport) \ - .ChannelPool(limit, preload) + .ChannelPool(limit, preload) def test_setup(self): P = self.create_resource(10, 2) diff --git a/kombu/tests/test_entities.py b/kombu/tests/test_entities.py index ff1a160f..7c2f25a4 100644 --- a/kombu/tests/test_entities.py +++ b/kombu/tests/test_entities.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from __future__ import with_statement import pickle @@ -19,8 +20,7 @@ def get_conn(): class test_binding(TestCase): def test_constructor(self): - x = binding( - Exchange('foo'), 'rkey', + x = binding(Exchange('foo'), 'rkey', arguments={'barg': 'bval'}, unbind_arguments={'uarg': 'uval'}, ) @@ -235,14 +235,13 @@ class test_Queue(TestCase): ]) q(chan).declare() self.assertIn( - call( - nowait=False, - exchange='mul1', - auto_delete=False, - passive=False, - arguments=None, - type='direct', - durable=True, + call(nowait=False, + exchange='mul1', + auto_delete=False, + passive=False, + arguments=None, + type='direct', + durable=True, ), chan.exchange_declare.call_args_list, ) @@ -261,13 +260,11 @@ class test_Queue(TestCase): def test_exclusive_implies_auto_delete(self): self.assertTrue( - Queue('foo', self.exchange, exclusive=True).auto_delete, - ) + Queue('foo', self.exchange, exclusive=True).auto_delete) def test_binds_at_instantiation(self): - self.assertTrue( - Queue('foo', self.exchange, channel=get_conn().channel()).is_bound, - ) + self.assertTrue(Queue('foo', self.exchange, + channel=get_conn().channel()).is_bound) def test_also_binds_exchange(self): chan = get_conn().channel() diff --git a/kombu/tests/test_log.py b/kombu/tests/test_log.py index b9cf966b..62dd1b35 100644 --- a/kombu/tests/test_log.py +++ b/kombu/tests/test_log.py @@ -80,15 +80,13 @@ class test_LogMixin(TestCase): def test_error(self): self.log.error('error', exc_info='exc') - self.logger.log.assert_called_with( - logging.ERROR, 'Log - error', exc_info='exc', - ) + self.logger.log.assert_called_with(logging.ERROR, 'Log - error', + exc_info='exc') def test_critical(self): self.log.critical('crit', exc_info='exc') - self.logger.log.assert_called_with( - logging.CRITICAL, 'Log - crit', exc_info='exc', - ) + self.logger.log.assert_called_with(logging.CRITICAL, 'Log - crit', + exc_info='exc') def test_error_when_DISABLE_TRACEBACKS(self): log.DISABLE_TRACEBACKS = True @@ -123,9 +121,8 @@ class test_LogMixin(TestCase): def test_log_with_format(self): self.log.debug('Host %r removed', 'example.com') - self.logger.log.assert_called_with( - logging.DEBUG, 'Log - Host %s removed', "'example.com'", - ) + self.logger.log.assert_called_with(logging.DEBUG, + 'Log - Host %s removed', "'example.com'") class test_setup_logging(TestCase): diff --git a/kombu/tests/test_messaging.py b/kombu/tests/test_messaging.py index 256352b3..a6024497 100644 --- a/kombu/tests/test_messaging.py +++ b/kombu/tests/test_messaging.py @@ -1,4 +1,5 @@ -from __future__ import absolute_import, unicode_literals +from __future__ import absolute_import +from __future__ import with_statement import anyjson import pickle @@ -67,7 +68,7 @@ class test_Producer(TestCase): 'p.declare() declares exchange') def test_prepare(self): - message = {'the quick brown fox': 'jumps over the lazy dog'} + message = {u'the quick brown fox': u'jumps over the lazy dog'} channel = self.connection.channel() p = Producer(channel, self.exchange, serializer='json') m, ctype, cencoding = p._prepare(message, headers={}) @@ -76,7 +77,7 @@ class test_Producer(TestCase): self.assertEqual(cencoding, 'utf-8') def test_prepare_compression(self): - message = {'the quick brown fox': 'jumps over the lazy dog'} + message = {u'the quick brown fox': u'jumps over the lazy dog'} channel = self.connection.channel() p = Producer(channel, self.exchange, serializer='json') headers = {} @@ -86,10 +87,8 @@ class test_Producer(TestCase): self.assertEqual(cencoding, 'utf-8') self.assertEqual(headers['compression'], 'application/x-gzip') import zlib - self.assertEqual( - anyjson.loads(zlib.decompress(m).decode('utf-8')), - message, - ) + self.assertEqual(anyjson.loads( + zlib.decompress(m).decode('utf-8')), message) def test_prepare_custom_content_type(self): message = 'the quick brown fox'.encode('utf-8') @@ -106,16 +105,15 @@ class test_Producer(TestCase): self.assertEqual(cencoding, 'alien') def test_prepare_is_already_unicode(self): - message = 'the quick brown fox' + message = u'the quick brown fox' channel = self.connection.channel() p = Producer(channel, self.exchange, serializer='json') m, ctype, cencoding = p._prepare(message, content_type='text/plain') self.assertEqual(m, message.encode('utf-8')) self.assertEqual(ctype, 'text/plain') self.assertEqual(cencoding, 'utf-8') - m, ctype, cencoding = p._prepare( - message, content_type='text/plain', content_encoding='utf-8', - ) + m, ctype, cencoding = p._prepare(message, content_type='text/plain', + content_encoding='utf-8') self.assertEqual(m, message.encode('utf-8')) self.assertEqual(ctype, 'text/plain') self.assertEqual(cencoding, 'utf-8') @@ -177,7 +175,7 @@ class test_Producer(TestCase): def test_publish(self): channel = self.connection.channel() p = Producer(channel, self.exchange, serializer='json') - message = {'the quick brown fox': 'jumps over the lazy dog'} + message = {u'the quick brown fox': u'jumps over the lazy dog'} ret = p.publish(message, routing_key='process') self.assertIn('prepare_message', channel) self.assertIn('basic_publish', channel) @@ -409,11 +407,11 @@ class test_Consumer(TestCase): message.payload # trigger cache consumer.register_callback(callback) - consumer._receive_callback({'foo': 'bar'}) + consumer._receive_callback({u'foo': u'bar'}) self.assertIn('basic_ack', channel) self.assertIn('message_to_python', channel) - self.assertEqual(received[0], {'foo': 'bar'}) + self.assertEqual(received[0], {u'foo': u'bar'}) def test_basic_ack_twice(self): channel = self.connection.channel() diff --git a/kombu/tests/test_pidbox.py b/kombu/tests/test_pidbox.py index 1eaec780..33e071a7 100644 --- a/kombu/tests/test_pidbox.py +++ b/kombu/tests/test_pidbox.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from __future__ import with_statement import socket @@ -29,8 +30,8 @@ class test_Mailbox(TestCase): self.bound = self.mailbox(self.connection) self.default_chan = self.connection.channel() self.node = self.bound.Node('test_pidbox', state=self.state, - handlers=self.handlers, - channel=self.default_chan) + handlers=self.handlers, + channel=self.default_chan) def test_reply__collect(self): mailbox = pidbox.Mailbox('test_reply__collect')(self.connection) @@ -45,8 +46,8 @@ class test_Mailbox(TestCase): def callback(body): _callback_called[0] = True - reply = mailbox._collect(ticket, limit=1, - callback=callback, channel=channel) + reply = mailbox._collect(ticket, limit=1, callback=callback, + channel=channel) self.assertEqual(reply, [{'foo': 'bar'}]) self.assertTrue(_callback_called[0]) @@ -208,10 +209,8 @@ class test_Mailbox(TestCase): self.bound.call('some_node', 'mymethod') def test_call(self): - self.assertEqual( - self.bound.call(['some_node'], 'mymethod'), - 'COLLECTED', - ) + self.assertEqual(self.bound.call(['some_node'], 'mymethod'), + 'COLLECTED') consumer = self.node.Consumer() self.assertIsCall(self.get_next(consumer)) diff --git a/kombu/tests/test_pools.py b/kombu/tests/test_pools.py index a9386602..1ec34395 100644 --- a/kombu/tests/test_pools.py +++ b/kombu/tests/test_pools.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import +from __future__ import with_statement from kombu import Connection, Producer from kombu import pools diff --git a/kombu/tests/test_serialization.py b/kombu/tests/test_serialization.py index 3d920cf8..c4b8bd81 100644 --- a/kombu/tests/test_serialization.py +++ b/kombu/tests/test_serialization.py @@ -1,40 +1,32 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals +from __future__ import absolute_import +from __future__ import with_statement -from kombu.serialization import ( - registry, - register, - SerializerNotInstalled, - raw_encode, - register_yaml, - register_msgpack, - decode, - bytes_t, - pickle, - pickle_protocol, - unregister, - register_pickle, -) +import sys + +from kombu.serialization import (registry, register, SerializerNotInstalled, + raw_encode, register_yaml, register_msgpack, + decode, bytes_t, pickle, pickle_protocol, + unregister, register_pickle) from .utils import TestCase from .utils import mask_modules, skip_if_not_module # For content_encoding tests -unicode_string = 'abcdé\u8463' +unicode_string = u'abcdé\u8463' unicode_string_as_utf8 = unicode_string.encode('utf-8') -latin_string = 'abcdé' +latin_string = u'abcdé' latin_string_as_latin1 = latin_string.encode('latin-1') latin_string_as_utf8 = latin_string.encode('utf-8') # For serialization tests -py_data = { - 'string': 'The quick brown fox jumps over the lazy dog', - 'int': 10, - 'float': 3.14159265, - 'unicode': 'Thé quick brown fox jumps over thé lazy dog', - 'list': ['george', 'jerry', 'elaine', 'cosmo'], +py_data = {'string': 'The quick brown fox jumps over the lazy dog', + 'int': 10, + 'float': 3.14159265, + 'unicode': u'Thé quick brown fox jumps over thé lazy dog', + 'list': ['george', 'jerry', 'elaine', 'cosmo'], } # JSON serialization tests @@ -55,17 +47,20 @@ yaml_data = ('float: 3.1415926500000002\nint: 10\n' 'jumps over th\\xE9 lazy dog"\n') -msgpack_py_data = { - 'string': 'The quick brown fox jumps over the lazy dog', - 'int': 10, - 'float': 3.14159265, - 'unicode': 'Thé quick brown fox jumps over thé lazy dog', - 'list': ['george', 'jerry', 'elaine', 'cosmo'], -} +msgpack_py_data = dict(py_data) # msgpack only supports tuples msgpack_py_data['list'] = tuple(msgpack_py_data['list']) # Unicode chars are lost in transmit :( msgpack_py_data['unicode'] = 'Th quick brown fox jumps over th lazy dog' +msgpack_data = ('\x85\xa3int\n\xa5float\xcb@\t!\xfbS\xc8\xd4\xf1\xa4list' + '\x94\xa6george\xa5jerry\xa6elaine\xa5cosmo\xa6string\xda' + '\x00+The quick brown fox jumps over the lazy dog\xa7unicode' + '\xda\x00)Th quick brown fox jumps over th lazy dog') + + +def say(m): + sys.stderr.write('%s\n' % (m, )) + registry.register('testS', lambda s: s, lambda s: 'decoded', 'application/testS', 'utf-8') @@ -95,7 +90,7 @@ class test_Serialization(TestCase): force=False) ret = registry.decode('xxd', 'application/testS', 'utf-8', - force=True) + force=True) self.assertEqual(ret, 'decoded') finally: disabled.clear() @@ -104,128 +99,114 @@ class test_Serialization(TestCase): registry.decode(None, 'application/testS', 'utf-8') def test_content_type_decoding(self): - self.assertEqual( - unicode_string, - registry.decode( - unicode_string_as_utf8, - content_type='plain/text', - content_encoding='utf-8'), - ) - self.assertEqual( - latin_string, - registry.decode( - latin_string_as_latin1, - content_type='application/data', - content_encoding='latin-1'), - ) + self.assertEqual(unicode_string, + registry.decode( + unicode_string_as_utf8, + content_type='plain/text', + content_encoding='utf-8')) + self.assertEqual(latin_string, + registry.decode( + latin_string_as_latin1, + content_type='application/data', + content_encoding='latin-1')) def test_content_type_binary(self): - self.assertIsInstance( - registry.decode(unicode_string_as_utf8, - content_type='application/data', - content_encoding='binary'), - bytes_t, - ) + self.assertIsInstance(registry.decode(unicode_string_as_utf8, + content_type='application/data', + content_encoding='binary'), + bytes_t) - self.assertEqual( - unicode_string_as_utf8, - registry.decode(unicode_string_as_utf8, - content_type='application/data', - content_encoding='binary'), - ) + self.assertEqual(unicode_string_as_utf8, + registry.decode( + unicode_string_as_utf8, + content_type='application/data', + content_encoding='binary')) def test_content_type_encoding(self): # Using the 'raw' serializer - self.assertEqual( - unicode_string_as_utf8, - registry.encode(unicode_string, serializer='raw')[-1], - ) - self.assertEqual( - latin_string_as_utf8, - registry.encode(latin_string, serializer='raw')[-1], - ) + self.assertEqual(unicode_string_as_utf8, + registry.encode( + unicode_string, serializer='raw')[-1]) + self.assertEqual(latin_string_as_utf8, + registry.encode( + latin_string, serializer='raw')[-1]) # And again w/o a specific serializer to check the # code where we force unicode objects into a string. - self.assertEqual( - unicode_string_as_utf8, - registry.encode(unicode_string)[-1], - ) - self.assertEqual( - latin_string_as_utf8, - registry.encode(latin_string)[-1], - ) + self.assertEqual(unicode_string_as_utf8, + registry.encode(unicode_string)[-1]) + self.assertEqual(latin_string_as_utf8, + registry.encode(latin_string)[-1]) def test_json_decode(self): - self.assertEqual( - py_data, - registry.decode( - json_data, - content_type='application/json', - content_encoding='utf-8'), - ) + self.assertEqual(py_data, + registry.decode( + json_data, + content_type='application/json', + content_encoding='utf-8')) def test_json_encode(self): - self.assertEqual( - registry.decode( - registry.encode(py_data, serializer='json')[-1], - content_type='application/json', - content_encoding='utf-8', - ), - registry.decode( - json_data, - content_type='application/json', - content_encoding='utf-8'), - ) + self.assertEqual(registry.decode( + registry.encode(py_data, serializer='json')[-1], + content_type='application/json', + content_encoding='utf-8'), + registry.decode( + json_data, + content_type='application/json', + content_encoding='utf-8')) @skip_if_not_module('msgpack') def test_msgpack_decode(self): register_msgpack() - decoded = registry.decode( - registry.encode(msgpack_py_data, serializer='msgpack')[-1], - content_type='application/x-msgpack', - content_encoding='binary', - ) - self.assertEqual(msgpack_py_data, decoded) + self.assertEqual(msgpack_py_data, + registry.decode( + msgpack_data, + content_type='application/x-msgpack', + content_encoding='binary')) + + @skip_if_not_module('msgpack') + def test_msgpack_encode(self): + register_msgpack() + self.assertEqual(registry.decode( + registry.encode(msgpack_py_data, serializer='msgpack')[-1], + content_type='application/x-msgpack', + content_encoding='binary'), + registry.decode( + msgpack_data, + content_type='application/x-msgpack', + content_encoding='binary')) @skip_if_not_module('yaml') def test_yaml_decode(self): register_yaml() - self.assertEqual( - py_data, - registry.decode(yaml_data, - content_type='application/x-yaml', - content_encoding='utf-8'), - ) + self.assertEqual(py_data, + registry.decode( + yaml_data, + content_type='application/x-yaml', + content_encoding='utf-8')) @skip_if_not_module('yaml') def test_yaml_encode(self): register_yaml() - self.assertEqual( - registry.decode( - registry.encode(py_data, serializer='yaml')[-1], - content_type='application/x-yaml', - content_encoding='utf-8', - ), - registry.decode( - yaml_data, - content_type='application/x-yaml', - content_encoding='utf-8'), - ) + self.assertEqual(registry.decode( + registry.encode(py_data, serializer='yaml')[-1], + content_type='application/x-yaml', + content_encoding='utf-8'), + registry.decode( + yaml_data, + content_type='application/x-yaml', + content_encoding='utf-8')) def test_pickle_decode(self): - self.assertEqual( - py_data, - registry.decode( - pickle_data, - content_type='application/x-python-serialize', - content_encoding='binary'), - ) + self.assertEqual(py_data, + registry.decode( + pickle_data, + content_type='application/x-python-serialize', + content_encoding='binary')) def test_pickle_encode(self): - self.assertEqual( - pickle.loads(pickle_data), - pickle.loads(registry.encode(py_data, serializer='pickle')[-1]), - ) + self.assertEqual(pickle.loads(pickle_data), + pickle.loads(registry.encode(py_data, + serializer='pickle')[-1])) def test_register(self): register(None, None, None, None) diff --git a/kombu/tests/test_simple.py b/kombu/tests/test_simple.py index 381d8a20..26b09080 100644 --- a/kombu/tests/test_simple.py +++ b/kombu/tests/test_simple.py @@ -1,7 +1,9 @@ from __future__ import absolute_import +from __future__ import with_statement + +from Queue import Empty from kombu import Connection, Exchange, Queue -from kombu.five import Empty from .utils import TestCase from .utils import Mock diff --git a/kombu/tests/test_utils.py b/kombu/tests/test_utils.py index 2ab3b5bb..3099b337 100644 --- a/kombu/tests/test_utils.py +++ b/kombu/tests/test_utils.py @@ -1,14 +1,19 @@ -from __future__ import absolute_import, unicode_literals +from __future__ import absolute_import +from __future__ import with_statement import pickle import sys from functools import wraps -from io import BytesIO, StringIO from mock import Mock, patch +if sys.version_info >= (3, 0): + from io import StringIO, BytesIO +else: + from StringIO import StringIO, StringIO as BytesIO # noqa + from kombu import utils -from kombu.five import string_t +from kombu.utils.compat import next from .utils import ( TestCase, @@ -57,12 +62,11 @@ class test_utils(TestCase): [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]) def test_reprkwargs(self): - self.assertTrue(utils.reprkwargs({'foo': 'bar', 1: 2, 'k': 'v'})) + self.assertTrue(utils.reprkwargs({'foo': 'bar', 1: 2, u'k': 'v'})) def test_reprcall(self): - self.assertTrue( - utils.reprcall('add', (2, 2), {'copy': True}), - ) + self.assertTrue(utils.reprcall('add', + (2, 2), {'copy': True})) class test_UUID(TestCase): @@ -88,7 +92,7 @@ class test_UUID(TestCase): self.assertIsNone(ctypes) tid = uuid() self.assertTrue(tid) - self.assertIsInstance(tid, string_t) + self.assertIsInstance(tid, basestring) try: with_ctypes_masked() @@ -103,8 +107,8 @@ class test_Misc(TestCase): def f(**kwargs): return kwargs - kw = {'foo': 'foo', - 'bar': 'bar'} + kw = {u'foo': 'foo', + u'bar': 'bar'} self.assertTrue(f(**utils.kwdict(kw))) @@ -138,12 +142,9 @@ class test_emergency_dump_state(TestCase): def raise_something(*args, **kwargs): raise KeyError('foo') - utils.emergency_dump_state( - {'foo': 'bar'}, - open_file=lambda n, m: fh, dump=raise_something, - ) - # replace at the end removes u' from repr on Py2 - self.assertIn("'foo': 'bar'", fh.getvalue().replace("u'", "'")) + utils.emergency_dump_state({'foo': 'bar'}, open_file=lambda n, m: fh, + dump=raise_something) + self.assertIn("'foo': 'bar'", fh.getvalue()) self.assertTrue(stderr.getvalue()) self.assertFalse(stdout.getvalue()) @@ -191,13 +192,12 @@ class test_retry_over_time(TestCase): try: utils.count.return_value = range(1) x = utils.retry_over_time(self.myfun, self.Predicate, - errback=None, interval_max=14) + errback=None, interval_max=14) self.assertIsNone(x) utils.count.return_value = range(10) cb = Mock() x = utils.retry_over_time(self.myfun, self.Predicate, - errback=self.errback, interval_max=14, - callback=cb) + errback=self.errback, callback=cb, interval_max=14) self.assertEqual(x, 42) self.assertEqual(self.index, 9) cb.assert_called_with() @@ -206,26 +206,20 @@ class test_retry_over_time(TestCase): @insomnia def test_retry_once(self): - self.assertRaises( - self.Predicate, utils.retry_over_time, - self.myfun, self.Predicate, - max_retries=1, errback=self.errback, interval_max=14, - ) + self.assertRaises(self.Predicate, utils.retry_over_time, + self.myfun, self.Predicate, + max_retries=1, errback=self.errback, interval_max=14) self.assertEqual(self.index, 2) # no errback - self.assertRaises( - self.Predicate, utils.retry_over_time, - self.myfun, self.Predicate, - max_retries=1, errback=None, interval_max=14, - ) + self.assertRaises(self.Predicate, utils.retry_over_time, + self.myfun, self.Predicate, + max_retries=1, errback=None, interval_max=14) @insomnia def test_retry_never(self): - self.assertRaises( - self.Predicate, utils.retry_over_time, - self.myfun, self.Predicate, - max_retries=0, errback=self.errback, interval_max=14, - ) + self.assertRaises(self.Predicate, utils.retry_over_time, + self.myfun, self.Predicate, + max_retries=0, errback=self.errback, interval_max=14) self.assertEqual(self.index, 1) @@ -288,7 +282,7 @@ class test_symbol_by_name(TestCase): def test_returns_default(self): default = object() self.assertIs(utils.symbol_by_name('xyz.ryx.qedoa.weq:foz', - default=default), default) + default=default), default) def test_no_default(self): with self.assertRaises(ImportError): @@ -303,17 +297,15 @@ class test_symbol_by_name(TestCase): def test_package(self): from kombu.entity import Exchange self.assertIs(utils.symbol_by_name('.entity:Exchange', - package='kombu'), Exchange) + package='kombu'), Exchange) self.assertTrue(utils.symbol_by_name(':Consumer', package='kombu')) class test_ChannelPromise(TestCase): def test_repr(self): - self.assertIn( - "'foo'", - repr(utils.ChannelPromise(lambda: 'foo')), - ) + self.assertEqual(repr(utils.ChannelPromise(lambda: 'foo')), + "") class test_entrypoints(TestCase): diff --git a/kombu/tests/transport/test_amqplib.py b/kombu/tests/transport/test_amqplib.py index 626050fc..fb6c0141 100644 --- a/kombu/tests/transport/test_amqplib.py +++ b/kombu/tests/transport/test_amqplib.py @@ -57,10 +57,9 @@ class test_Channel(amqplibCase): self.assertFalse(self.channel.no_ack_consumers) def test_prepare_message(self): - x = self.channel.prepare_message( - 'foobar', 10, 'application/data', 'utf-8', - properties={}, - ) + x = self.channel.prepare_message('foobar', 10, + 'application/data', 'utf-8', + properties={}) self.assertTrue(x) def test_message_to_python(self): diff --git a/kombu/tests/transport/test_base.py b/kombu/tests/transport/test_base.py index 2ba7156a..e369449f 100644 --- a/kombu/tests/transport/test_base.py +++ b/kombu/tests/transport/test_base.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from __future__ import with_statement from kombu import Connection, Consumer, Producer, Queue from kombu.transport.base import Message, StdChannel, Transport @@ -32,9 +33,8 @@ class test_StdChannel(TestCase): StdChannel().get_bindings() def test_interface_after_reply_message_received(self): - self.assertIsNone( - StdChannel().after_reply_message_received(Queue('foo')), - ) + self.assertIsNone(StdChannel().after_reply_message_received( + Queue('foo'))) class test_Message(TestCase): diff --git a/kombu/tests/transport/test_filesystem.py b/kombu/tests/transport/test_filesystem.py index 7bdad8f5..b1d7c0cd 100644 --- a/kombu/tests/transport/test_filesystem.py +++ b/kombu/tests/transport/test_filesystem.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from __future__ import with_statement import tempfile diff --git a/kombu/tests/transport/test_memory.py b/kombu/tests/transport/test_memory.py index 970681d7..d138e494 100644 --- a/kombu/tests/transport/test_memory.py +++ b/kombu/tests/transport/test_memory.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from __future__ import with_statement import socket diff --git a/kombu/tests/transport/test_pyamqp.py b/kombu/tests/transport/test_pyamqp.py index 21764c83..a1b550da 100644 --- a/kombu/tests/transport/test_pyamqp.py +++ b/kombu/tests/transport/test_pyamqp.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from __future__ import with_statement import sys @@ -49,10 +50,9 @@ class test_Channel(TestCase): self.assertFalse(self.channel.no_ack_consumers) def test_prepare_message(self): - x = self.channel.prepare_message( - 'foobar', 10, 'application/data', 'utf-8', - properties={}, - ) + x = self.channel.prepare_message('foobar', 10, + 'application/data', 'utf-8', + properties={}) self.assertTrue(x) def test_message_to_python(self): @@ -166,10 +166,8 @@ class test_pyamqp(TestCase): def test_eventmap(self): t = pyamqp.Transport(Mock()) conn = Mock() - self.assertDictEqual( - t.eventmap(conn), - {conn.sock: t.client.drain_nowait}, - ) + self.assertDictEqual(t.eventmap(conn), + {conn.sock: t.client.drain_nowait}) def test_event_interface(self): t = pyamqp.Transport(Mock()) diff --git a/kombu/tests/transport/test_redis.py b/kombu/tests/transport/test_redis.py index 8cb8fab5..e007664d 100644 --- a/kombu/tests/transport/test_redis.py +++ b/kombu/tests/transport/test_redis.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from __future__ import with_statement import socket import types @@ -6,10 +7,10 @@ import types from anyjson import dumps from collections import defaultdict from itertools import count +from Queue import Empty, Queue as _Queue from kombu import Connection, Exchange, Queue, Consumer, Producer from kombu.exceptions import InconsistencyError, VersionMismatch -from kombu.five import Empty, Queue as _Queue from kombu.utils import eventio # patch poll from kombu.tests.utils import TestCase @@ -128,10 +129,10 @@ class Client(object): class _socket(object): blocking = True - filenos = count(30) + next_fileno = count(30).next def __init__(self, *args): - self._fileno = next(self.filenos) + self._fileno = self.next_fileno() self.data = [] def fileno(self): @@ -261,28 +262,22 @@ class test_Channel(TestCase): self.assertFalse(s.subscribed) def test_handle_pmessage_message(self): - self.assertDictEqual( - self.channel._handle_message( - self.channel.subclient, - ['pmessage', 'pattern', 'channel', 'data'] - ), - {'type': 'pmessage', - 'pattern': 'pattern', - 'channel': 'channel', - 'data': 'data'}, - ) + self.assertDictEqual(self.channel._handle_message( + self.channel.subclient, + ['pmessage', 'pattern', 'channel', 'data']), + {'type': 'pmessage', + 'pattern': 'pattern', + 'channel': 'channel', + 'data': 'data'}) def test_handle_message(self): - self.assertDictEqual( - self.channel._handle_message( - self.channel.subclient, - ['type', 'channel', 'data'] - ), - {'type': 'type', - 'pattern': None, - 'channel': 'channel', - 'data': 'data'}, - ) + self.assertDictEqual(self.channel._handle_message( + self.channel.subclient, + ['type', 'channel', 'data']), + {'type': 'type', + 'pattern': None, + 'channel': 'channel', + 'data': 'data'}) def test_brpop_start_but_no_queues(self): self.assertIsNone(self.channel._brpop_start()) @@ -290,9 +285,8 @@ class test_Channel(TestCase): def test_receive(self): s = self.channel.subclient = Mock() self.channel._fanout_to_queue['a'] = 'b' - s.parse_response.return_value = [ - 'message', 'a', dumps({'hello': 'world'}), - ] + s.parse_response.return_value = ['message', 'a', + dumps({'hello': 'world'})] payload, queue = self.channel._receive() self.assertDictEqual(payload, {'hello': 'world'}) self.assertEqual(queue, 'b') @@ -731,7 +725,8 @@ class test_MultiChannelPoller(TestCase): self.assertEqual(p._register.call_count, 1) self.assertEqual(channel._subscribe.call_count, 1) - def create_get(self, events=None, queues=None, fanouts=None): + def create_get(self, events=None, queues=None, + fanouts=None): _pr = [] if events is None else events _aq = [] if queues is None else queues _af = [] if fanouts is None else fanouts diff --git a/kombu/tests/transport/test_sqlalchemy.py b/kombu/tests/transport/test_sqlalchemy.py index f3d7d239..27cc4323 100644 --- a/kombu/tests/transport/test_sqlalchemy.py +++ b/kombu/tests/transport/test_sqlalchemy.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from __future__ import with_statement from mock import patch from nose import SkipTest diff --git a/kombu/tests/transport/test_transport.py b/kombu/tests/transport/test_transport.py index 608b9767..11cdcbe3 100644 --- a/kombu/tests/transport/test_transport.py +++ b/kombu/tests/transport/test_transport.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from __future__ import with_statement from mock import patch diff --git a/kombu/tests/transport/virtual/test_base.py b/kombu/tests/transport/virtual/test_base.py index 571c6e17..4adfa9e6 100644 --- a/kombu/tests/transport/virtual/test_base.py +++ b/kombu/tests/transport/virtual/test_base.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from __future__ import with_statement import warnings @@ -9,6 +10,7 @@ from kombu.exceptions import StdChannelError from kombu.transport import virtual from kombu.utils import uuid +from kombu.tests.compat import catch_warnings from kombu.tests.utils import TestCase from kombu.tests.utils import Mock, redirect_stdouts @@ -64,7 +66,7 @@ class test_QoS(TestCase): self.q.append(i + 1, uuid()) self.assertFalse(self.q.can_consume()) - tag1 = next(iter(self.q._delivered)) + tag1 = iter(self.q._delivered).next() self.q.ack(tag1) self.assertTrue(self.q.can_consume()) @@ -284,7 +286,7 @@ class test_Channel(TestCase): self.assertIn(n, c.purged) def test_basic_publish__get__consume__restore(self, - n='test_basic_publish'): + n='test_basic_publish'): c = memory_client().channel() c.exchange_declare(n) @@ -305,7 +307,7 @@ class test_Channel(TestCase): consumer_tag = uuid() c.basic_consume(n + '2', False, consumer_tag=consumer_tag, - callback=lambda *a: None) + callback=lambda *a: None) self.assertIn(n + '2', c._active_queues) r2, _ = c.drain_events() r2 = c.message_to_python(r2) @@ -363,7 +365,7 @@ class test_Channel(TestCase): @patch('kombu.transport.virtual.emergency_dump_state') @patch('kombu.transport.virtual.say') def test_restore_unacked_once_when_unrestored(self, say, - emergency_dump_state): + emergency_dump_state): q = self.channel.qos q._flush = Mock() @@ -406,11 +408,9 @@ class test_Channel(TestCase): def test_lookup__undeliverable(self, n='test_lookup__undeliverable'): warnings.resetwarnings() - with warnings.catch_warnings(record=True) as log: - self.assertListEqual( - self.channel._lookup(n, n, 'ae.undeliver'), - ['ae.undeliver'], - ) + with catch_warnings(record=True) as log: + self.assertListEqual(self.channel._lookup(n, n, 'ae.undeliver'), + ['ae.undeliver']) self.assertTrue(log) self.assertIn('could not be delivered', log[0].message.args[0]) diff --git a/kombu/tests/transport/virtual/test_exchange.py b/kombu/tests/transport/virtual/test_exchange.py index d59aaa06..d1b2a85a 100644 --- a/kombu/tests/transport/virtual/test_exchange.py +++ b/kombu/tests/transport/virtual/test_exchange.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from __future__ import with_statement from kombu import Connection from kombu.transport.virtual import exchange @@ -24,18 +25,15 @@ class test_Direct(ExchangeCase): ('rBaz', None, 'qBaz')] def test_lookup(self): - self.assertListEqual( - self.e.lookup(self.table, 'eFoo', 'rFoo', None), - ['qFoo', 'qFox'], - ) - self.assertListEqual( - self.e.lookup(self.table, 'eMoz', 'rMoz', 'DEFAULT'), - [], - ) - self.assertListEqual( - self.e.lookup(self.table, 'eBar', 'rBar', None), - ['qBar'], - ) + self.assertListEqual(self.e.lookup( + self.table, 'eFoo', 'rFoo', None), + ['qFoo', 'qFox']) + self.assertListEqual(self.e.lookup( + self.table, 'eMoz', 'rMoz', 'DEFAULT'), + []) + self.assertListEqual(self.e.lookup( + self.table, 'eBar', 'rBar', None), + ['qBar']) class test_Fanout(ExchangeCase): @@ -45,10 +43,9 @@ class test_Fanout(ExchangeCase): (None, None, 'qBar')] def test_lookup(self): - self.assertListEqual( - self.e.lookup(self.table, 'eFoo', 'rFoo', None), - ['qFoo', 'qFox', 'qBar'], - ) + self.assertListEqual(self.e.lookup( + self.table, 'eFoo', 'rFoo', None), + ['qFoo', 'qFox', 'qBar']) def test_deliver_when_fanout_supported(self): self.e.channel = Mock() @@ -69,36 +66,31 @@ class test_Fanout(ExchangeCase): class test_Topic(ExchangeCase): type = exchange.TopicExchange table = [('stock.#', None, 'rFoo'), - ('stock.us.*', None, 'rBar')] + ('stock.us.*', None, 'rBar')] def setUp(self): super(test_Topic, self).setUp() self.table = [(rkey, self.e.key_to_pattern(rkey), queue) - for rkey, _, queue in self.table] + for rkey, _, queue in self.table] def test_prepare_bind(self): x = self.e.prepare_bind('qFoo', 'eFoo', 'stock.#', {}) self.assertTupleEqual(x, ('stock.#', r'^stock\..*?$', 'qFoo')) def test_lookup(self): - self.assertListEqual( - self.e.lookup(self.table, 'eFoo', 'stock.us.nasdaq', None), - ['rFoo', 'rBar'], - ) + self.assertListEqual(self.e.lookup( + self.table, 'eFoo', 'stock.us.nasdaq', None), + ['rFoo', 'rBar']) self.assertTrue(self.e._compiled) - self.assertListEqual( - self.e.lookup(self.table, 'eFoo', 'stock.europe.OSE', None), - ['rFoo'], - ) - self.assertListEqual( - self.e.lookup(self.table, 'eFoo', 'stockxeuropexOSE', None), - [], - ) - self.assertListEqual( - self.e.lookup(self.table, 'eFoo', - 'candy.schleckpulver.snap_crackle', None), - [], - ) + self.assertListEqual(self.e.lookup( + self.table, 'eFoo', 'stock.europe.OSE', None), + ['rFoo']) + self.assertListEqual(self.e.lookup( + self.table, 'eFoo', 'stockxeuropexOSE', None), + []) + self.assertListEqual(self.e.lookup( + self.table, 'eFoo', 'candy.schleckpulver.snap_crackle', None), + []) def test_deliver(self): self.e.channel = Mock() @@ -119,10 +111,8 @@ class test_ExchangeType(ExchangeCase): self.e.lookup([], 'eFoo', 'rFoo', None) def test_prepare_bind(self): - self.assertTupleEqual( - self.e.prepare_bind('qFoo', 'eFoo', 'rFoo', {}), - ('rFoo', None, 'qFoo'), - ) + self.assertTupleEqual(self.e.prepare_bind('qFoo', 'eFoo', 'rFoo', {}), + ('rFoo', None, 'qFoo')) def test_equivalent(self): e1 = dict(type='direct', @@ -130,23 +120,20 @@ class test_ExchangeType(ExchangeCase): auto_delete=True, arguments={}) self.assertTrue( - self.e.equivalent(e1, 'eFoo', 'direct', True, True, {})) + self.e.equivalent(e1, 'eFoo', 'direct', True, True, {})) self.assertFalse( - self.e.equivalent(e1, 'eFoo', 'topic', True, True, {})) + self.e.equivalent(e1, 'eFoo', 'topic', True, True, {})) self.assertFalse( - self.e.equivalent(e1, 'eFoo', 'direct', False, True, {})) + self.e.equivalent(e1, 'eFoo', 'direct', False, True, {})) self.assertFalse( - self.e.equivalent(e1, 'eFoo', 'direct', True, False, {})) + self.e.equivalent(e1, 'eFoo', 'direct', True, False, {})) self.assertFalse( - self.e.equivalent(e1, 'eFoo', 'direct', True, True, - {'expires': 3000}), - ) + self.e.equivalent(e1, 'eFoo', 'direct', True, True, { + 'expires': 3000})) e2 = dict(e1, arguments={'expires': 3000}) self.assertTrue( - self.e.equivalent(e2, 'eFoo', 'direct', True, True, - {'expires': 3000}), - ) + self.e.equivalent(e2, 'eFoo', 'direct', True, True, { + 'expires': 3000})) self.assertFalse( - self.e.equivalent(e2, 'eFoo', 'direct', True, True, - {'expires': 6000}), - ) + self.e.equivalent(e2, 'eFoo', 'direct', True, True, { + 'expires': 6000})) diff --git a/kombu/tests/transport/virtual/test_scheduling.py b/kombu/tests/transport/virtual/test_scheduling.py index 1a6c32bc..afbcd061 100644 --- a/kombu/tests/transport/virtual/test_scheduling.py +++ b/kombu/tests/transport/virtual/test_scheduling.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from __future__ import with_statement from kombu.transport.virtual.scheduling import FairCycle @@ -42,16 +43,12 @@ class test_FairCycle(TestCase): return r cycle = FairCycle(echo, resources, MyEmpty) - self.assertEqual( - consume(cycle.get, len(resources)), - [('a', 'a'), ('b', 'b'), ('d', 'd'), - ('e', 'e'), ('a', 'a')], - ) - self.assertEqual( - consume(cycle.get, len(resources)), - [('b', 'b'), ('d', 'd'), ('e', 'e'), - ('a', 'a'), ('b', 'b')], - ) + self.assertEqual(consume(cycle.get, len(resources)), + [('a', 'a'), ('b', 'b'), ('d', 'd'), + ('e', 'e'), ('a', 'a')]) + self.assertEqual(consume(cycle.get, len(resources)), + [('b', 'b'), ('d', 'd'), ('e', 'e'), + ('a', 'a'), ('b', 'b')]) cycle2 = FairCycle(echo, ['c', 'c'], MyEmpty) with self.assertRaises(MyEmpty): consume(cycle2.get, 3) diff --git a/kombu/tests/utilities/test_amq_manager.py b/kombu/tests/utilities/test_amq_manager.py index e030810e..1dcd761b 100644 --- a/kombu/tests/utilities/test_amq_manager.py +++ b/kombu/tests/utilities/test_amq_manager.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from __future__ import with_statement from mock import patch @@ -18,9 +19,8 @@ class test_get_manager(TestCase): with patch('pyrabbit.Client', create=True) as Client: manager = Connection('amqp://').get_manager() self.assertIsNotNone(manager) - Client.assert_called_with( - 'localhost:55672', 'guest', 'guest', - ) + Client.assert_called_with('localhost:55672', + 'guest', 'guest') @module_exists('pyrabbit') def test_transport_options(self): @@ -32,6 +32,5 @@ class test_get_manager(TestCase): 'manager_password': 'bosco', }).get_manager() self.assertIsNotNone(manager) - Client.assert_called_with( - 'admin.mq.vandelay.com:808', 'george', 'bosco', - ) + Client.assert_called_with('admin.mq.vandelay.com:808', + 'george', 'bosco') diff --git a/kombu/tests/utilities/test_debug.py b/kombu/tests/utilities/test_debug.py index d364400f..dbe8a2af 100644 --- a/kombu/tests/utilities/test_debug.py +++ b/kombu/tests/utilities/test_debug.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from __future__ import with_statement import logging diff --git a/kombu/tests/utilities/test_encoding.py b/kombu/tests/utilities/test_encoding.py index 5c2607e7..eb19d1ad 100644 --- a/kombu/tests/utilities/test_encoding.py +++ b/kombu/tests/utilities/test_encoding.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals +from __future__ import absolute_import +from __future__ import with_statement import sys @@ -43,16 +44,16 @@ class test_encoding_utils(TestCase): def test_str_to_bytes(self): with clean_encoding() as e: - self.assertIsInstance(e.str_to_bytes('foobar'), str) + self.assertIsInstance(e.str_to_bytes(u'foobar'), str) self.assertIsInstance(e.str_to_bytes('foobar'), str) def test_from_utf8(self): with clean_encoding() as e: - self.assertIsInstance(e.from_utf8('foobar'), str) + self.assertIsInstance(e.from_utf8(u'foobar'), str) def test_default_encode(self): with clean_encoding() as e: - self.assertTrue(e.default_encode(b'foo')) + self.assertTrue(e.default_encode('foo')) class test_safe_str(TestCase): @@ -61,10 +62,10 @@ class test_safe_str(TestCase): self.assertEqual(safe_str('foo'), 'foo') def test_when_unicode(self): - self.assertIsInstance(safe_str('foo'), str) + self.assertIsInstance(safe_str(u'foo'), str) def test_when_containing_high_chars(self): - s = 'The quiæk fåx jømps øver the lazy dåg' + s = u'The quiæk fåx jømps øver the lazy dåg' res = safe_str(s) self.assertIsInstance(res, str) diff --git a/kombu/tests/utilities/test_functional.py b/kombu/tests/utilities/test_functional.py index b20ad5b7..c84a6854 100644 --- a/kombu/tests/utilities/test_functional.py +++ b/kombu/tests/utilities/test_functional.py @@ -14,16 +14,12 @@ def double(x): class test_promise(TestCase): def test__str__(self): - self.assertEqual( - str(promise(lambda: 'the quick brown fox')), - 'the quick brown fox', - ) + self.assertEqual(str(promise(lambda: 'the quick brown fox')), + 'the quick brown fox') def test__repr__(self): - self.assertEqual( - repr(promise(lambda: 'fi fa fo')), - "'fi fa fo'", - ) + self.assertEqual(repr(promise(lambda: 'fi fa fo')), + "'fi fa fo'") def test_evaluate(self): self.assertEqual(promise(lambda: 2 + 2)(), 4) diff --git a/kombu/tests/utils.py b/kombu/tests/utils.py index 82830dad..61c98b66 100644 --- a/kombu/tests/utils.py +++ b/kombu/tests/utils.py @@ -1,10 +1,12 @@ from __future__ import absolute_import +import __builtin__ import os import sys import types from functools import wraps +from StringIO import StringIO import mock @@ -16,8 +18,6 @@ try: except AttributeError: import unittest2 as unittest # noqa -from kombu.five import StringIO, builtins, string_t, module_name_t - class TestCase(unittest.TestCase): @@ -60,8 +60,8 @@ def redirect_stdouts(fun): sys.stdout = StringIO() sys.stderr = StringIO() try: - return fun(*args, **dict(kwargs, - stdout=sys.stdout, stderr=sys.stderr)) + return fun(*args, **dict(kwargs, stdout=sys.stdout, + stderr=sys.stderr)) finally: sys.stdout = sys.__stdout__ sys.stderr = sys.__stderr__ @@ -76,8 +76,8 @@ def module_exists(*modules): @wraps(fun) def __inner(*args, **kwargs): for module in modules: - if isinstance(module, string_t): - module = types.ModuleType(module_name_t(module)) + if isinstance(module, basestring): + module = types.ModuleType(module) sys.modules[module.__name__] = module try: return fun(*args, **kwargs) @@ -95,19 +95,19 @@ def mask_modules(*modnames): @wraps(fun) def __inner(*args, **kwargs): - realimport = builtins.__import__ + realimport = __builtin__.__import__ def myimp(name, *args, **kwargs): if name in modnames: - raise ImportError('No module named {0}'.format(name)) + raise ImportError('No module named %s' % name) else: return realimport(name, *args, **kwargs) - builtins.__import__ = myimp + __builtin__.__import__ = myimp try: return fun(*args, **kwargs) finally: - builtins.__import__ = realimport + __builtin__.__import__ = realimport return __inner return _inner @@ -120,7 +120,7 @@ def skip_if_environ(env_var_name): @wraps(fun) def _skips_if_environ(*args, **kwargs): if os.environ.get(env_var_name): - raise SkipTest('SKIP {0}: {1} set'.format( + raise SkipTest('SKIP %s: %s set\n' % ( fun.__name__, env_var_name)) return fun(*args, **kwargs) @@ -135,7 +135,7 @@ def skip_if_module(module): def _skip_if_module(*args, **kwargs): try: __import__(module) - raise SkipTest('SKIP {0}: {1} available'.format( + raise SkipTest('SKIP %s: %s available\n' % ( fun.__name__, module)) except ImportError: pass @@ -151,7 +151,7 @@ def skip_if_not_module(module): try: __import__(module) except ImportError: - raise SkipTest('SKIP {0}: {1} available'.format( + raise SkipTest('SKIP %s: %s available\n' % ( fun.__name__, module)) return fun(*args, **kwargs) return _skip_if_not_module diff --git a/kombu/utils/amq_manager.py b/kombu/utils/amq_manager.py index 30419ae6..08ee3939 100644 --- a/kombu/utils/amq_manager.py +++ b/kombu/utils/amq_manager.py @@ -8,7 +8,7 @@ def get_manager(client, hostname=None, port=None, userid=None, def get(name, val, default): return (val if val is not None - else opt.get('manager_%s' % name) + else opt('manager_%s' % name) or getattr(client, name, None) or default) host = get('hostname', hostname, 'localhost') From dd0fe3a3a6a1bb50209e697d7bef91473661bee2 Mon Sep 17 00:00:00 2001 From: Ask Solem Date: Thu, 17 Jan 2013 13:50:01 +0000 Subject: [PATCH 2/9] More pep8ify --- docs/_ext/applyxrefs.py | 4 +- docs/_ext/literals_to_xrefs.py | 6 +- docs/conf.py | 4 +- examples/simple_task_queue/client.py | 9 +- extra/release/bump_version.py | 2 +- extra/release/flakeplus.py | 2 +- funtests/setup.py | 2 +- funtests/transport.py | 18 +- kombu/tests/__init__.py | 17 +- kombu/tests/compat.py | 8 +- kombu/tests/mocks.py | 13 +- kombu/tests/test_common.py | 3 +- kombu/tests/test_compat.py | 19 +- kombu/tests/test_connection.py | 73 +++--- kombu/tests/test_entities.py | 24 +- kombu/tests/test_log.py | 15 +- kombu/tests/test_messaging.py | 8 +- kombu/tests/test_pidbox.py | 18 +- kombu/tests/test_serialization.py | 238 ++++++++++-------- kombu/tests/test_utils.py | 58 +++-- kombu/tests/transport/test_amqplib.py | 8 +- kombu/tests/transport/test_base.py | 5 +- kombu/tests/transport/test_pyamqp.py | 14 +- kombu/tests/transport/test_redis.py | 41 +-- kombu/tests/transport/virtual/test_base.py | 14 +- .../tests/transport/virtual/test_exchange.py | 108 ++++---- .../transport/virtual/test_scheduling.py | 16 +- kombu/tests/utilities/test_amq_manager.py | 10 +- kombu/tests/utilities/test_functional.py | 12 +- kombu/tests/utils.py | 4 +- pavement.py | 5 +- setup.py | 5 +- 32 files changed, 456 insertions(+), 327 deletions(-) diff --git a/docs/_ext/applyxrefs.py b/docs/_ext/applyxrefs.py index 027490b8..93222a33 100644 --- a/docs/_ext/applyxrefs.py +++ b/docs/_ext/applyxrefs.py @@ -5,9 +5,7 @@ import os testing = False -DONT_TOUCH = ( - './index.txt', - ) +DONT_TOUCH = ('./index.txt', ) def target_name(fn): diff --git a/docs/_ext/literals_to_xrefs.py b/docs/_ext/literals_to_xrefs.py index e9dc7ca0..f1497565 100644 --- a/docs/_ext/literals_to_xrefs.py +++ b/docs/_ext/literals_to_xrefs.py @@ -95,8 +95,10 @@ def fixliterals(fname): replace_type in ("class", "func", "meth"): default = default[:-2] replace_value = raw_input( - colorize("Text [", fg="yellow") + default + \ - colorize("]: ", fg="yellow")).strip() + colorize("Text [", fg="yellow") + + default + + colorize("]: ", fg="yellow"), + ).strip() if not replace_value: replace_value = default new.append(":%s:`%s`" % (replace_type, replace_value)) diff --git a/docs/conf.py b/docs/conf.py index 27534746..bf39ded2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -62,8 +62,8 @@ html_use_modindex = True html_use_index = True latex_documents = [ - ('index', 'Kombu.tex', ur'Kombu Documentation', - ur'Ask Solem', 'manual'), + ('index', 'Kombu.tex', u'Kombu Documentation', + u'Ask Solem', 'manual'), ] html_theme = "celery" diff --git a/examples/simple_task_queue/client.py b/examples/simple_task_queue/client.py index fe0a512b..b4731061 100644 --- a/examples/simple_task_queue/client.py +++ b/examples/simple_task_queue/client.py @@ -16,10 +16,11 @@ def send_as_task(connection, fun, args=(), kwargs={}, priority='mid'): with producers[connection].acquire(block=True) as producer: maybe_declare(task_exchange, producer.channel) - producer.publish(payload, serializer='pickle', - compression='bzip2', - exchange=task_exchange, - routing_key=routing_key) + producer.publish(payload, + serializer='pickle', + compression='bzip2', + exchange=task_exchange, + routing_key=routing_key) if __name__ == '__main__': from kombu import Connection diff --git a/extra/release/bump_version.py b/extra/release/bump_version.py index ccf7355e..5798f6a0 100755 --- a/extra/release/bump_version.py +++ b/extra/release/bump_version.py @@ -149,7 +149,7 @@ def bump(*files, **kwargs): v.write(next) print(cmd("git", "commit", "-m", "Bumps version to %s" % (to_str(next), ), - *[f.filename for f in files])) + *[f.filename for f in files])) print(cmd("git", "tag", "v%s" % (to_str(next), ))) diff --git a/extra/release/flakeplus.py b/extra/release/flakeplus.py index 6fe1f1fc..4e1efd47 100755 --- a/extra/release/flakeplus.py +++ b/extra/release/flakeplus.py @@ -37,7 +37,7 @@ class FlakePP(object): re_with = compile(RE_WITH) re_noqa = compile(RE_NOQA) map = {"abs": True, "print": False, - "with": False, "with-used": False} + "with": False, "with-used": False} def __init__(self, verbose=False): self.verbose = verbose diff --git a/funtests/setup.py b/funtests/setup.py index fdb7a98c..a7ad8b4e 100644 --- a/funtests/setup.py +++ b/funtests/setup.py @@ -8,7 +8,7 @@ except ImportError: from ez_setup import use_setuptools use_setuptools() from setuptools import setup # noqa - from setuptools.command.install import install # noqa + from setuptools.command.install import install # noqa class no_install(install): diff --git a/funtests/transport.py b/funtests/transport.py index 5924a72a..f6ae1e17 100644 --- a/funtests/transport.py +++ b/funtests/transport.py @@ -40,7 +40,7 @@ def consumeN(conn, consumer, n=1, timeout=30): except socket.timeout: seconds += 1 msg = "Received %s/%s messages. %s seconds passed." % ( - len(messages), n, seconds) + len(messages), n, seconds) if seconds >= timeout: raise socket.timeout(msg) if seconds > 1: @@ -113,7 +113,7 @@ class TransportCase(unittest.TestCase): self.after_connect(self.connection) except self.connection.connection_errors: self.skip_test_reason = "%s transport can't connect" % ( - self.transport, ) + self.transport, ) else: self.connected = True @@ -161,14 +161,15 @@ class TransportCase(unittest.TestCase): return _digest(data).hexdigest() @skip_if_quick - def test_produce__consume_large_messages(self, bytes=1048576, n=10, + def test_produce__consume_large_messages( + self, bytes=1048576, n=10, charset=string.punctuation + string.letters + string.digits): if not self.verify_alive(): return bytes = min(filter(None, [bytes, self.message_size_limit])) messages = ["".join(random.choice(charset) - for j in xrange(bytes)) + "--%s" % n - for i in xrange(n)] + for j in xrange(bytes)) + "--%s" % n + for i in xrange(n)] digests = [] chan1 = self.connection.channel() consumer = chan1.Consumer(self.queue) @@ -180,7 +181,7 @@ class TransportCase(unittest.TestCase): digests.append(self._digest(message)) received = [(msg["i"], msg["text"]) - for msg in consumeN(self.connection, consumer, n)] + for msg in consumeN(self.connection, consumer, n)] self.assertEqual(len(received), n) ordering = [i for i, _ in received] if ordering != range(n) and not self.suppress_disorder_warning: @@ -229,8 +230,9 @@ class TransportCase(unittest.TestCase): chan = self.connection.channel() self.purge([self.queue.name]) consumer = chan.Consumer(self.queue) - self.assertRaises(socket.timeout, self.connection.drain_events, - timeout=0.3) + self.assertRaises( + socket.timeout, self.connection.drain_events, timeout=0.3, + ) consumer.cancel() chan.close() diff --git a/kombu/tests/__init__.py b/kombu/tests/__init__.py index 730d9404..6a13a750 100644 --- a/kombu/tests/__init__.py +++ b/kombu/tests/__init__.py @@ -52,12 +52,17 @@ def setup_django_env(): return if not settings.configured: - settings.configure(DATABASES={'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': ':memory:'}}, - DATABASE_ENGINE='sqlite3', - DATABASE_NAME=':memory:', - INSTALLED_APPS=('kombu.transport.django', )) + settings.configure( + DATABASES={ + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:', + }, + }, + DATABASE_ENGINE='sqlite3', + DATABASE_NAME=':memory:', + INSTALLED_APPS=('kombu.transport.django', ), + ) def setup(): diff --git a/kombu/tests/compat.py b/kombu/tests/compat.py index 391b7f1a..e750552b 100644 --- a/kombu/tests/compat.py +++ b/kombu/tests/compat.py @@ -10,8 +10,8 @@ class WarningMessage(object): _WARNING_DETAILS = ('message', 'category', 'filename', 'lineno', 'file', 'line') - def __init__(self, message, category, filename, lineno, file=None, - line=None): + def __init__(self, message, category, filename, lineno, + file=None, line=None): local_values = locals() for attr in self._WARNING_DETAILS: setattr(self, attr, local_values[attr]) @@ -20,8 +20,8 @@ class WarningMessage(object): def __str__(self): return ('{message : %r, category : %r, filename : %r, lineno : %s, ' - 'line : %r}' % (self.message, self._category_name, - self.filename, self.lineno, self.line)) + 'line : %r}' % (self.message, self._category_name, + self.filename, self.lineno, self.line)) class catch_warnings(object): diff --git a/kombu/tests/mocks.py b/kombu/tests/mocks.py index 16aa4389..4d38da56 100644 --- a/kombu/tests/mocks.py +++ b/kombu/tests/mocks.py @@ -42,7 +42,7 @@ class Channel(base.StdChannel): self._called('exchange_declare') def prepare_message(self, body, priority=0, content_type=None, - content_encoding=None, headers=None, properties={}): + content_encoding=None, headers=None, properties={}): self._called('prepare_message') return dict(body=body, headers=headers, @@ -52,7 +52,7 @@ class Channel(base.StdChannel): content_encoding=content_encoding) def basic_publish(self, message, exchange='', routing_key='', - mandatory=False, immediate=False, **kwargs): + mandatory=False, immediate=False, **kwargs): self._called('basic_publish') return message, exchange, routing_key @@ -105,9 +105,10 @@ class Channel(base.StdChannel): def message_to_python(self, message, *args, **kwargs): self._called('message_to_python') return Message(self, body=anyjson.dumps(message), - delivery_tag=self.deliveries(), - throw_decode_error=self.throw_decode_error, - content_type='application/json', content_encoding='utf-8') + delivery_tag=self.deliveries(), + throw_decode_error=self.throw_decode_error, + content_type='application/json', + content_encoding='utf-8') def flow(self, active): self._called('flow') @@ -118,7 +119,7 @@ class Channel(base.StdChannel): return self._called('basic_reject') def basic_qos(self, prefetch_size=0, prefetch_count=0, - apply_global=False): + apply_global=False): self._called('basic_qos') diff --git a/kombu/tests/test_common.py b/kombu/tests/test_common.py index c97fe4ef..978687e3 100644 --- a/kombu/tests/test_common.py +++ b/kombu/tests/test_common.py @@ -226,7 +226,8 @@ class test_insured(TestCase): ret = common.insured(pool, fun, (2, 2), {'foo': 'bar'}) self.assertEqual(ret, 'works') conn.ensure_connection.assert_called_with( - errback=common._ensure_errback) + errback=common._ensure_errback, + ) self.assertTrue(insured.called) i_args, i_kwargs = insured.call_args diff --git a/kombu/tests/test_compat.py b/kombu/tests/test_compat.py index 36a60d39..7e80e21f 100644 --- a/kombu/tests/test_compat.py +++ b/kombu/tests/test_compat.py @@ -102,7 +102,7 @@ class test_Publisher(TestCase): self.assertFalse(pub2.exchange.durable) explicit = Exchange('test_Publisher_constructor_explicit', - type='topic') + type='topic') pub3 = compat.Publisher(self.connection, exchange=explicit) self.assertEqual(pub3.exchange, explicit) @@ -241,8 +241,8 @@ class test_Consumer(TestCase): for i in range(limit): yield i - c = C(self.connection, queue=n, exchange=n, - routing_key='rkey') + c = C(self.connection, + queue=n, exchange=n, routing_key='rkey') self.assertEqual(c.wait(10), range(10)) c.close() @@ -256,8 +256,8 @@ class test_Consumer(TestCase): i[0] += 1 return z - c = C(self.connection, queue=n, exchange=n, - routing_key='rkey') + c = C(self.connection, + queue=n, exchange=n, routing_key='rkey') self.assertEqual(list(c.iterqueue(limit=10)), range(10)) c.close() @@ -289,7 +289,7 @@ class test_ConsumerSet(TestCase): 'routing_key': 'xyz'}} consumers = [compat.Consumer(self.connection, queue=prefix + str(i), exchange=prefix + str(i)) - for i in range(3)] + for i in range(3)] c = compat.ConsumerSet(self.connection, consumers=consumers) c2 = compat.ConsumerSet(self.connection, from_dict=dcon) @@ -303,9 +303,12 @@ class test_ConsumerSet(TestCase): for cq in c.queues: self.assertIs(cq.channel, c.channel) - c2.add_consumer_from_dict({'%s.xxx' % prefix: { + c2.add_consumer_from_dict({ + '%s.xxx' % prefix: { 'exchange': '%s.xxx' % prefix, - 'routing_key': 'xxx'}}) + 'routing_key': 'xxx', + }, + }) self.assertEqual(len(c2.queues), 3) for c2q in c2.queues: self.assertIs(c2q.channel, c2.channel) diff --git a/kombu/tests/test_connection.py b/kombu/tests/test_connection.py index 6997be69..f3c4120a 100644 --- a/kombu/tests/test_connection.py +++ b/kombu/tests/test_connection.py @@ -68,77 +68,78 @@ class test_connection_utils(TestCase): self.assert_info( Connection('amqp://user:pass@host:10000/vhost'), - userid='user', password='pass', hostname='host', - port=10000, virtual_host='vhost') + userid='user', password='pass', hostname='host', + port=10000, virtual_host='vhost', + ) self.assert_info( Connection('amqp://user%61:%61pass@ho%61st:10000/v%2fhost'), - userid='usera', password='apass', - hostname='hoast', port=10000, - virtual_host='v/host') + userid='usera', password='apass', hostname='hoast', + port=10000, virtual_host='v/host', + ) self.assert_info( Connection('amqp://'), - userid='guest', password='guest', - hostname='localhost', port=5672, - virtual_host='/') + userid='guest', password='guest', hostname='localhost', + port=5672, virtual_host='/', + ) self.assert_info( Connection('amqp://:@/'), - userid='guest', password='guest', - hostname='localhost', port=5672, - virtual_host='/') + userid='guest', password='guest', hostname='localhost', + port=5672, virtual_host='/', + ) self.assert_info( Connection('amqp://user@/'), - userid='user', password='guest', - hostname='localhost', port=5672, - virtual_host='/') + userid='user', password='guest', hostname='localhost', + port=5672, virtual_host='/', + ) self.assert_info( Connection('amqp://user:pass@/'), - userid='user', password='pass', - hostname='localhost', port=5672, - virtual_host='/') + userid='user', password='pass', hostname='localhost', + port=5672, virtual_host='/', + ) self.assert_info( Connection('amqp://host'), - userid='guest', password='guest', - hostname='host', port=5672, - virtual_host='/') + userid='guest', password='guest', hostname='host', + port=5672, virtual_host='/', + ) self.assert_info( Connection('amqp://:10000'), - userid='guest', password='guest', - hostname='localhost', port=10000, - virtual_host='/') + userid='guest', password='guest', hostname='localhost', + port=10000, virtual_host='/', + ) self.assert_info( Connection('amqp:///vhost'), - userid='guest', password='guest', - hostname='localhost', port=5672, - virtual_host='vhost') + userid='guest', password='guest', hostname='localhost', + port=5672, virtual_host='vhost', + ) self.assert_info( Connection('amqp://host/'), - userid='guest', password='guest', - hostname='host', port=5672, - virtual_host='/') + userid='guest', password='guest', hostname='host', + port=5672, virtual_host='/', + ) self.assert_info( Connection('amqp://host/%2f'), - userid='guest', password='guest', - hostname='host', port=5672, - virtual_host='/') + userid='guest', password='guest', hostname='host', + port=5672, virtual_host='/', + ) def test_url_IPV6(self): raise SkipTest("urllib can't parse ipv6 urls") self.assert_info( Connection('amqp://[::1]'), - userid='guest', password='guest', - hostname='[::1]', port=5672, - virtual_host='/') + userid='guest', password='guest', hostname='[::1]', + port=5672, virtual_host='/', + ) class test_Connection(TestCase): @@ -635,7 +636,7 @@ class test_ChannelPool(ResourceCase): def create_resource(self, limit, preload): return Connection(port=5672, transport=Transport) \ - .ChannelPool(limit, preload) + .ChannelPool(limit, preload) def test_setup(self): P = self.create_resource(10, 2) diff --git a/kombu/tests/test_entities.py b/kombu/tests/test_entities.py index 7c2f25a4..8e89f84e 100644 --- a/kombu/tests/test_entities.py +++ b/kombu/tests/test_entities.py @@ -20,7 +20,8 @@ def get_conn(): class test_binding(TestCase): def test_constructor(self): - x = binding(Exchange('foo'), 'rkey', + x = binding( + Exchange('foo'), 'rkey', arguments={'barg': 'bval'}, unbind_arguments={'uarg': 'uval'}, ) @@ -235,14 +236,16 @@ class test_Queue(TestCase): ]) q(chan).declare() self.assertIn( - call(nowait=False, - exchange='mul1', - auto_delete=False, - passive=False, - arguments=None, - type='direct', - durable=True, - ), chan.exchange_declare.call_args_list, + call( + nowait=False, + exchange='mul1', + auto_delete=False, + passive=False, + arguments=None, + type='direct', + durable=True, + ), + chan.exchange_declare.call_args_list, ) def test_can_cache_declaration(self): @@ -260,7 +263,8 @@ class test_Queue(TestCase): def test_exclusive_implies_auto_delete(self): self.assertTrue( - Queue('foo', self.exchange, exclusive=True).auto_delete) + Queue('foo', self.exchange, exclusive=True).auto_delete, + ) def test_binds_at_instantiation(self): self.assertTrue(Queue('foo', self.exchange, diff --git a/kombu/tests/test_log.py b/kombu/tests/test_log.py index 62dd1b35..b9cf966b 100644 --- a/kombu/tests/test_log.py +++ b/kombu/tests/test_log.py @@ -80,13 +80,15 @@ class test_LogMixin(TestCase): def test_error(self): self.log.error('error', exc_info='exc') - self.logger.log.assert_called_with(logging.ERROR, 'Log - error', - exc_info='exc') + self.logger.log.assert_called_with( + logging.ERROR, 'Log - error', exc_info='exc', + ) def test_critical(self): self.log.critical('crit', exc_info='exc') - self.logger.log.assert_called_with(logging.CRITICAL, 'Log - crit', - exc_info='exc') + self.logger.log.assert_called_with( + logging.CRITICAL, 'Log - crit', exc_info='exc', + ) def test_error_when_DISABLE_TRACEBACKS(self): log.DISABLE_TRACEBACKS = True @@ -121,8 +123,9 @@ class test_LogMixin(TestCase): def test_log_with_format(self): self.log.debug('Host %r removed', 'example.com') - self.logger.log.assert_called_with(logging.DEBUG, - 'Log - Host %s removed', "'example.com'") + self.logger.log.assert_called_with( + logging.DEBUG, 'Log - Host %s removed', "'example.com'", + ) class test_setup_logging(TestCase): diff --git a/kombu/tests/test_messaging.py b/kombu/tests/test_messaging.py index a6024497..0fb8a657 100644 --- a/kombu/tests/test_messaging.py +++ b/kombu/tests/test_messaging.py @@ -87,8 +87,10 @@ class test_Producer(TestCase): self.assertEqual(cencoding, 'utf-8') self.assertEqual(headers['compression'], 'application/x-gzip') import zlib - self.assertEqual(anyjson.loads( - zlib.decompress(m).decode('utf-8')), message) + self.assertEqual( + anyjson.loads(zlib.decompress(m).decode('utf-8')), + message, + ) def test_prepare_custom_content_type(self): message = 'the quick brown fox'.encode('utf-8') @@ -113,7 +115,7 @@ class test_Producer(TestCase): self.assertEqual(ctype, 'text/plain') self.assertEqual(cencoding, 'utf-8') m, ctype, cencoding = p._prepare(message, content_type='text/plain', - content_encoding='utf-8') + content_encoding='utf-8') self.assertEqual(m, message.encode('utf-8')) self.assertEqual(ctype, 'text/plain') self.assertEqual(cencoding, 'utf-8') diff --git a/kombu/tests/test_pidbox.py b/kombu/tests/test_pidbox.py index 33e071a7..d250eedb 100644 --- a/kombu/tests/test_pidbox.py +++ b/kombu/tests/test_pidbox.py @@ -29,9 +29,11 @@ class test_Mailbox(TestCase): self.handlers = {'mymethod': self._handler} self.bound = self.mailbox(self.connection) self.default_chan = self.connection.channel() - self.node = self.bound.Node('test_pidbox', state=self.state, - handlers=self.handlers, - channel=self.default_chan) + self.node = self.bound.Node( + 'test_pidbox', + state=self.state, handlers=self.handlers, + channel=self.default_chan, + ) def test_reply__collect(self): mailbox = pidbox.Mailbox('test_reply__collect')(self.connection) @@ -46,8 +48,8 @@ class test_Mailbox(TestCase): def callback(body): _callback_called[0] = True - reply = mailbox._collect(ticket, limit=1, callback=callback, - channel=channel) + reply = mailbox._collect(ticket, limit=1, + callback=callback, channel=channel) self.assertEqual(reply, [{'foo': 'bar'}]) self.assertTrue(_callback_called[0]) @@ -209,8 +211,10 @@ class test_Mailbox(TestCase): self.bound.call('some_node', 'mymethod') def test_call(self): - self.assertEqual(self.bound.call(['some_node'], 'mymethod'), - 'COLLECTED') + self.assertEqual( + self.bound.call(['some_node'], 'mymethod'), + 'COLLECTED', + ) consumer = self.node.Consumer() self.assertIsCall(self.get_next(consumer)) diff --git a/kombu/tests/test_serialization.py b/kombu/tests/test_serialization.py index c4b8bd81..de7ed343 100644 --- a/kombu/tests/test_serialization.py +++ b/kombu/tests/test_serialization.py @@ -22,29 +22,34 @@ latin_string_as_utf8 = latin_string.encode('utf-8') # For serialization tests -py_data = {'string': 'The quick brown fox jumps over the lazy dog', - 'int': 10, - 'float': 3.14159265, - 'unicode': u'Thé quick brown fox jumps over thé lazy dog', - 'list': ['george', 'jerry', 'elaine', 'cosmo'], +py_data = { + 'string': 'The quick brown fox jumps over the lazy dog', + 'int': 10, + 'float': 3.14159265, + 'unicode': u'Thé quick brown fox jumps over thé lazy dog', + 'list': ['george', 'jerry', 'elaine', 'cosmo'], } # JSON serialization tests -json_data = ('{"int": 10, "float": 3.1415926500000002, ' - '"list": ["george", "jerry", "elaine", "cosmo"], ' - '"string": "The quick brown fox jumps over the lazy ' - 'dog", "unicode": "Th\\u00e9 quick brown fox jumps over ' - 'th\\u00e9 lazy dog"}') +json_data = """\ +{"int": 10, "float": 3.1415926500000002, \ +"list": ["george", "jerry", "elaine", "cosmo"], \ +"string": "The quick brown fox jumps over the lazy \ +dog", "unicode": "Th\\u00e9 quick brown fox jumps over \ +th\\u00e9 lazy dog"}\ +""" # Pickle serialization tests pickle_data = pickle.dumps(py_data, protocol=pickle_protocol) # YAML serialization tests -yaml_data = ('float: 3.1415926500000002\nint: 10\n' - 'list: [george, jerry, elaine, cosmo]\n' - 'string: The quick brown fox jumps over the lazy dog\n' - 'unicode: "Th\\xE9 quick brown fox ' - 'jumps over th\\xE9 lazy dog"\n') +yaml_data = """\ +float: 3.1415926500000002 +int: 10 +list: [george, jerry, elaine, cosmo] +string: The quick brown fox jumps over the lazy dog +unicode: "Th\\xE9 quick brown fox jumps over th\\xE9 lazy dog" +""" msgpack_py_data = dict(py_data) @@ -52,10 +57,12 @@ msgpack_py_data = dict(py_data) msgpack_py_data['list'] = tuple(msgpack_py_data['list']) # Unicode chars are lost in transmit :( msgpack_py_data['unicode'] = 'Th quick brown fox jumps over th lazy dog' -msgpack_data = ('\x85\xa3int\n\xa5float\xcb@\t!\xfbS\xc8\xd4\xf1\xa4list' - '\x94\xa6george\xa5jerry\xa6elaine\xa5cosmo\xa6string\xda' - '\x00+The quick brown fox jumps over the lazy dog\xa7unicode' - '\xda\x00)Th quick brown fox jumps over th lazy dog') +msgpack_data = """\ +\x85\xa3int\n\xa5float\xcb@\t!\xfbS\xc8\xd4\xf1\xa4list\ +\x94\xa6george\xa5jerry\xa6elaine\xa5cosmo\xa6string\xda\ +\x00+The quick brown fox jumps over the lazy dog\xa7unicode\ +\xda\x00)Th quick brown fox jumps over th lazy dog\ +""" def say(m): @@ -86,11 +93,13 @@ class test_Serialization(TestCase): registry.disable('testS') with self.assertRaises(SerializerNotInstalled): - registry.decode('xxd', 'application/testS', 'utf-8', - force=False) + registry.decode( + 'xxd', 'application/testS', 'utf-8', force=False, + ) - ret = registry.decode('xxd', 'application/testS', 'utf-8', - force=True) + ret = registry.decode( + 'xxd', 'application/testS', 'utf-8', force=True, + ) self.assertEqual(ret, 'decoded') finally: disabled.clear() @@ -99,114 +108,142 @@ class test_Serialization(TestCase): registry.decode(None, 'application/testS', 'utf-8') def test_content_type_decoding(self): - self.assertEqual(unicode_string, - registry.decode( - unicode_string_as_utf8, - content_type='plain/text', - content_encoding='utf-8')) - self.assertEqual(latin_string, - registry.decode( - latin_string_as_latin1, - content_type='application/data', - content_encoding='latin-1')) + self.assertEqual( + unicode_string, + registry.decode(unicode_string_as_utf8, + content_type='plain/text', + content_encoding='utf-8'), + ) + self.assertEqual( + latin_string, + registry.decode(latin_string_as_latin1, + content_type='application/data', + content_encoding='latin-1'), + ) def test_content_type_binary(self): - self.assertIsInstance(registry.decode(unicode_string_as_utf8, - content_type='application/data', - content_encoding='binary'), - bytes_t) + self.assertIsInstance( + registry.decode(unicode_string_as_utf8, + content_type='application/data', + content_encoding='binary'), + bytes_t, + ) - self.assertEqual(unicode_string_as_utf8, - registry.decode( - unicode_string_as_utf8, - content_type='application/data', - content_encoding='binary')) + self.assertEqual( + unicode_string_as_utf8, + registry.decode(unicode_string_as_utf8, + content_type='application/data', + content_encoding='binary'), + ) def test_content_type_encoding(self): # Using the 'raw' serializer - self.assertEqual(unicode_string_as_utf8, - registry.encode( - unicode_string, serializer='raw')[-1]) - self.assertEqual(latin_string_as_utf8, - registry.encode( - latin_string, serializer='raw')[-1]) + self.assertEqual( + unicode_string_as_utf8, + registry.encode(unicode_string, serializer='raw')[-1], + ) + self.assertEqual( + latin_string_as_utf8, + registry.encode(latin_string, serializer='raw')[-1], + ) # And again w/o a specific serializer to check the # code where we force unicode objects into a string. - self.assertEqual(unicode_string_as_utf8, - registry.encode(unicode_string)[-1]) - self.assertEqual(latin_string_as_utf8, - registry.encode(latin_string)[-1]) + self.assertEqual( + unicode_string_as_utf8, + registry.encode(unicode_string)[-1], + ) + self.assertEqual( + latin_string_as_utf8, + registry.encode(latin_string)[-1], + ) def test_json_decode(self): - self.assertEqual(py_data, - registry.decode( - json_data, - content_type='application/json', - content_encoding='utf-8')) + self.assertEqual( + py_data, + registry.decode(json_data, + content_type='application/json', + content_encoding='utf-8'), + ) def test_json_encode(self): - self.assertEqual(registry.decode( - registry.encode(py_data, serializer='json')[-1], - content_type='application/json', - content_encoding='utf-8'), - registry.decode( - json_data, - content_type='application/json', - content_encoding='utf-8')) + self.assertEqual( + registry.decode( + registry.encode(py_data, serializer='json')[-1], + content_type='application/json', + content_encoding='utf-8', + ), + registry.decode( + json_data, + content_type='application/json', + content_encoding='utf-8', + ), + ) @skip_if_not_module('msgpack') def test_msgpack_decode(self): register_msgpack() - self.assertEqual(msgpack_py_data, - registry.decode( - msgpack_data, - content_type='application/x-msgpack', - content_encoding='binary')) + self.assertEqual( + msgpack_py_data, + registry.decode(msgpack_data, + content_type='application/x-msgpack', + content_encoding='binary'), + ) @skip_if_not_module('msgpack') def test_msgpack_encode(self): register_msgpack() - self.assertEqual(registry.decode( + self.assertEqual( + registry.decode( registry.encode(msgpack_py_data, serializer='msgpack')[-1], content_type='application/x-msgpack', - content_encoding='binary'), - registry.decode( - msgpack_data, - content_type='application/x-msgpack', - content_encoding='binary')) + content_encoding='binary', + ), + registry.decode( + msgpack_data, + content_type='application/x-msgpack', + content_encoding='binary', + ), + ) @skip_if_not_module('yaml') def test_yaml_decode(self): register_yaml() - self.assertEqual(py_data, - registry.decode( - yaml_data, - content_type='application/x-yaml', - content_encoding='utf-8')) + self.assertEqual( + py_data, + registry.decode(yaml_data, + content_type='application/x-yaml', + content_encoding='utf-8'), + ) @skip_if_not_module('yaml') def test_yaml_encode(self): register_yaml() - self.assertEqual(registry.decode( - registry.encode(py_data, serializer='yaml')[-1], - content_type='application/x-yaml', - content_encoding='utf-8'), - registry.decode( - yaml_data, - content_type='application/x-yaml', - content_encoding='utf-8')) + self.assertEqual( + registry.decode( + registry.encode(py_data, serializer='yaml')[-1], + content_type='application/x-yaml', + content_encoding='utf-8', + ), + registry.decode( + yaml_data, + content_type='application/x-yaml', + content_encoding='utf-8', + ), + ) def test_pickle_decode(self): - self.assertEqual(py_data, - registry.decode( - pickle_data, - content_type='application/x-python-serialize', - content_encoding='binary')) + self.assertEqual( + py_data, + registry.decode(pickle_data, + content_type='application/x-python-serialize', + content_encoding='binary'), + ) def test_pickle_encode(self): - self.assertEqual(pickle.loads(pickle_data), - pickle.loads(registry.encode(py_data, - serializer='pickle')[-1])) + self.assertEqual( + pickle.loads(pickle_data), + pickle.loads(registry.encode(py_data, serializer='pickle')[-1]), + ) def test_register(self): register(None, None, None, None) @@ -229,9 +266,10 @@ class test_Serialization(TestCase): registry.encode('foo', serializer='nonexisting') def test_raw_encode(self): - self.assertTupleEqual(raw_encode('foo'.encode('utf-8')), - ('application/data', 'binary', - 'foo'.encode('utf-8'))) + self.assertTupleEqual( + raw_encode('foo'.encode('utf-8')), + ('application/data', 'binary', 'foo'.encode('utf-8')), + ) @mask_modules('yaml') def test_register_yaml__no_yaml(self): diff --git a/kombu/tests/test_utils.py b/kombu/tests/test_utils.py index 3099b337..7090546c 100644 --- a/kombu/tests/test_utils.py +++ b/kombu/tests/test_utils.py @@ -65,8 +65,9 @@ class test_utils(TestCase): self.assertTrue(utils.reprkwargs({'foo': 'bar', 1: 2, u'k': 'v'})) def test_reprcall(self): - self.assertTrue(utils.reprcall('add', - (2, 2), {'copy': True})) + self.assertTrue( + utils.reprcall('add', (2, 2), {'copy': True}), + ) class test_UUID(TestCase): @@ -142,8 +143,10 @@ class test_emergency_dump_state(TestCase): def raise_something(*args, **kwargs): raise KeyError('foo') - utils.emergency_dump_state({'foo': 'bar'}, open_file=lambda n, m: fh, - dump=raise_something) + utils.emergency_dump_state( + {'foo': 'bar'}, + open_file=lambda n, m: fh, dump=raise_something, + ) self.assertIn("'foo': 'bar'", fh.getvalue()) self.assertTrue(stderr.getvalue()) self.assertFalse(stdout.getvalue()) @@ -192,12 +195,13 @@ class test_retry_over_time(TestCase): try: utils.count.return_value = range(1) x = utils.retry_over_time(self.myfun, self.Predicate, - errback=None, interval_max=14) + errback=None, interval_max=14) self.assertIsNone(x) utils.count.return_value = range(10) cb = Mock() x = utils.retry_over_time(self.myfun, self.Predicate, - errback=self.errback, callback=cb, interval_max=14) + errback=self.errback, callback=cb, + interval_max=14) self.assertEqual(x, 42) self.assertEqual(self.index, 9) cb.assert_called_with() @@ -206,20 +210,26 @@ class test_retry_over_time(TestCase): @insomnia def test_retry_once(self): - self.assertRaises(self.Predicate, utils.retry_over_time, - self.myfun, self.Predicate, - max_retries=1, errback=self.errback, interval_max=14) + self.assertRaises( + self.Predicate, utils.retry_over_time, + self.myfun, self.Predicate, + max_retries=1, errback=self.errback, interval_max=14, + ) self.assertEqual(self.index, 2) # no errback - self.assertRaises(self.Predicate, utils.retry_over_time, - self.myfun, self.Predicate, - max_retries=1, errback=None, interval_max=14) + self.assertRaises( + self.Predicate, utils.retry_over_time, + self.myfun, self.Predicate, + max_retries=1, errback=None, interval_max=14, + ) @insomnia def test_retry_never(self): - self.assertRaises(self.Predicate, utils.retry_over_time, - self.myfun, self.Predicate, - max_retries=0, errback=self.errback, interval_max=14) + self.assertRaises( + self.Predicate, utils.retry_over_time, + self.myfun, self.Predicate, + max_retries=0, errback=self.errback, interval_max=14, + ) self.assertEqual(self.index, 1) @@ -281,8 +291,10 @@ class test_symbol_by_name(TestCase): def test_returns_default(self): default = object() - self.assertIs(utils.symbol_by_name('xyz.ryx.qedoa.weq:foz', - default=default), default) + self.assertIs( + utils.symbol_by_name('xyz.ryx.qedoa.weq:foz', default=default), + default, + ) def test_no_default(self): with self.assertRaises(ImportError): @@ -296,16 +308,20 @@ class test_symbol_by_name(TestCase): def test_package(self): from kombu.entity import Exchange - self.assertIs(utils.symbol_by_name('.entity:Exchange', - package='kombu'), Exchange) + self.assertIs( + utils.symbol_by_name('.entity:Exchange', package='kombu'), + Exchange, + ) self.assertTrue(utils.symbol_by_name(':Consumer', package='kombu')) class test_ChannelPromise(TestCase): def test_repr(self): - self.assertEqual(repr(utils.ChannelPromise(lambda: 'foo')), - "") + self.assertEqual( + repr(utils.ChannelPromise(lambda: 'foo')), + "", + ) class test_entrypoints(TestCase): diff --git a/kombu/tests/transport/test_amqplib.py b/kombu/tests/transport/test_amqplib.py index fb6c0141..185cc349 100644 --- a/kombu/tests/transport/test_amqplib.py +++ b/kombu/tests/transport/test_amqplib.py @@ -57,10 +57,10 @@ class test_Channel(amqplibCase): self.assertFalse(self.channel.no_ack_consumers) def test_prepare_message(self): - x = self.channel.prepare_message('foobar', 10, - 'application/data', 'utf-8', - properties={}) - self.assertTrue(x) + self.assertTrue(self.channel.prepare_message( + 'foobar', 10, 'application/data', 'utf-8', + properties={}, + )) def test_message_to_python(self): message = Mock() diff --git a/kombu/tests/transport/test_base.py b/kombu/tests/transport/test_base.py index e369449f..c34871d7 100644 --- a/kombu/tests/transport/test_base.py +++ b/kombu/tests/transport/test_base.py @@ -33,8 +33,9 @@ class test_StdChannel(TestCase): StdChannel().get_bindings() def test_interface_after_reply_message_received(self): - self.assertIsNone(StdChannel().after_reply_message_received( - Queue('foo'))) + self.assertIsNone( + StdChannel().after_reply_message_received(Queue('foo')), + ) class test_Message(TestCase): diff --git a/kombu/tests/transport/test_pyamqp.py b/kombu/tests/transport/test_pyamqp.py index a1b550da..bd4e86bf 100644 --- a/kombu/tests/transport/test_pyamqp.py +++ b/kombu/tests/transport/test_pyamqp.py @@ -50,10 +50,10 @@ class test_Channel(TestCase): self.assertFalse(self.channel.no_ack_consumers) def test_prepare_message(self): - x = self.channel.prepare_message('foobar', 10, - 'application/data', 'utf-8', - properties={}) - self.assertTrue(x) + self.assertTrue(self.channel.prepare_message( + 'foobar', 10, 'application/data', 'utf-8', + properties={}, + )) def test_message_to_python(self): message = Mock() @@ -166,8 +166,10 @@ class test_pyamqp(TestCase): def test_eventmap(self): t = pyamqp.Transport(Mock()) conn = Mock() - self.assertDictEqual(t.eventmap(conn), - {conn.sock: t.client.drain_nowait}) + self.assertDictEqual( + t.eventmap(conn), + {conn.sock: t.client.drain_nowait}, + ) def test_event_interface(self): t = pyamqp.Transport(Mock()) diff --git a/kombu/tests/transport/test_redis.py b/kombu/tests/transport/test_redis.py index e007664d..90e3a318 100644 --- a/kombu/tests/transport/test_redis.py +++ b/kombu/tests/transport/test_redis.py @@ -262,22 +262,32 @@ class test_Channel(TestCase): self.assertFalse(s.subscribed) def test_handle_pmessage_message(self): - self.assertDictEqual(self.channel._handle_message( - self.channel.subclient, - ['pmessage', 'pattern', 'channel', 'data']), - {'type': 'pmessage', - 'pattern': 'pattern', - 'channel': 'channel', - 'data': 'data'}) + self.assertDictEqual( + self.channel._handle_message( + self.channel.subclient, + ['pmessage', 'pattern', 'channel', 'data'], + ), + { + 'type': 'pmessage', + 'pattern': 'pattern', + 'channel': 'channel', + 'data': 'data', + }, + ) def test_handle_message(self): - self.assertDictEqual(self.channel._handle_message( - self.channel.subclient, - ['type', 'channel', 'data']), - {'type': 'type', - 'pattern': None, - 'channel': 'channel', - 'data': 'data'}) + self.assertDictEqual( + self.channel._handle_message( + self.channel.subclient, + ['type', 'channel', 'data'], + ), + { + 'type': 'type', + 'pattern': None, + 'channel': 'channel', + 'data': 'data', + }, + ) def test_brpop_start_but_no_queues(self): self.assertIsNone(self.channel._brpop_start()) @@ -725,8 +735,7 @@ class test_MultiChannelPoller(TestCase): self.assertEqual(p._register.call_count, 1) self.assertEqual(channel._subscribe.call_count, 1) - def create_get(self, events=None, queues=None, - fanouts=None): + def create_get(self, events=None, queues=None, fanouts=None): _pr = [] if events is None else events _aq = [] if queues is None else queues _af = [] if fanouts is None else fanouts diff --git a/kombu/tests/transport/virtual/test_base.py b/kombu/tests/transport/virtual/test_base.py index 4adfa9e6..736063dc 100644 --- a/kombu/tests/transport/virtual/test_base.py +++ b/kombu/tests/transport/virtual/test_base.py @@ -286,7 +286,7 @@ class test_Channel(TestCase): self.assertIn(n, c.purged) def test_basic_publish__get__consume__restore(self, - n='test_basic_publish'): + n='test_basic_publish'): c = memory_client().channel() c.exchange_declare(n) @@ -306,8 +306,8 @@ class test_Channel(TestCase): consumer_tag = uuid() - c.basic_consume(n + '2', False, consumer_tag=consumer_tag, - callback=lambda *a: None) + c.basic_consume(n + '2', False, + consumer_tag=consumer_tag, callback=lambda *a: None) self.assertIn(n + '2', c._active_queues) r2, _ = c.drain_events() r2 = c.message_to_python(r2) @@ -365,7 +365,7 @@ class test_Channel(TestCase): @patch('kombu.transport.virtual.emergency_dump_state') @patch('kombu.transport.virtual.say') def test_restore_unacked_once_when_unrestored(self, say, - emergency_dump_state): + emergency_dump_state): q = self.channel.qos q._flush = Mock() @@ -409,8 +409,10 @@ class test_Channel(TestCase): def test_lookup__undeliverable(self, n='test_lookup__undeliverable'): warnings.resetwarnings() with catch_warnings(record=True) as log: - self.assertListEqual(self.channel._lookup(n, n, 'ae.undeliver'), - ['ae.undeliver']) + self.assertListEqual( + self.channel._lookup(n, n, 'ae.undeliver'), + ['ae.undeliver'], + ) self.assertTrue(log) self.assertIn('could not be delivered', log[0].message.args[0]) diff --git a/kombu/tests/transport/virtual/test_exchange.py b/kombu/tests/transport/virtual/test_exchange.py index d1b2a85a..90127ba0 100644 --- a/kombu/tests/transport/virtual/test_exchange.py +++ b/kombu/tests/transport/virtual/test_exchange.py @@ -25,15 +25,18 @@ class test_Direct(ExchangeCase): ('rBaz', None, 'qBaz')] def test_lookup(self): - self.assertListEqual(self.e.lookup( - self.table, 'eFoo', 'rFoo', None), - ['qFoo', 'qFox']) - self.assertListEqual(self.e.lookup( - self.table, 'eMoz', 'rMoz', 'DEFAULT'), - []) - self.assertListEqual(self.e.lookup( - self.table, 'eBar', 'rBar', None), - ['qBar']) + self.assertListEqual( + self.e.lookup(self.table, 'eFoo', 'rFoo', None), + ['qFoo', 'qFox'], + ) + self.assertListEqual( + self.e.lookup(self.table, 'eMoz', 'rMoz', 'DEFAULT'), + [], + ) + self.assertListEqual( + self.e.lookup(self.table, 'eBar', 'rBar', None), + ['qBar'], + ) class test_Fanout(ExchangeCase): @@ -43,9 +46,10 @@ class test_Fanout(ExchangeCase): (None, None, 'qBar')] def test_lookup(self): - self.assertListEqual(self.e.lookup( - self.table, 'eFoo', 'rFoo', None), - ['qFoo', 'qFox', 'qBar']) + self.assertListEqual( + self.e.lookup(self.table, 'eFoo', 'rFoo', None), + ['qFoo', 'qFox', 'qBar'], + ) def test_deliver_when_fanout_supported(self): self.e.channel = Mock() @@ -65,32 +69,39 @@ class test_Fanout(ExchangeCase): class test_Topic(ExchangeCase): type = exchange.TopicExchange - table = [('stock.#', None, 'rFoo'), - ('stock.us.*', None, 'rBar')] + table = [ + ('stock.#', None, 'rFoo'), + ('stock.us.*', None, 'rBar'), + ] def setUp(self): super(test_Topic, self).setUp() self.table = [(rkey, self.e.key_to_pattern(rkey), queue) - for rkey, _, queue in self.table] + for rkey, _, queue in self.table] def test_prepare_bind(self): x = self.e.prepare_bind('qFoo', 'eFoo', 'stock.#', {}) self.assertTupleEqual(x, ('stock.#', r'^stock\..*?$', 'qFoo')) def test_lookup(self): - self.assertListEqual(self.e.lookup( - self.table, 'eFoo', 'stock.us.nasdaq', None), - ['rFoo', 'rBar']) + self.assertListEqual( + self.e.lookup(self.table, 'eFoo', 'stock.us.nasdaq', None), + ['rFoo', 'rBar'], + ) self.assertTrue(self.e._compiled) - self.assertListEqual(self.e.lookup( - self.table, 'eFoo', 'stock.europe.OSE', None), - ['rFoo']) - self.assertListEqual(self.e.lookup( - self.table, 'eFoo', 'stockxeuropexOSE', None), - []) - self.assertListEqual(self.e.lookup( - self.table, 'eFoo', 'candy.schleckpulver.snap_crackle', None), - []) + self.assertListEqual( + self.e.lookup(self.table, 'eFoo', 'stock.europe.OSE', None), + ['rFoo'], + ) + self.assertListEqual( + self.e.lookup(self.table, 'eFoo', 'stockxeuropexOSE', None), + [], + ) + self.assertListEqual( + self.e.lookup(self.table, 'eFoo', + 'candy.schleckpulver.snap_crackle', None), + [], + ) def test_deliver(self): self.e.channel = Mock() @@ -111,29 +122,40 @@ class test_ExchangeType(ExchangeCase): self.e.lookup([], 'eFoo', 'rFoo', None) def test_prepare_bind(self): - self.assertTupleEqual(self.e.prepare_bind('qFoo', 'eFoo', 'rFoo', {}), - ('rFoo', None, 'qFoo')) + self.assertTupleEqual( + self.e.prepare_bind('qFoo', 'eFoo', 'rFoo', {}), + ('rFoo', None, 'qFoo'), + ) def test_equivalent(self): - e1 = dict(type='direct', - durable=True, - auto_delete=True, - arguments={}) + e1 = dict( + type='direct', + durable=True, + auto_delete=True, + arguments={}, + ) self.assertTrue( - self.e.equivalent(e1, 'eFoo', 'direct', True, True, {})) + self.e.equivalent(e1, 'eFoo', 'direct', True, True, {}), + ) self.assertFalse( - self.e.equivalent(e1, 'eFoo', 'topic', True, True, {})) + self.e.equivalent(e1, 'eFoo', 'topic', True, True, {}), + ) self.assertFalse( - self.e.equivalent(e1, 'eFoo', 'direct', False, True, {})) + self.e.equivalent(e1, 'eFoo', 'direct', False, True, {}), + ) self.assertFalse( - self.e.equivalent(e1, 'eFoo', 'direct', True, False, {})) + self.e.equivalent(e1, 'eFoo', 'direct', True, False, {}), + ) self.assertFalse( - self.e.equivalent(e1, 'eFoo', 'direct', True, True, { - 'expires': 3000})) + self.e.equivalent(e1, 'eFoo', 'direct', True, True, + {'expires': 3000}), + ) e2 = dict(e1, arguments={'expires': 3000}) self.assertTrue( - self.e.equivalent(e2, 'eFoo', 'direct', True, True, { - 'expires': 3000})) + self.e.equivalent(e2, 'eFoo', 'direct', True, True, + {'expires': 3000}), + ) self.assertFalse( - self.e.equivalent(e2, 'eFoo', 'direct', True, True, { - 'expires': 6000})) + self.e.equivalent(e2, 'eFoo', 'direct', True, True, + {'expires': 6000}), + ) diff --git a/kombu/tests/transport/virtual/test_scheduling.py b/kombu/tests/transport/virtual/test_scheduling.py index afbcd061..6f2d24f1 100644 --- a/kombu/tests/transport/virtual/test_scheduling.py +++ b/kombu/tests/transport/virtual/test_scheduling.py @@ -43,12 +43,16 @@ class test_FairCycle(TestCase): return r cycle = FairCycle(echo, resources, MyEmpty) - self.assertEqual(consume(cycle.get, len(resources)), - [('a', 'a'), ('b', 'b'), ('d', 'd'), - ('e', 'e'), ('a', 'a')]) - self.assertEqual(consume(cycle.get, len(resources)), - [('b', 'b'), ('d', 'd'), ('e', 'e'), - ('a', 'a'), ('b', 'b')]) + self.assertEqual( + consume(cycle.get, len(resources)), + [('a', 'a'), ('b', 'b'), ('d', 'd'), + ('e', 'e'), ('a', 'a')], + ) + self.assertEqual( + consume(cycle.get, len(resources)), + [('b', 'b'), ('d', 'd'), ('e', 'e'), + ('a', 'a'), ('b', 'b')], + ) cycle2 = FairCycle(echo, ['c', 'c'], MyEmpty) with self.assertRaises(MyEmpty): consume(cycle2.get, 3) diff --git a/kombu/tests/utilities/test_amq_manager.py b/kombu/tests/utilities/test_amq_manager.py index 1dcd761b..ccf4ec08 100644 --- a/kombu/tests/utilities/test_amq_manager.py +++ b/kombu/tests/utilities/test_amq_manager.py @@ -19,8 +19,9 @@ class test_get_manager(TestCase): with patch('pyrabbit.Client', create=True) as Client: manager = Connection('amqp://').get_manager() self.assertIsNotNone(manager) - Client.assert_called_with('localhost:55672', - 'guest', 'guest') + Client.assert_called_with( + 'localhost:55672', 'guest', 'guest', + ) @module_exists('pyrabbit') def test_transport_options(self): @@ -32,5 +33,6 @@ class test_get_manager(TestCase): 'manager_password': 'bosco', }).get_manager() self.assertIsNotNone(manager) - Client.assert_called_with('admin.mq.vandelay.com:808', - 'george', 'bosco') + Client.assert_called_with( + 'admin.mq.vandelay.com:808', 'george', 'bosco', + ) diff --git a/kombu/tests/utilities/test_functional.py b/kombu/tests/utilities/test_functional.py index c84a6854..b20ad5b7 100644 --- a/kombu/tests/utilities/test_functional.py +++ b/kombu/tests/utilities/test_functional.py @@ -14,12 +14,16 @@ def double(x): class test_promise(TestCase): def test__str__(self): - self.assertEqual(str(promise(lambda: 'the quick brown fox')), - 'the quick brown fox') + self.assertEqual( + str(promise(lambda: 'the quick brown fox')), + 'the quick brown fox', + ) def test__repr__(self): - self.assertEqual(repr(promise(lambda: 'fi fa fo')), - "'fi fa fo'") + self.assertEqual( + repr(promise(lambda: 'fi fa fo')), + "'fi fa fo'", + ) def test_evaluate(self): self.assertEqual(promise(lambda: 2 + 2)(), 4) diff --git a/kombu/tests/utils.py b/kombu/tests/utils.py index 61c98b66..a8f92a37 100644 --- a/kombu/tests/utils.py +++ b/kombu/tests/utils.py @@ -60,8 +60,8 @@ def redirect_stdouts(fun): sys.stdout = StringIO() sys.stderr = StringIO() try: - return fun(*args, **dict(kwargs, stdout=sys.stdout, - stderr=sys.stderr)) + return fun(*args, **dict(kwargs, + stdout=sys.stdout, stderr=sys.stderr)) finally: sys.stdout = sys.__stdout__ sys.stderr = sys.__stderr__ diff --git a/pavement.py b/pavement.py index a51cca73..ba467adb 100644 --- a/pavement.py +++ b/pavement.py @@ -7,7 +7,7 @@ from paver.setuputils import setup # noqa PYCOMPILE_CACHES = ["*.pyc", "*$py.class"] options( - sphinx=Bunch(builddir=".build"), + sphinx=Bunch(builddir=".build"), ) @@ -91,7 +91,7 @@ def readme(options): ]) def bump(options): s = "-- '%s'" % (options.custom, ) \ - if getattr(options, "custom", None) else "" + if getattr(options, "custom", None) else "" sh("extra/release/bump_version.py \ kombu/__init__.py README.rst %s" % (s, )) @@ -129,6 +129,7 @@ def flake8(options): }{exit $FOUND_FLAKE; '""" % (complexity, migrations_path), ignore_error=noerror) + @task @cmdopts([ ("noerror", "E", "Ignore errors"), diff --git a/setup.py b/setup.py index d512407f..1adf5b09 100644 --- a/setup.py +++ b/setup.py @@ -88,8 +88,9 @@ for dirpath, dirnames, filenames in os.walk(src_dir): if filename.endswith('.py'): packages.append('.'.join(fullsplit(dirpath))) else: - data_files.append([dirpath, [os.path.join(dirpath, f) for f in - filenames]]) + data_files.append( + [dirpath, [os.path.join(dirpath, f) for f in filenames]], + ) if os.path.exists('README.rst'): long_description = codecs.open('README.rst', 'r', 'utf-8').read() From b33247ebc58d2e7975b243eaac25625b41f009d8 Mon Sep 17 00:00:00 2001 From: Ask Solem Date: Mon, 28 Jan 2013 15:38:45 +0000 Subject: [PATCH 3/9] contextmanagers that needs finally --- kombu/tests/utilities/test_encoding.py | 8 +++-- kombu/transport/redis.py | 43 ++++++++++++++------------ 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/kombu/tests/utilities/test_encoding.py b/kombu/tests/utilities/test_encoding.py index eb19d1ad..b2942b67 100644 --- a/kombu/tests/utilities/test_encoding.py +++ b/kombu/tests/utilities/test_encoding.py @@ -17,9 +17,11 @@ from kombu.tests.utils import TestCase def clean_encoding(): old_encoding = sys.modules.pop('kombu.utils.encoding', None) import kombu.utils.encoding - yield kombu.utils.encoding - if old_encoding: - sys.modules['kombu.utils.encoding'] = old_encoding + try: + yield kombu.utils.encoding + finally: + if old_encoding: + sys.modules['kombu.utils.encoding'] = old_encoding class test_default_encoding(TestCase): diff --git a/kombu/transport/redis.py b/kombu/transport/redis.py index c7d373a3..48aabc3a 100644 --- a/kombu/transport/redis.py +++ b/kombu/transport/redis.py @@ -71,24 +71,27 @@ class MutexHeld(Exception): @contextmanager def Mutex(client, name, expire): lock_id = uuid() - if client.setnx(name, lock_id): - client.expire(name, expire) - yield - else: - if not client.ttl(name): - client.expire(name, expire) - raise MutexHeld() - - pipe = client.pipeline(True) + i_won = client.setnx(name, lock_id) try: - pipe.watch(name) - if pipe.get(name) == lock_id: - pipe.multi() - pipe.delete(name) - pipe.execute() - pipe.unwatch() - except redis.WatchError: - pass + if i_won: + client.expire(name, expire) + yield + else: + if not client.ttl(name): + client.expire(name, expire) + raise MutexHeld() + finally: + if i_won: + pipe = client.pipeline(True) + try: + pipe.watch(name) + if pipe.get(name) == lock_id: + pipe.multi() + pipe.delete(name) + pipe.execute() + pipe.unwatch() + except redis.WatchError: + pass class QoS(virtual.QoS): @@ -654,8 +657,10 @@ class Channel(virtual.Channel): else: if self._in_poll: client = self._create_client() - yield client - self.pool.release(client.connection) + try: + yield client + finally: + self.pool.release(client.connection) else: yield self.client From 583fc1f7fe7531e1804b131980e92d2f7e655489 Mon Sep 17 00:00:00 2001 From: Ask Solem Date: Wed, 30 Jan 2013 12:52:05 +0000 Subject: [PATCH 4/9] Remove sqs_message and sqs_queue objects when restoring SQS message. Closes #1108 --- kombu/transport/SQS.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kombu/transport/SQS.py b/kombu/transport/SQS.py index 1110a204..8bf7e6b5 100644 --- a/kombu/transport/SQS.py +++ b/kombu/transport/SQS.py @@ -241,6 +241,13 @@ class Channel(virtual.Channel): return payload raise Empty() + def _restore(self, message, + unwanted_delivery_info=('sqs_message', 'sqs_queue')): + for unwanted_key in unwanted_delivery_info: + # Remove objects that aren't JSON serializable (Issue #1108). + message.delivery_info.pop(unwanted_key, None) + return super(Channel, self)._restore(message) + def basic_ack(self, delivery_tag): delivery_info = self.qos.get(delivery_tag).delivery_info try: From 6efad2ed583216cff5e259fc229c2a69380ca4b1 Mon Sep 17 00:00:00 2001 From: Ask Solem Date: Wed, 6 Feb 2013 15:17:10 +0000 Subject: [PATCH 5/9] virtual QoS: Flush must happen before append, not after --- kombu/transport/virtual/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kombu/transport/virtual/__init__.py b/kombu/transport/virtual/__init__.py index 89f6294a..ce937014 100644 --- a/kombu/transport/virtual/__init__.py +++ b/kombu/transport/virtual/__init__.py @@ -119,9 +119,9 @@ class QoS(object): def append(self, message, delivery_tag): """Append message to transactional state.""" - self._delivered[delivery_tag] = message if self._dirty: self._flush() + self._delivered[delivery_tag] = message def get(self, delivery_tag): return self._delivered[delivery_tag] From d8b940a40e235fb165e8c8ca4cbb04b0b725fbae Mon Sep 17 00:00:00 2001 From: Ask Solem Date: Wed, 6 Feb 2013 15:17:24 +0000 Subject: [PATCH 6/9] virtual QoS support for basic_get --- kombu/transport/virtual/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kombu/transport/virtual/__init__.py b/kombu/transport/virtual/__init__.py index ce937014..c1ba71d1 100644 --- a/kombu/transport/virtual/__init__.py +++ b/kombu/transport/virtual/__init__.py @@ -493,10 +493,13 @@ class Channel(AbstractChannel, base.StdChannel): pass self.connection._callbacks.pop(queue, None) - def basic_get(self, queue, **kwargs): + def basic_get(self, queue, no_ack=False, **kwargs): """Get message by direct access (synchronous).""" try: - return self._get(queue) + message = self.Message(self, self._get(queue)) + if not no_ack: + self.qos.append(message, message.delivery_tag) + return message except Empty: pass From 2558fbe29afcf7da61bbe9876b05212d542100af Mon Sep 17 00:00:00 2001 From: Ask Solem Date: Wed, 6 Feb 2013 17:54:24 +0000 Subject: [PATCH 7/9] Ignore exceptions in Consumer.__exit__ --- kombu/messaging.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kombu/messaging.py b/kombu/messaging.py index e3e6c4d1..cb13f2c7 100644 --- a/kombu/messaging.py +++ b/kombu/messaging.py @@ -376,7 +376,10 @@ class Consumer(object): return self def __exit__(self, *exc_info): - self.cancel() + try: + self.cancel() + except Exception: + pass def add_queue(self, queue): queue = queue(self.channel) From 4e4339fa5b39d63f33d470732379da2ca35f62e3 Mon Sep 17 00:00:00 2001 From: Alex Koshelev Date: Wed, 6 Feb 2013 03:09:29 +0400 Subject: [PATCH 8/9] Fixes compression header removal for the serializable case --- kombu/tests/transport/virtual/test_base.py | 5 ++++- kombu/transport/virtual/__init__.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/kombu/tests/transport/virtual/test_base.py b/kombu/tests/transport/virtual/test_base.py index 736063dc..28714cc4 100644 --- a/kombu/tests/transport/virtual/test_base.py +++ b/kombu/tests/transport/virtual/test_base.py @@ -9,6 +9,7 @@ from kombu import Connection from kombu.exceptions import StdChannelError from kombu.transport import virtual from kombu.utils import uuid +from kombu.compression import compress from kombu.tests.compat import catch_warnings from kombu.tests.utils import TestCase @@ -122,13 +123,15 @@ class test_Message(TestCase): def test_serializable(self): c = client().channel() - data = c.prepare_message('the quick brown fox...') + body, content_type = compress('the quick brown fox...', 'gzip') + data = c.prepare_message(body, headers={'compression': content_type}) tag = data['properties']['delivery_tag'] = uuid() message = c.message_to_python(data) dict_ = message.serializable() self.assertEqual(dict_['body'], 'the quick brown fox...'.encode('utf-8')) self.assertEqual(dict_['properties']['delivery_tag'], tag) + self.assertFalse('compression' in dict_['headers']) class test_AbstractChannel(TestCase): diff --git a/kombu/transport/virtual/__init__.py b/kombu/transport/virtual/__init__.py index c1ba71d1..2b11203d 100644 --- a/kombu/transport/virtual/__init__.py +++ b/kombu/transport/virtual/__init__.py @@ -226,7 +226,7 @@ class Message(base.Message): 'properties': props, 'content-type': self.content_type, 'content-encoding': self.content_encoding, - 'headers': self.headers} + 'headers': headers} class AbstractChannel(object): From 7c5dc19be1953e94fdf04adf016f91292677e144 Mon Sep 17 00:00:00 2001 From: Ask Solem Date: Thu, 7 Feb 2013 15:37:06 +0000 Subject: [PATCH 9/9] Adds Alex Koshelev to AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index a8e8f690..6b6366a9 100644 --- a/AUTHORS +++ b/AUTHORS @@ -5,6 +5,7 @@ Adam Nelson Adam Wentz +Alex Koshelev Alexandre Bourget Andrew Watts Andrey Antukh