diff options
author | Ask Solem <ask@celeryproject.org> | 2013-09-11 16:33:57 +0100 |
---|---|---|
committer | Ask Solem <ask@celeryproject.org> | 2013-09-11 16:33:57 +0100 |
commit | 9dc3ceaa43c3c36f7569a3a56f3ceeb9de8a12c0 (patch) | |
tree | 8242e19958fa942c2bbd88b176ef9002d4518a96 /kombu/tests | |
parent | da623b81b16ed6314efbf8467d562f378e43b607 (diff) | |
download | kombu-9dc3ceaa43c3c36f7569a3a56f3ceeb9de8a12c0.tar.gz |
Tests cleanup (and renamed TestCase -> Case
Diffstat (limited to 'kombu/tests')
32 files changed, 162 insertions, 170 deletions
diff --git a/kombu/tests/utils.py b/kombu/tests/case.py index d0e1db82..155d6360 100644 --- a/kombu/tests/utils.py +++ b/kombu/tests/case.py @@ -25,7 +25,7 @@ patch = mock.patch call = mock.call -class TestCase(unittest.TestCase): +class Case(unittest.TestCase): def assertItemsEqual(self, a, b, *args, **kwargs): return self.assertEqual(sorted(a), sorted(b), *args, **kwargs) diff --git a/kombu/tests/test_clocks.py b/kombu/tests/test_clocks.py index ed8c9fa8..f3e10991 100644 --- a/kombu/tests/test_clocks.py +++ b/kombu/tests/test_clocks.py @@ -4,10 +4,10 @@ from heapq import heappush from kombu.clocks import LamportClock -from .utils import TestCase +from .case import Case -class test_LamportClock(TestCase): +class test_LamportClock(Case): def test_clocks(self): c1 = LamportClock() diff --git a/kombu/tests/test_common.py b/kombu/tests/test_common.py index c61a2076..2275a565 100644 --- a/kombu/tests/test_common.py +++ b/kombu/tests/test_common.py @@ -2,8 +2,6 @@ from __future__ import absolute_import import socket -from mock import patch - from kombu import common from kombu.common import ( Broadcast, maybe_declare, @@ -14,11 +12,10 @@ from kombu.common import ( ) from kombu.exceptions import StdChannelError -from .utils import TestCase -from .utils import ContextMock, Mock, MockPool +from .case import Case, ContextMock, Mock, MockPool, patch -class test_ignore_errors(TestCase): +class test_ignore_errors(Case): def test_ignored(self): connection = Mock() @@ -41,7 +38,7 @@ class test_ignore_errors(TestCase): raise KeyError() -class test_declaration_cached(TestCase): +class test_declaration_cached(Case): def test_when_cached(self): chan = Mock() @@ -54,7 +51,7 @@ class test_declaration_cached(TestCase): self.assertFalse(declaration_cached('foo', chan)) -class test_Broadcast(TestCase): +class test_Broadcast(Case): def test_arguments(self): q = Broadcast(name='test_Broadcast') @@ -69,7 +66,7 @@ class test_Broadcast(TestCase): self.assertEqual(q.exchange.name, 'test_Broadcast') -class test_maybe_declare(TestCase): +class test_maybe_declare(Case): def test_cacheable(self): channel = Mock() @@ -115,7 +112,7 @@ class test_maybe_declare(TestCase): self.assertTrue(channel.connection.client.ensure.call_count) -class test_replies(TestCase): +class test_replies(Case): def test_send_reply(self): req = Mock() @@ -188,7 +185,7 @@ class test_replies(TestCase): self.assertFalse(channel.after_reply_message_received.called) -class test_insured(TestCase): +class test_insured(Case): @patch('kombu.common.logger') def test_ensure_errback(self, logger): @@ -298,7 +295,7 @@ class MockConsumer(object): self.consumers.discard(self) -class test_itermessages(TestCase): +class test_itermessages(Case): class MockConnection(object): should_raise_timeout = False @@ -347,7 +344,7 @@ class test_itermessages(TestCase): next(it) -class test_entry_to_queue(TestCase): +class test_entry_to_queue(Case): def test_calls_Queue_from_dict(self): with patch('kombu.common.Queue') as Queue: @@ -355,7 +352,7 @@ class test_entry_to_queue(TestCase): Queue.from_dict.assert_called_with('name', exchange='bar') -class test_QoS(TestCase): +class test_QoS(Case): class _QoS(QoS): def __init__(self, value): diff --git a/kombu/tests/test_compat.py b/kombu/tests/test_compat.py index 473b25e4..283800be 100644 --- a/kombu/tests/test_compat.py +++ b/kombu/tests/test_compat.py @@ -1,16 +1,13 @@ from __future__ import absolute_import -from mock import patch - from kombu import Connection, Exchange, Queue from kombu import compat +from .case import Case, Mock, patch from .mocks import Transport, Channel -from .utils import TestCase -from .utils import Mock -class test_misc(TestCase): +class test_misc(Case): def test_iterconsume(self): @@ -77,7 +74,7 @@ class test_misc(TestCase): Queue.from_dict('foo', **dict(defs))) -class test_Publisher(TestCase): +class test_Publisher(Case): def setUp(self): self.connection = Connection(transport=Transport) @@ -128,7 +125,7 @@ class test_Publisher(TestCase): self.assertTrue(pub._closed) -class test_Consumer(TestCase): +class test_Consumer(Case): def setUp(self): self.connection = Connection(transport=Transport) @@ -262,7 +259,7 @@ class test_Consumer(TestCase): c.close() -class test_ConsumerSet(TestCase): +class test_ConsumerSet(Case): def setUp(self): self.connection = Connection(transport=Transport) diff --git a/kombu/tests/test_compression.py b/kombu/tests/test_compression.py index 2df3b388..e0cd4cbb 100644 --- a/kombu/tests/test_compression.py +++ b/kombu/tests/test_compression.py @@ -2,15 +2,12 @@ from __future__ import absolute_import import sys -from nose import SkipTest - from kombu import compression -from .utils import TestCase -from .utils import mask_modules +from .case import Case, SkipTest, mask_modules -class test_compression(TestCase): +class test_compression(Case): def setUp(self): try: diff --git a/kombu/tests/test_connection.py b/kombu/tests/test_connection.py index 5ed034cf..d8a79fb9 100644 --- a/kombu/tests/test_connection.py +++ b/kombu/tests/test_connection.py @@ -5,20 +5,16 @@ import pickle import socket from copy import copy -from mock import patch -from nose import SkipTest from kombu import Connection, Consumer, Producer, parse_url from kombu.connection import Resource from kombu.five import items, range +from .case import Case, Mock, SkipTest, patch, skip_if_not_module from .mocks import Transport -from .utils import TestCase -from .utils import Mock, skip_if_not_module - -class test_connection_utils(TestCase): +class test_connection_utils(Case): def setUp(self): self.url = 'amqp://user:pass@localhost:5672/my/vhost' @@ -142,7 +138,7 @@ class test_connection_utils(TestCase): ) -class test_Connection(TestCase): +class test_Connection(Case): def setUp(self): self.conn = Connection(port=5672, transport=Transport) @@ -512,7 +508,7 @@ class test_Connection(TestCase): self.assertTupleEqual(conn.connection_errors, (KeyError, ValueError)) -class test_Connection_with_transport_options(TestCase): +class test_Connection_with_transport_options(Case): transport_options = {'pool_recycler': 3600, 'echo': True} @@ -531,7 +527,7 @@ class xResource(Resource): pass -class ResourceCase(TestCase): +class ResourceCase(Case): abstract = True def create_resource(self, limit, preload): diff --git a/kombu/tests/test_entities.py b/kombu/tests/test_entities.py index 04111577..165160f1 100644 --- a/kombu/tests/test_entities.py +++ b/kombu/tests/test_entities.py @@ -2,21 +2,18 @@ from __future__ import absolute_import import pickle -from mock import call - from kombu import Connection, Exchange, Producer, Queue, binding from kombu.exceptions import NotBoundError +from .case import Case, Mock, call from .mocks import Transport -from .utils import TestCase -from .utils import Mock def get_conn(): return Connection(transport=Transport) -class test_binding(TestCase): +class test_binding(Case): def test_constructor(self): x = binding( @@ -59,7 +56,7 @@ class test_binding(TestCase): self.assertIn('rkey', repr(b)) -class test_Exchange(TestCase): +class test_Exchange(Case): def test_bound(self): exchange = Exchange('foo', 'direct') @@ -187,7 +184,7 @@ class test_Exchange(TestCase): self.assertIn('exchange_unbind', chan) -class test_Queue(TestCase): +class test_Queue(Case): def setUp(self): self.exchange = Exchange('foo', 'direct') diff --git a/kombu/tests/test_log.py b/kombu/tests/test_log.py index bb063151..738b7cb2 100644 --- a/kombu/tests/test_log.py +++ b/kombu/tests/test_log.py @@ -3,8 +3,6 @@ from __future__ import absolute_import import logging import sys -from mock import patch - from kombu.log import ( NullHandler, get_logger, @@ -16,18 +14,17 @@ from kombu.log import ( setup_logging, ) -from .utils import TestCase -from .utils import Mock +from .case import Case, Mock, patch -class test_NullHandler(TestCase): +class test_NullHandler(Case): def test_emit(self): h = NullHandler() h.emit('record') -class test_get_logger(TestCase): +class test_get_logger(Case): def test_when_string(self): l = get_logger('foo') @@ -59,7 +56,7 @@ class test_get_logger(TestCase): self.assertEqual(get_loglevel(logging.INFO), logging.INFO) -class test_safe_format(TestCase): +class test_safe_format(Case): def test_formatting(self): fmt = 'The %r jumped %x over the %s' @@ -69,7 +66,7 @@ class test_safe_format(TestCase): self.assertListEqual(res, ["'frog'", 'foo', 'elephant']) -class test_LogMixin(TestCase): +class test_LogMixin(Case): def setUp(self): self.log = Log('Log', Mock()) @@ -138,7 +135,7 @@ class test_LogMixin(TestCase): ) -class test_setup_logging(TestCase): +class test_setup_logging(Case): @patch('logging.getLogger') def test_set_up_default_values(self, getLogger): diff --git a/kombu/tests/test_messaging.py b/kombu/tests/test_messaging.py index be402c13..d5355e99 100644 --- a/kombu/tests/test_messaging.py +++ b/kombu/tests/test_messaging.py @@ -1,21 +1,19 @@ -from __future__ import absolute_import -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals import anyjson import pickle from collections import defaultdict -from mock import patch from kombu import Connection, Consumer, Producer, Exchange, Queue from kombu.exceptions import MessageStateError from kombu.utils import ChannelPromise +from .case import Case, Mock, patch from .mocks import Transport -from .utils import TestCase, Mock -class test_Producer(TestCase): +class test_Producer(Case): def setUp(self): self.exchange = Exchange('foo', 'direct') @@ -218,7 +216,7 @@ class test_Producer(TestCase): self.assertTrue(p.on_return) -class test_Consumer(TestCase): +class test_Consumer(Case): def setUp(self): self.connection = Connection(transport=Transport) @@ -282,7 +280,7 @@ class test_Consumer(TestCase): callback = Mock(name='callback') with conn.Consumer(queues=[q], accept=['pickle'], - callbacks=[callback]) as consumer: + callbacks=[callback]): conn.drain_events(timeout=1) self.assertTrue(callback.called) body, message = callback.call_args[0] diff --git a/kombu/tests/test_mixins.py b/kombu/tests/test_mixins.py index d827e984..b80f0131 100644 --- a/kombu/tests/test_mixins.py +++ b/kombu/tests/test_mixins.py @@ -4,7 +4,7 @@ import socket from kombu.mixins import ConsumerMixin -from .utils import TestCase, Mock, ContextMock, patch +from .case import Case, Mock, ContextMock, patch def Message(body, content_type='text/plain', content_encoding='utf-8'): @@ -31,7 +31,7 @@ class Cons(ConsumerMixin): self.extra_context.return_value = self.extra_context -class test_ConsumerMixin(TestCase): +class test_ConsumerMixin(Case): def _context(self): Acons = ContextMock(name='consumerA') @@ -108,7 +108,7 @@ class test_ConsumerMixin(TestCase): c.on_consume_end.assert_called_with(conn, channel) -class test_ConsumerMixin_interface(TestCase): +class test_ConsumerMixin_interface(Case): def setUp(self): self.c = ConsumerMixin() diff --git a/kombu/tests/test_pidbox.py b/kombu/tests/test_pidbox.py index 28512023..7ac0d9e4 100644 --- a/kombu/tests/test_pidbox.py +++ b/kombu/tests/test_pidbox.py @@ -6,11 +6,10 @@ from kombu import Connection from kombu import pidbox from kombu.utils import uuid -from .utils import TestCase -from .utils import Mock +from .case import Case, Mock -class test_Mailbox(TestCase): +class test_Mailbox(Case): def _handler(self, state): return self.stats['var'] diff --git a/kombu/tests/test_pools.py b/kombu/tests/test_pools.py index a9386602..9bb5609e 100644 --- a/kombu/tests/test_pools.py +++ b/kombu/tests/test_pools.py @@ -5,11 +5,10 @@ from kombu import pools from kombu.connection import ConnectionPool from kombu.utils import eqhash -from .utils import TestCase -from .utils import Mock +from .case import Case, Mock -class test_ProducerPool(TestCase): +class test_ProducerPool(Case): Pool = pools.ProducerPool class MyPool(pools.ProducerPool): @@ -112,7 +111,7 @@ class test_ProducerPool(TestCase): self.assertIsNone(p.channel) -class test_PoolGroup(TestCase): +class test_PoolGroup(Case): Group = pools.PoolGroup class MyGroup(pools.PoolGroup): @@ -206,7 +205,7 @@ class test_PoolGroup(TestCase): pools.set_limit(pools.get_limit()) -class test_fun_PoolGroup(TestCase): +class test_fun_PoolGroup(Case): def test_connections_behavior(self): c1u = 'memory://localhost:123' diff --git a/kombu/tests/test_serialization.py b/kombu/tests/test_serialization.py index 702bd628..599412d2 100644 --- a/kombu/tests/test_serialization.py +++ b/kombu/tests/test_serialization.py @@ -16,8 +16,7 @@ from kombu.serialization import ( ) from kombu.utils.encoding import str_to_bytes -from .utils import TestCase -from .utils import mask_modules, skip_if_not_module +from .case import Case, mask_modules, skip_if_not_module # For content_encoding tests unicode_string = 'abcdé\u8463' @@ -76,7 +75,7 @@ registry.register('testS', lambda s: s, lambda s: 'decoded', 'application/testS', 'utf-8') -class test_Serialization(TestCase): +class test_Serialization(Case): def test_disable(self): disabled = registry._disabled_content_types diff --git a/kombu/tests/test_simple.py b/kombu/tests/test_simple.py index 727ce2d2..53a4ac38 100644 --- a/kombu/tests/test_simple.py +++ b/kombu/tests/test_simple.py @@ -2,11 +2,10 @@ from __future__ import absolute_import from kombu import Connection, Exchange, Queue -from .utils import TestCase -from .utils import Mock +from .case import Case, Mock -class SimpleBase(TestCase): +class SimpleBase(Case): abstract = True def Queue(self, name, *args, **kwargs): diff --git a/kombu/tests/transport/test_amqplib.py b/kombu/tests/transport/test_amqplib.py index 185cc349..cf7d6150 100644 --- a/kombu/tests/transport/test_amqplib.py +++ b/kombu/tests/transport/test_amqplib.py @@ -2,12 +2,9 @@ from __future__ import absolute_import import sys -from nose import SkipTest - from kombu import Connection -from kombu.tests.utils import TestCase -from kombu.tests.utils import mask_modules, Mock +from kombu.tests.case import Case, SkipTest, Mock, mask_modules class MockConnection(dict): @@ -35,7 +32,7 @@ else: pass -class amqplibCase(TestCase): +class amqplibCase(Case): def setUp(self): if amqplib is None: diff --git a/kombu/tests/transport/test_base.py b/kombu/tests/transport/test_base.py index e96cd130..c4b344af 100644 --- a/kombu/tests/transport/test_base.py +++ b/kombu/tests/transport/test_base.py @@ -3,11 +3,10 @@ from __future__ import absolute_import from kombu import Connection, Consumer, Exchange, Producer, Queue from kombu.transport.base import Message, StdChannel, Transport -from kombu.tests.utils import TestCase -from kombu.tests.utils import Mock +from kombu.tests.case import Case, Mock -class test_StdChannel(TestCase): +class test_StdChannel(Case): def setUp(self): self.conn = Connection('memory://') @@ -37,7 +36,7 @@ class test_StdChannel(TestCase): ) -class test_Message(TestCase): +class test_Message(Case): def setUp(self): self.conn = Connection('memory://') @@ -84,7 +83,7 @@ class test_Message(TestCase): self.assertIn("Couldn't ack", logger.critical.call_args[0][0]) -class test_interface(TestCase): +class test_interface(Case): def test_establish_connection(self): with self.assertRaises(NotImplementedError): diff --git a/kombu/tests/transport/test_filesystem.py b/kombu/tests/transport/test_filesystem.py index 7bdad8f5..876c203f 100644 --- a/kombu/tests/transport/test_filesystem.py +++ b/kombu/tests/transport/test_filesystem.py @@ -2,14 +2,12 @@ from __future__ import absolute_import import tempfile -from nose import SkipTest - from kombu import Connection, Exchange, Queue, Consumer, Producer -from kombu.tests.utils import TestCase +from kombu.tests.case import Case, SkipTest -class test_FilesystemTransport(TestCase): +class test_FilesystemTransport(Case): def setUp(self): try: diff --git a/kombu/tests/transport/test_memory.py b/kombu/tests/transport/test_memory.py index 970681d7..605527f4 100644 --- a/kombu/tests/transport/test_memory.py +++ b/kombu/tests/transport/test_memory.py @@ -4,10 +4,10 @@ import socket from kombu import Connection, Exchange, Queue, Consumer, Producer -from kombu.tests.utils import TestCase +from kombu.tests.case import Case -class test_MemoryTransport(TestCase): +class test_MemoryTransport(Case): def setUp(self): self.c = Connection(transport='memory') @@ -18,6 +18,14 @@ class test_MemoryTransport(TestCase): self.q2 = Queue('test_transport_memory2', exchange=self.e, routing_key='test_transport_memory2') + self.fanout = Exchange('test_transport_memory_fanout', type='fanout') + self.q3 = Queue('test_transport_memory_fanout1', + exchange=self.fanout) + self.q4 = Queue('test_transport_memory_fanout2', + exchange=self.fanout) + + def test_driver_version(self): + self.assertTrue(self.c.transport.driver_version()) def test_produce_consume_noack(self): channel = self.c.channel() @@ -42,6 +50,21 @@ class test_MemoryTransport(TestCase): self.assertEqual(len(_received), 10) + def test_produce_consume_fanout(self): + producer = self.c.Producer() + consumer = self.c.Consumer([self.q3, self.q4]) + + producer.publish( + {'hello': 'world'}, + declare=consumer.queues, + exchange=self.fanout, + ) + + self.assertEqual(self.q3(self.c).get().payload, {'hello': 'world'}) + self.assertEqual(self.q4(self.c).get().payload, {'hello': 'world'}) + self.assertIsNone(self.q3(self.c).get()) + self.assertIsNone(self.q4(self.c).get()) + def test_produce_consume(self): channel = self.c.channel() producer = Producer(channel, self.e) diff --git a/kombu/tests/transport/test_mongodb.py b/kombu/tests/transport/test_mongodb.py index 522df04a..fbd9a774 100644 --- a/kombu/tests/transport/test_mongodb.py +++ b/kombu/tests/transport/test_mongodb.py @@ -1,10 +1,8 @@ from __future__ import absolute_import -from nose import SkipTest - from kombu import Connection -from kombu.tests.utils import TestCase, skip_if_not_module +from kombu.tests.case import Case, SkipTest, skip_if_not_module class MockConnection(dict): @@ -13,7 +11,7 @@ class MockConnection(dict): self[key] = value -class test_mongodb(TestCase): +class test_mongodb(Case): @skip_if_not_module('pymongo') def test_url_parser(self): diff --git a/kombu/tests/transport/test_pyamqp.py b/kombu/tests/transport/test_pyamqp.py index 32f1c229..9b948ed6 100644 --- a/kombu/tests/transport/test_pyamqp.py +++ b/kombu/tests/transport/test_pyamqp.py @@ -2,8 +2,6 @@ from __future__ import absolute_import import sys -from mock import patch -from nose import SkipTest from itertools import count try: @@ -15,8 +13,7 @@ else: from kombu import Connection from kombu.five import nextfun -from kombu.tests.utils import TestCase -from kombu.tests.utils import mask_modules, Mock +from kombu.tests.case import Case, Mock, SkipTest, mask_modules, patch class MockConnection(dict): @@ -25,7 +22,7 @@ class MockConnection(dict): self[key] = value -class test_Channel(TestCase): +class test_Channel(Case): def setUp(self): if pyamqp is None: @@ -81,7 +78,7 @@ class test_Channel(TestCase): self.assertNotIn('my-consumer-tag', self.channel.no_ack_consumers) -class test_Transport(TestCase): +class test_Transport(Case): def setUp(self): if pyamqp is None: @@ -94,6 +91,9 @@ class test_Transport(TestCase): self.transport.create_channel(connection) connection.channel.assert_called_with() + def test_driver_version(self): + self.assertTrue(self.transport.driver_version()) + def test_drain_events(self): connection = Mock() self.transport.drain_events(connection, timeout=10.0) @@ -134,7 +134,7 @@ class test_Transport(TestCase): sys.modules['amqp.connection'] = pm -class test_pyamqp(TestCase): +class test_pyamqp(Case): def setUp(self): if pyamqp is None: diff --git a/kombu/tests/transport/test_redis.py b/kombu/tests/transport/test_redis.py index 2a626085..1bb26044 100644 --- a/kombu/tests/transport/test_redis.py +++ b/kombu/tests/transport/test_redis.py @@ -3,7 +3,6 @@ from __future__ import absolute_import import socket import types -from mock import patch from anyjson import dumps from collections import defaultdict from itertools import count @@ -13,8 +12,9 @@ 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 -from kombu.tests.utils import Mock, module_exists, skip_if_not_module +from kombu.tests.case import ( + Case, Mock, module_exists, skip_if_not_module, patch, +) class _poll(eventio._select): @@ -213,7 +213,7 @@ class Transport(redis.Transport): return ((KeyError, ), (IndexError, )) -class test_Channel(TestCase): +class test_Channel(Case): def setUp(self): self.connection = Connection(transport=Transport) @@ -488,7 +488,7 @@ class test_Channel(TestCase): self.assertEqual(connparams['path'], '/tmp/redis.sock') -class test_Redis(TestCase): +class test_Redis(Case): def setUp(self): self.connection = Connection(transport=Transport) @@ -644,7 +644,7 @@ def _redis_modules(): return myredis, exceptions -class test_MultiChannelPoller(TestCase): +class test_MultiChannelPoller(Case): Poller = redis.MultiChannelPoller def test_close_unregisters_fds(self): diff --git a/kombu/tests/transport/test_sqlalchemy.py b/kombu/tests/transport/test_sqlalchemy.py index d3b93662..07055999 100644 --- a/kombu/tests/transport/test_sqlalchemy.py +++ b/kombu/tests/transport/test_sqlalchemy.py @@ -1,13 +1,10 @@ from __future__ import absolute_import -from mock import patch -from nose import SkipTest - from kombu import Connection -from kombu.tests.utils import TestCase +from kombu.tests.case import Case, SkipTest, patch -class test_sqlalchemy(TestCase): +class test_sqlalchemy(Case): def setUp(self): try: diff --git a/kombu/tests/transport/test_transport.py b/kombu/tests/transport/test_transport.py index 608b9767..96845a4a 100644 --- a/kombu/tests/transport/test_transport.py +++ b/kombu/tests/transport/test_transport.py @@ -1,13 +1,11 @@ from __future__ import absolute_import -from mock import patch - from kombu import transport -from kombu.tests.utils import TestCase +from kombu.tests.case import Case, patch -class test_transport(TestCase): +class test_transport(Case): def test_resolve_transport_when_callable(self): from kombu.transport.memory import Transport @@ -16,7 +14,7 @@ class test_transport(TestCase): Transport) -class test_transport_gettoq(TestCase): +class test_transport_gettoq(Case): @patch('warnings.warn') def test_compat(self, warn): diff --git a/kombu/tests/transport/virtual/test_base.py b/kombu/tests/transport/virtual/test_base.py index d20087c1..c05ab00d 100644 --- a/kombu/tests/transport/virtual/test_base.py +++ b/kombu/tests/transport/virtual/test_base.py @@ -2,27 +2,24 @@ from __future__ import absolute_import import warnings -from mock import patch - from kombu import Connection -from kombu.exceptions import StdChannelError +from kombu.exceptions import ResourceError, StdChannelError from kombu.transport import virtual from kombu.utils import uuid from kombu.compression import compress -from kombu.tests.utils import TestCase -from kombu.tests.utils import Mock, redirect_stdouts +from kombu.tests.case import Case, Mock, patch, redirect_stdouts def client(**kwargs): - return Connection(transport='kombu.transport.virtual.Transport', **kwargs) + return Connection(transport='kombu.transport.virtual:Transport', **kwargs) def memory_client(): return Connection(transport='memory') -class test_BrokerState(TestCase): +class test_BrokerState(Case): def test_constructor(self): s = virtual.BrokerState() @@ -34,7 +31,7 @@ class test_BrokerState(TestCase): self.assertEqual(t.bindings, 32) -class test_QoS(TestCase): +class test_QoS(Case): def setUp(self): self.q = virtual.QoS(client().channel(), prefetch_count=10) @@ -99,8 +96,11 @@ class test_QoS(TestCase): self.q._delivered['foo'] = 1 self.assertEqual(self.q.get('foo'), 1) + def test_restore_visible_interface(self): + self.q.restore_visible() + -class test_Message(TestCase): +class test_Message(Case): def test_create(self): c = client().channel() @@ -132,7 +132,7 @@ class test_Message(TestCase): self.assertFalse('compression' in dict_['headers']) -class test_AbstractChannel(TestCase): +class test_AbstractChannel(Case): def test_get(self): with self.assertRaises(NotImplementedError): @@ -173,7 +173,7 @@ class test_AbstractChannel(TestCase): self.assertTrue(cycle.called) -class test_Channel(TestCase): +class test_Channel(Case): def setUp(self): self.channel = client().channel() @@ -182,6 +182,14 @@ class test_Channel(TestCase): if self.channel._qos is not None: self.channel._qos._on_collect.cancel() + def test_exceeds_channel_max(self): + c = client() + t = c.transport + avail = t._avail_channel_ids = Mock(name='_avail_channel_ids') + avail.pop.side_effect = IndexError() + with self.assertRaises(ResourceError): + virtual.Channel(t) + def test_exchange_bind_interface(self): with self.assertRaises(NotImplementedError): self.channel.exchange_bind('dest', 'src', 'key') @@ -487,7 +495,7 @@ class test_Channel(TestCase): self.channel.queue_declare(queue='21wisdjwqe', passive=True) -class test_Transport(TestCase): +class test_Transport(Case): def setUp(self): self.transport = client().transport diff --git a/kombu/tests/transport/virtual/test_exchange.py b/kombu/tests/transport/virtual/test_exchange.py index 3c58e10c..e32b1fc1 100644 --- a/kombu/tests/transport/virtual/test_exchange.py +++ b/kombu/tests/transport/virtual/test_exchange.py @@ -3,12 +3,11 @@ from __future__ import absolute_import from kombu import Connection from kombu.transport.virtual import exchange +from kombu.tests.case import Case, Mock from kombu.tests.mocks import Transport -from kombu.tests.utils import TestCase -from kombu.tests.utils import Mock -class ExchangeCase(TestCase): +class ExchangeCase(Case): type = None def setUp(self): diff --git a/kombu/tests/transport/virtual/test_scheduling.py b/kombu/tests/transport/virtual/test_scheduling.py index 1a6c32bc..ccd7d4ee 100644 --- a/kombu/tests/transport/virtual/test_scheduling.py +++ b/kombu/tests/transport/virtual/test_scheduling.py @@ -2,7 +2,7 @@ from __future__ import absolute_import from kombu.transport.virtual.scheduling import FairCycle -from kombu.tests.utils import TestCase +from kombu.tests.case import Case class MyEmpty(Exception): @@ -16,7 +16,7 @@ def consume(fun, n): return r -class test_FairCycle(TestCase): +class test_FairCycle(Case): def test_cycle(self): resources = ['a', 'b', 'c', 'd', 'e'] diff --git a/kombu/tests/utilities/__init__.py b/kombu/tests/utils/__init__.py index e69de29b..e69de29b 100644 --- a/kombu/tests/utilities/__init__.py +++ b/kombu/tests/utils/__init__.py diff --git a/kombu/tests/utilities/test_amq_manager.py b/kombu/tests/utils/test_amq_manager.py index ffa0c555..b34b52e8 100644 --- a/kombu/tests/utilities/test_amq_manager.py +++ b/kombu/tests/utils/test_amq_manager.py @@ -1,12 +1,11 @@ from __future__ import absolute_import -from mock import patch - from kombu import Connection -from kombu.tests.utils import TestCase, mask_modules, module_exists + +from kombu.tests.case import Case, mask_modules, module_exists, patch -class test_get_manager(TestCase): +class test_get_manager(Case): @mask_modules('pyrabbit') def test_without_pyrabbit(self): diff --git a/kombu/tests/utilities/test_debug.py b/kombu/tests/utils/test_debug.py index 78c9f029..ea25cb77 100644 --- a/kombu/tests/utilities/test_debug.py +++ b/kombu/tests/utils/test_debug.py @@ -2,16 +2,14 @@ from __future__ import absolute_import import logging -from mock import Mock, patch - from kombu.utils.debug import ( setup_logging, Logwrapped, ) -from kombu.tests.utils import TestCase +from kombu.tests.case import Case, Mock, patch -class test_setup_logging(TestCase): +class test_setup_logging(Case): def test_adds_handlers_sets_level(self): with patch('kombu.utils.debug.get_logger') as get_logger: @@ -24,7 +22,7 @@ class test_setup_logging(TestCase): logger.setLevel.assert_called_with(logging.DEBUG) -class test_Logwrapped(TestCase): +class test_Logwrapped(Case): def test_wraps(self): with patch('kombu.utils.debug.get_logger') as get_logger: @@ -54,3 +52,5 @@ class test_Logwrapped(TestCase): W.some_method(kw=1) self.assertTrue(logger.debug.called) self.assertIn('ident', logger.debug.call_args[0][0]) + + self.assertEqual(dir(W), dir(W.instance)) diff --git a/kombu/tests/utilities/test_encoding.py b/kombu/tests/utils/test_encoding.py index 5b28e8a1..a56d2a7e 100644 --- a/kombu/tests/utilities/test_encoding.py +++ b/kombu/tests/utils/test_encoding.py @@ -5,13 +5,11 @@ from __future__ import unicode_literals import sys from contextlib import contextmanager -from mock import patch -from nose import SkipTest from kombu.five import bytes_t, string_t from kombu.utils.encoding import safe_str, default_encoding -from kombu.tests.utils import TestCase +from kombu.tests.case import Case, SkipTest, patch @contextmanager @@ -25,7 +23,7 @@ def clean_encoding(): sys.modules['kombu.utils.encoding'] = old_encoding -class test_default_encoding(TestCase): +class test_default_encoding(Case): @patch('sys.getdefaultencoding') def test_default(self, getdefaultencoding): @@ -39,7 +37,7 @@ class test_default_encoding(TestCase): getdefaultencoding.assert_called_with() -class test_encoding_utils(TestCase): +class test_encoding_utils(Case): def setUp(self): if sys.version_info >= (3, 0): @@ -58,7 +56,7 @@ class test_encoding_utils(TestCase): self.assertTrue(e.default_encode(b'foo')) -class test_safe_str(TestCase): +class test_safe_str(Case): def setUp(self): self._cencoding = patch('sys.getdefaultencoding') diff --git a/kombu/tests/utilities/test_functional.py b/kombu/tests/utils/test_functional.py index f463ab87..20b8bbd1 100644 --- a/kombu/tests/utilities/test_functional.py +++ b/kombu/tests/utils/test_functional.py @@ -4,14 +4,14 @@ import pickle from kombu.utils.functional import lazy, maybe_evaluate -from kombu.tests.utils import TestCase +from kombu.tests.case import Case def double(x): return x * 2 -class test_lazy(TestCase): +class test_lazy(Case): def test__str__(self): self.assertEqual( @@ -25,6 +25,10 @@ class test_lazy(TestCase): "'fi fa fo'", ) + def test__cmp__(self): + self.assertEqual(lazy(lambda: 10).__cmp__(lazy(lambda: 20)), -1) + self.assertEqual(lazy(lambda: 10).__cmp__(5), 1) + def test_evaluate(self): self.assertEqual(lazy(lambda: 2 + 2)(), 4) self.assertEqual(lazy(lambda x: x * 4, 2), 8) @@ -48,7 +52,7 @@ class test_lazy(TestCase): self.assertEqual(x(), y()) -class test_maybe_evaluate(TestCase): +class test_maybe_evaluate(Case): def test_evaluates(self): self.assertEqual(maybe_evaluate(lazy(lambda: 10)), 10) diff --git a/kombu/tests/test_utils.py b/kombu/tests/utils/test_utils.py index 389f84b7..6392feec 100644 --- a/kombu/tests/test_utils.py +++ b/kombu/tests/utils/test_utils.py @@ -5,7 +5,6 @@ import pickle import sys from functools import wraps -from mock import Mock, patch if sys.version_info >= (3, 0): from io import StringIO, BytesIO @@ -15,8 +14,8 @@ else: from kombu import utils from kombu.five import string_t -from .utils import ( - TestCase, +from kombu.tests.case import ( + Case, Mock, patch, redirect_stdouts, mask_modules, module_exists, skip_if_module, ) @@ -36,14 +35,14 @@ class OldString(object): return self.value.rsplit(*args, **kwargs) -class test_kombu_module(TestCase): +class test_kombu_module(Case): def test_dir(self): import kombu self.assertTrue(dir(kombu)) -class test_utils(TestCase): +class test_utils(Case): def test_maybe_list(self): self.assertEqual(utils.maybe_list(None), []) @@ -70,7 +69,7 @@ class test_utils(TestCase): ) -class test_UUID(TestCase): +class test_UUID(Case): def test_uuid4(self): self.assertNotEqual(utils.uuid4(), @@ -101,7 +100,7 @@ class test_UUID(TestCase): sys.modules['celery.utils'] = old_utils -class test_Misc(TestCase): +class test_Misc(Case): def test_kwdict(self): @@ -125,7 +124,7 @@ class MyBytesIO(BytesIO): pass -class test_emergency_dump_state(TestCase): +class test_emergency_dump_state(Case): @redirect_stdouts def test_dump(self, stdout, stderr): @@ -170,7 +169,7 @@ def insomnia(fun): return _inner -class test_retry_over_time(TestCase): +class test_retry_over_time(Case): def setUp(self): self.index = 0 @@ -234,7 +233,7 @@ class test_retry_over_time(TestCase): self.assertEqual(self.index, 0) -class test_cached_property(TestCase): +class test_cached_property(Case): def test_deleting(self): @@ -284,7 +283,7 @@ class test_cached_property(TestCase): del(x.foo) -class test_symbol_by_name(TestCase): +class test_symbol_by_name(Case): def test_instance_returns_instance(self): instance = object() @@ -316,7 +315,7 @@ class test_symbol_by_name(TestCase): self.assertTrue(utils.symbol_by_name(':Consumer', package='kombu')) -class test_ChannelPromise(TestCase): +class test_ChannelPromise(Case): def test_repr(self): self.assertIn( @@ -325,7 +324,7 @@ class test_ChannelPromise(TestCase): ) -class test_entrypoints(TestCase): +class test_entrypoints(Case): @mask_modules('pkg_resources') def test_without_pkg_resources(self): @@ -342,7 +341,7 @@ class test_entrypoints(TestCase): eps[1].load.assert_called_with() -class test_shufflecycle(TestCase): +class test_shufflecycle(Case): def test_shuffles(self): prev_repeat, utils.repeat = utils.repeat, Mock() |