Replace the Calculator fixture by a Number fixture.

This makes the tests a little more realistic, since I want to add a test
for class methods.
main
Vincent Driessen 12 years ago
parent 89293353d6
commit a5dff6659c

@ -49,13 +49,16 @@ def access_self():
return job.id return job.id
class Calculator(object): class Number(object):
"""Test instance methods.""" def __init__(self, value):
def __init__(self, denominator): self.value = value
self.denominator = denominator
def calculate(self, x, y): @classmethod
return x * y / self.denominator def divide(cls, x, y):
return x * y
def div(self, y):
return self.value / y
with Connection(): with Connection():

@ -1,7 +1,7 @@
import times import times
from datetime import datetime from datetime import datetime
from tests import RQTestCase from tests import RQTestCase
from tests.fixtures import Calculator, some_calculation, say_hello, access_self from tests.fixtures import Number, some_calculation, say_hello, access_self
from tests.helpers import strip_milliseconds from tests.helpers import strip_milliseconds
from cPickle import loads from cPickle import loads
from rq.job import Job, get_current_job from rq.job import Job, get_current_job
@ -51,13 +51,13 @@ class TestJob(RQTestCase):
def test_create_instance_method_job(self): def test_create_instance_method_job(self):
"""Creation of jobs for instance methods.""" """Creation of jobs for instance methods."""
c = Calculator(2) n = Number(2)
job = Job.create(func=c.calculate, args=(3, 4)) job = Job.create(func=n.div, args=(4,))
# Job data is set # Job data is set
self.assertEquals(job.func, c.calculate) self.assertEquals(job.func, n.div)
self.assertEquals(job.instance, c) self.assertEquals(job.instance, n)
self.assertEquals(job.args, (3, 4)) self.assertEquals(job.args, (4,))
def test_create_job_from_string_function(self): def test_create_job_from_string_function(self):
"""Creation of jobs using string specifier.""" """Creation of jobs using string specifier."""

@ -1,5 +1,5 @@
from tests import RQTestCase from tests import RQTestCase
from tests.fixtures import Calculator, div_by_zero, say_hello, some_calculation from tests.fixtures import Number, div_by_zero, say_hello, some_calculation
from rq import Queue, get_failed_queue from rq import Queue, get_failed_queue
from rq.job import Job, Status from rq.job import Job, Status
from rq.exceptions import InvalidJobOperationError from rq.exceptions import InvalidJobOperationError
@ -161,14 +161,14 @@ class TestQueue(RQTestCase):
def test_dequeue_instance_method(self): def test_dequeue_instance_method(self):
"""Dequeueing instance method jobs from queues.""" """Dequeueing instance method jobs from queues."""
q = Queue() q = Queue()
c = Calculator(2) n = Number(2)
result = q.enqueue(c.calculate, 3, 4) q.enqueue(n.div, 4)
job = q.dequeue() job = q.dequeue()
# The instance has been pickled and unpickled, so it is now a separate # The instance has been pickled and unpickled, so it is now a separate
# object. Test for equality using each object's __dict__ instead. # object. Test for equality using each object's __dict__ instead.
self.assertEquals(job.instance.__dict__, c.__dict__) self.assertEquals(job.instance.__dict__, Number.__dict__)
self.assertEquals(job.func.__name__, 'calculate') self.assertEquals(job.func.__name__, 'divide')
self.assertEquals(job.args, (3, 4)) self.assertEquals(job.args, (3, 4))
def test_dequeue_ignores_nonexisting_jobs(self): def test_dequeue_ignores_nonexisting_jobs(self):

Loading…
Cancel
Save