@ -21,12 +21,12 @@ class TestQueue(RQTestCase):
def test_create_queue ( self ) :
""" Creating queues. """
q = Queue ( ' my-queue ' )
self . assertEqual s ( q . name , ' my-queue ' )
self . assertEqual ( q . name , ' my-queue ' )
def test_create_default_queue ( self ) :
""" Instantiating the default queue. """
q = Queue ( )
self . assertEqual s ( q . name , ' default ' )
self . assertEqual ( q . name , ' default ' )
def test_equality ( self ) :
""" Mathematical equality of queues. """
@ -34,10 +34,10 @@ class TestQueue(RQTestCase):
q2 = Queue ( ' foo ' )
q3 = Queue ( ' bar ' )
self . assertEqual s ( q1 , q2 )
self . assertEqual s ( q2 , q1 )
self . assertNotEqual s ( q1 , q3 )
self . assertNotEqual s ( q2 , q3 )
self . assertEqual ( q1 , q2 )
self . assertEqual ( q2 , q1 )
self . assertNotEqual ( q1 , q3 )
self . assertNotEqual ( q2 , q3 )
def test_empty_queue ( self ) :
""" Emptying queues. """
@ -45,11 +45,11 @@ class TestQueue(RQTestCase):
self . testconn . rpush ( ' rq:queue:example ' , ' foo ' )
self . testconn . rpush ( ' rq:queue:example ' , ' bar ' )
self . assertEqual s ( q . is_empty ( ) , False )
self . assertEqual ( q . is_empty ( ) , False )
q . empty ( )
self . assertEqual s ( q . is_empty ( ) , True )
self . assertEqual ( q . is_empty ( ) , True )
self . assertIsNone ( self . testconn . lpop ( ' rq:queue:example ' ) )
def test_empty_removes_jobs ( self ) :
@ -63,10 +63,10 @@ class TestQueue(RQTestCase):
def test_queue_is_empty ( self ) :
""" Detecting empty queues. """
q = Queue ( ' example ' )
self . assertEqual s ( q . is_empty ( ) , True )
self . assertEqual ( q . is_empty ( ) , True )
self . testconn . rpush ( ' rq:queue:example ' , ' sentinel message ' )
self . assertEqual s ( q . is_empty ( ) , False )
self . assertEqual ( q . is_empty ( ) , False )
def test_remove ( self ) :
""" Ensure queue.remove properly removes Job from queue. """
@ -113,7 +113,7 @@ class TestQueue(RQTestCase):
def test_enqueue ( self ) :
""" Enqueueing job onto queues. """
q = Queue ( )
self . assertEqual s ( q . is_empty ( ) , True )
self . assertEqual ( q . is_empty ( ) , True )
# say_hello spec holds which queue this is sent to
job = q . enqueue ( say_hello , ' Nick ' , foo = ' bar ' )
@ -122,8 +122,8 @@ class TestQueue(RQTestCase):
# Inspect data inside Redis
q_key = ' rq:queue:default '
self . assertEqual s ( self . testconn . llen ( q_key ) , 1 )
self . assertEqual s (
self . assertEqual ( self . testconn . llen ( q_key ) , 1 )
self . assertEqual (
self . testconn . lrange ( q_key , 0 , - 1 ) [ 0 ] . decode ( ' ascii ' ) ,
job_id )
@ -149,11 +149,11 @@ class TestQueue(RQTestCase):
q . push_job_id ( uuid )
# Pop it off the queue...
self . assertEqual s ( q . count , 1 )
self . assertEqual s ( q . pop_job_id ( ) , uuid )
self . assertEqual ( q . count , 1 )
self . assertEqual ( q . pop_job_id ( ) , uuid )
# ...and assert the queue count when down
self . assertEqual s ( q . count , 0 )
self . assertEqual ( q . count , 0 )
def test_dequeue ( self ) :
""" Dequeueing jobs from queues. """
@ -162,16 +162,16 @@ class TestQueue(RQTestCase):
result = q . enqueue ( say_hello , ' Rick ' , foo = ' bar ' )
# Dequeue a job (not a job ID) off the queue
self . assertEqual s ( q . count , 1 )
self . assertEqual ( q . count , 1 )
job = q . dequeue ( )
self . assertEqual s ( job . id , result . id )
self . assertEqual s ( job . func , say_hello )
self . assertEqual s ( job . origin , q . name )
self . assertEqual s ( job . args [ 0 ] , ' Rick ' )
self . assertEqual s ( job . kwargs [ ' foo ' ] , ' bar ' )
self . assertEqual ( job . id , result . id )
self . assertEqual ( job . func , say_hello )
self . assertEqual ( job . origin , q . name )
self . assertEqual ( job . args [ 0 ] , ' Rick ' )
self . assertEqual ( job . kwargs [ ' foo ' ] , ' bar ' )
# ...and assert the queue count when down
self . assertEqual s ( q . count , 0 )
self . assertEqual ( q . count , 0 )
def test_dequeue_deleted_jobs ( self ) :
""" Dequeueing deleted jobs from queues don ' t blow the stack. """
@ -191,9 +191,9 @@ class TestQueue(RQTestCase):
# The instance has been pickled and unpickled, so it is now a separate
# object. Test for equality using each object's __dict__ instead.
self . assertEqual s ( job . instance . __dict__ , n . __dict__ )
self . assertEqual s ( job . func . __name__ , ' div ' )
self . assertEqual s ( job . args , ( 4 , ) )
self . assertEqual ( job . instance . __dict__ , n . __dict__ )
self . assertEqual ( job . func . __name__ , ' div ' )
self . assertEqual ( job . args , ( 4 , ) )
def test_dequeue_class_method ( self ) :
""" Dequeueing class method jobs from queues. """
@ -202,9 +202,9 @@ class TestQueue(RQTestCase):
job = q . dequeue ( )
self . assertEqual s ( job . instance . __dict__ , Number . __dict__ )
self . assertEqual s ( job . func . __name__ , ' divide ' )
self . assertEqual s ( job . args , ( 3 , 4 ) )
self . assertEqual ( job . instance . __dict__ , Number . __dict__ )
self . assertEqual ( job . func . __name__ , ' divide ' )
self . assertEqual ( job . args , ( 3 , 4 ) )
def test_dequeue_ignores_nonexisting_jobs ( self ) :
""" Dequeuing silently ignores non-existing jobs. """
@ -217,40 +217,40 @@ class TestQueue(RQTestCase):
q . push_job_id ( uuid )
# Dequeue simply ignores the missing job and returns None
self . assertEqual s ( q . count , 4 )
self . assertEqual s ( q . dequeue ( ) . id , result . id )
self . assertEqual ( q . count , 4 )
self . assertEqual ( q . dequeue ( ) . id , result . id )
self . assertIsNone ( q . dequeue ( ) )
self . assertEqual s ( q . count , 0 )
self . assertEqual ( q . count , 0 )
def test_dequeue_any ( self ) :
""" Fetching work from any given queue. """
fooq = Queue ( ' foo ' )
barq = Queue ( ' bar ' )
self . assertEqual s ( Queue . dequeue_any ( [ fooq , barq ] , None ) , None )
self . assertEqual ( Queue . dequeue_any ( [ fooq , barq ] , None ) , None )
# Enqueue a single item
barq . enqueue ( say_hello )
job , queue = Queue . dequeue_any ( [ fooq , barq ] , None )
self . assertEqual s ( job . func , say_hello )
self . assertEqual s ( queue , barq )
self . assertEqual ( job . func , say_hello )
self . assertEqual ( queue , barq )
# Enqueue items on both queues
barq . enqueue ( say_hello , ' for Bar ' )
fooq . enqueue ( say_hello , ' for Foo ' )
job , queue = Queue . dequeue_any ( [ fooq , barq ] , None )
self . assertEqual s ( queue , fooq )
self . assertEqual s ( job . func , say_hello )
self . assertEqual s ( job . origin , fooq . name )
self . assertEqual s ( job . args [ 0 ] , ' for Foo ' ,
self . assertEqual ( queue , fooq )
self . assertEqual ( job . func , say_hello )
self . assertEqual ( job . origin , fooq . name )
self . assertEqual ( job . args [ 0 ] , ' for Foo ' ,
' Foo should be dequeued first. ' )
job , queue = Queue . dequeue_any ( [ fooq , barq ] , None )
self . assertEqual s ( queue , barq )
self . assertEqual s ( job . func , say_hello )
self . assertEqual s ( job . origin , barq . name )
self . assertEqual s ( job . args [ 0 ] , ' for Bar ' ,
self . assertEqual ( queue , barq )
self . assertEqual ( job . func , say_hello )
self . assertEqual ( job . origin , barq . name )
self . assertEqual ( job . args [ 0 ] , ' for Bar ' ,
' Bar should be dequeued second. ' )
def test_dequeue_any_ignores_nonexisting_jobs ( self ) :
@ -261,10 +261,10 @@ class TestQueue(RQTestCase):
q . push_job_id ( uuid )
# Dequeue simply ignores the missing job and returns None
self . assertEqual s ( q . count , 1 )
self . assertEqual s ( Queue . dequeue_any ( [ Queue ( ) , Queue ( ' low ' ) ] , None ) , # noqa
self . assertEqual ( q . count , 1 )
self . assertEqual ( Queue . dequeue_any ( [ Queue ( ) , Queue ( ' low ' ) ] , None ) , # noqa
None )
self . assertEqual s ( q . count , 0 )
self . assertEqual ( q . count , 0 )
def test_enqueue_sets_status ( self ) :
""" Enqueueing a job sets its status to " queued " . """
@ -305,15 +305,15 @@ class TestQueue(RQTestCase):
q3 = Queue ( ' third-queue ' )
# Ensure a queue is added only once a job is enqueued
self . assertEqual s ( len ( Queue . all ( ) ) , 0 )
self . assertEqual ( len ( Queue . all ( ) ) , 0 )
q1 . enqueue ( say_hello )
self . assertEqual s ( len ( Queue . all ( ) ) , 1 )
self . assertEqual ( len ( Queue . all ( ) ) , 1 )
# Ensure this holds true for multiple queues
q2 . enqueue ( say_hello )
q3 . enqueue ( say_hello )
names = [ q . name for q in Queue . all ( ) ]
self . assertEqual s ( len ( Queue . all ( ) ) , 3 )
self . assertEqual ( len ( Queue . all ( ) ) , 3 )
# Verify names
self . assertTrue ( ' first-queue ' in names )
@ -325,7 +325,7 @@ class TestQueue(RQTestCase):
w . work ( burst = True )
# Queue.all() should still report the empty queues
self . assertEqual s ( len ( Queue . all ( ) ) , 3 )
self . assertEqual ( len ( Queue . all ( ) ) , 3 )
def test_enqueue_dependents ( self ) :
""" Enqueueing dependent jobs pushes all jobs in the depends set to the queue
@ -447,12 +447,12 @@ class TestFailedQueue(RQTestCase):
get_failed_queue ( ) . quarantine ( job , Exception ( ' Some fake error ' ) ) # noqa
self . assertEqual ( Queue . all ( ) , [ get_failed_queue ( ) ] ) # noqa
self . assertEqual s ( get_failed_queue ( ) . count , 1 )
self . assertEqual ( get_failed_queue ( ) . count , 1 )
get_failed_queue ( ) . requeue ( job . id )
self . assertEqual s ( get_failed_queue ( ) . count , 0 )
self . assertEqual s ( Queue ( ' fake ' ) . count , 1 )
self . assertEqual ( get_failed_queue ( ) . count , 0 )
self . assertEqual ( Queue ( ' fake ' ) . count , 1 )
def test_requeue_nonfailed_job_fails ( self ) :
""" Requeueing non-failed jobs raises error. """
@ -471,7 +471,7 @@ class TestFailedQueue(RQTestCase):
job . save ( )
get_failed_queue ( ) . quarantine ( job , Exception ( ' Some fake error ' ) )
self . assertEqual s ( job . timeout , 200 )
self . assertEqual ( job . timeout , 200 )
def test_requeueing_preserves_timeout ( self ) :
""" Requeueing preserves job timeout. """
@ -483,7 +483,7 @@ class TestFailedQueue(RQTestCase):
get_failed_queue ( ) . requeue ( job . id )
job = Job . fetch ( job . id )
self . assertEqual s ( job . timeout , 200 )
self . assertEqual ( job . timeout , 200 )
def test_requeue_sets_status_to_queued ( self ) :
""" Requeueing a job should set its status back to QUEUED. """