From c1dc30eae30aefe9ab501012a3cd9c5e2aac0c58 Mon Sep 17 00:00:00 2001 From: Selwin Ong Date: Wed, 10 Sep 2014 00:00:16 +0700 Subject: [PATCH] Added __len__ method to Queue. --- rq/queue.py | 3 +++ tests/test_queue.py | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/rq/queue.py b/rq/queue.py index 621942a..7569104 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -68,6 +68,9 @@ class Queue(object): job_class = import_attribute(job_class) self.job_class = job_class + def __len__(self): + return self.count + @property def key(self): """Returns the Redis key for this Queue.""" diff --git a/tests/test_queue.py b/tests/test_queue.py index c60b510..e61568e 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -101,11 +101,13 @@ class TestQueue(RQTestCase): q.enqueue(say_hello, 'Charlie') self.testconn.lpush(q.key, '1', '2') - self.assertEquals(q.count, 4) + self.assertEqual(q.count, 4) + self.assertEqual(len(q), 4) q.compact() - self.assertEquals(q.count, 2) + self.assertEqual(q.count, 2) + self.assertEqual(len(q), 2) def test_enqueue(self): """Enqueueing job onto queues."""