mirror of https://github.com/celery/kombu.git
removed useless list copies, lookup methods now return sets
This commit is contained in:
parent
91f25df052
commit
af09172807
|
@ -23,17 +23,17 @@ class test_Direct(ExchangeCase):
|
|||
('rBaz', None, 'qBaz')]
|
||||
|
||||
def test_lookup(self):
|
||||
self.assertListEqual(
|
||||
self.assertSetEqual(
|
||||
self.e.lookup(self.table, 'eFoo', 'rFoo', None),
|
||||
['qFoo', 'qFox'],
|
||||
{'qFoo', 'qFox'},
|
||||
)
|
||||
self.assertListEqual(
|
||||
self.assertSetEqual(
|
||||
self.e.lookup(self.table, 'eMoz', 'rMoz', 'DEFAULT'),
|
||||
[],
|
||||
set(),
|
||||
)
|
||||
self.assertListEqual(
|
||||
self.assertSetEqual(
|
||||
self.e.lookup(self.table, 'eBar', 'rBar', None),
|
||||
['qBar'],
|
||||
{'qBar'},
|
||||
)
|
||||
|
||||
|
||||
|
@ -44,9 +44,9 @@ class test_Fanout(ExchangeCase):
|
|||
(None, None, 'qBar')]
|
||||
|
||||
def test_lookup(self):
|
||||
self.assertListEqual(
|
||||
self.assertSetEqual(
|
||||
self.e.lookup(self.table, 'eFoo', 'rFoo', None),
|
||||
['qFoo', 'qFox', 'qBar'],
|
||||
{'qFoo', 'qFox', 'qBar'},
|
||||
)
|
||||
|
||||
def test_deliver_when_fanout_supported(self):
|
||||
|
@ -84,23 +84,23 @@ class test_Topic(ExchangeCase):
|
|||
self.assertTupleEqual(x, ('stock.#', r'^stock\..*?$', 'qFoo'))
|
||||
|
||||
def test_lookup(self):
|
||||
self.assertListEqual(
|
||||
self.assertSetEqual(
|
||||
self.e.lookup(self.table, 'eFoo', 'stock.us.nasdaq', None),
|
||||
['rFoo', 'rBar'],
|
||||
{'rFoo', 'rBar'},
|
||||
)
|
||||
self.assertTrue(self.e._compiled)
|
||||
self.assertListEqual(
|
||||
self.assertSetEqual(
|
||||
self.e.lookup(self.table, 'eFoo', 'stock.europe.OSE', None),
|
||||
['rFoo'],
|
||||
{'rFoo'},
|
||||
)
|
||||
self.assertListEqual(
|
||||
self.assertSetEqual(
|
||||
self.e.lookup(self.table, 'eFoo', 'stockxeuropexOSE', None),
|
||||
[],
|
||||
set(),
|
||||
)
|
||||
self.assertListEqual(
|
||||
self.assertSetEqual(
|
||||
self.e.lookup(self.table, 'eFoo',
|
||||
'candy.schleckpulver.snap_crackle', None),
|
||||
[],
|
||||
set(),
|
||||
)
|
||||
|
||||
def test_deliver(self):
|
||||
|
@ -133,23 +133,23 @@ class test_TopicMultibind(ExchangeCase):
|
|||
for rkey, _, queue in self.table]
|
||||
|
||||
def test_lookup(self):
|
||||
self.assertListEqual(
|
||||
self.assertSetEqual(
|
||||
self.e.lookup(self.table, 'eFoo', 'stock.us.nasdaq', None),
|
||||
['rFoo'],
|
||||
{'rFoo'},
|
||||
)
|
||||
self.assertTrue(self.e._compiled)
|
||||
self.assertListEqual(
|
||||
self.assertSetEqual(
|
||||
self.e.lookup(self.table, 'eFoo', 'stock.europe.OSE', None),
|
||||
['rFoo'],
|
||||
{'rFoo'},
|
||||
)
|
||||
self.assertListEqual(
|
||||
self.assertSetEqual(
|
||||
self.e.lookup(self.table, 'eFoo', 'stockxeuropexOSE', None),
|
||||
['rFoo'],
|
||||
{'rFoo'},
|
||||
)
|
||||
self.assertListEqual(
|
||||
self.assertSetEqual(
|
||||
self.e.lookup(self.table, 'eFoo',
|
||||
'candy.schleckpulver.snap_crackle', None),
|
||||
['rFoo'],
|
||||
{'rFoo'},
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -52,13 +52,9 @@ class DirectExchange(ExchangeType):
|
|||
type = 'direct'
|
||||
|
||||
def lookup(self, table, exchange, routing_key, default):
|
||||
# Using an OrderedDict to purge queue duplicates while
|
||||
# keeping the same order in which they appear in the table
|
||||
return list(
|
||||
collections.OrderedDict.fromkeys(
|
||||
queue for rkey, _, queue in table
|
||||
if rkey == routing_key
|
||||
)
|
||||
return set(
|
||||
queue for rkey, _, queue in table
|
||||
if rkey == routing_key
|
||||
)
|
||||
|
||||
def deliver(self, message, exchange, routing_key, **kwargs):
|
||||
|
@ -82,13 +78,9 @@ class TopicExchange(ExchangeType):
|
|||
_compiled = {}
|
||||
|
||||
def lookup(self, table, exchange, routing_key, default):
|
||||
# Using an OrderedDict to purge queue duplicates while
|
||||
# keeping the same order in which they appear in the table
|
||||
return list(
|
||||
collections.OrderedDict.fromkeys(
|
||||
queue for rkey, pattern, queue in table
|
||||
if self._match(pattern, routing_key)
|
||||
)
|
||||
return set(
|
||||
queue for rkey, pattern, queue in table
|
||||
if self._match(pattern, routing_key)
|
||||
)
|
||||
|
||||
def deliver(self, message, exchange, routing_key, **kwargs):
|
||||
|
@ -133,12 +125,8 @@ class FanoutExchange(ExchangeType):
|
|||
type = 'fanout'
|
||||
|
||||
def lookup(self, table, exchange, routing_key, default):
|
||||
# Using an OrderedDict to purge queue duplicates while
|
||||
# keeping the same order in which they appear in the table
|
||||
return list(
|
||||
collections.OrderedDict.fromkeys(
|
||||
queue for _, _, queue in table
|
||||
)
|
||||
return set(
|
||||
queue for _, _, queue in table
|
||||
)
|
||||
|
||||
def deliver(self, message, exchange, routing_key, **kwargs):
|
||||
|
|
Loading…
Reference in New Issue