mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-26 01:44:11 +00:00
profiling: minor fixes and new testcase for IndexError exception
--HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40999
This commit is contained in:
parent
9d1855a66e
commit
fdfa5302a4
@ -132,7 +132,7 @@ class PriorityQueue3b(PriorityQueue3):
|
||||
"""deque+heapq+int"""
|
||||
|
||||
left_time = 0
|
||||
righ_time = 0
|
||||
right_time = 0
|
||||
|
||||
def push(self, item, priority=0):
|
||||
if priority == 0:
|
||||
@ -141,8 +141,8 @@ class PriorityQueue3b(PriorityQueue3):
|
||||
self.left_time += 1
|
||||
heappush(self.negitems, (priority, self.left_time, item))
|
||||
else:
|
||||
self.righ_time += 1
|
||||
heappush(self.positems, (priority, self.righ_time, item))
|
||||
self.right_time += 1
|
||||
heappush(self.positems, (priority, self.right_time, item))
|
||||
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
@ -240,7 +240,7 @@ class PriorityQueue5(object):
|
||||
yield (i, final)
|
||||
|
||||
def __nonzero__(self):
|
||||
return bool(len(self))
|
||||
return any(d for d in self.priolist)
|
||||
|
||||
class PriorityQueue5b(PriorityQueue5):
|
||||
"""list+deque+cache"""
|
||||
@ -283,4 +283,5 @@ class PriorityQueue5c(PriorityQueue5b):
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
__all__ = [name for name in globals().keys() if name.startswith('PriorityQueue')]
|
||||
|
@ -54,6 +54,10 @@ class TestPriorityQueue(object):
|
||||
pq.pop()
|
||||
self.assertEquals(len(pq), 0)
|
||||
|
||||
def test_indexerror(self):
|
||||
pq = self.PriorityQueue(PRIOSIZE)
|
||||
self.assertRaises(IndexError, pq.pop)
|
||||
|
||||
|
||||
# automatically test any PriorityQueueN class defined at pq_classes
|
||||
prioclasses = [(name, cls) for name, cls in globals().items() if name.startswith('PriorityQueue')]
|
||||
|
Loading…
x
Reference in New Issue
Block a user