mirror of https://github.com/rq/rq.git
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.
This commit is contained in:
parent
89293353d6
commit
a5dff6659c
|
@ -49,13 +49,16 @@ def access_self():
|
|||
return job.id
|
||||
|
||||
|
||||
class Calculator(object):
|
||||
"""Test instance methods."""
|
||||
def __init__(self, denominator):
|
||||
self.denominator = denominator
|
||||
class Number(object):
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
def calculate(self, x, y):
|
||||
return x * y / self.denominator
|
||||
@classmethod
|
||||
def divide(cls, x, y):
|
||||
return x * y
|
||||
|
||||
def div(self, y):
|
||||
return self.value / y
|
||||
|
||||
|
||||
with Connection():
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import times
|
||||
from datetime import datetime
|
||||
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 cPickle import loads
|
||||
from rq.job import Job, get_current_job
|
||||
|
@ -51,13 +51,13 @@ class TestJob(RQTestCase):
|
|||
|
||||
def test_create_instance_method_job(self):
|
||||
"""Creation of jobs for instance methods."""
|
||||
c = Calculator(2)
|
||||
job = Job.create(func=c.calculate, args=(3, 4))
|
||||
n = Number(2)
|
||||
job = Job.create(func=n.div, args=(4,))
|
||||
|
||||
# Job data is set
|
||||
self.assertEquals(job.func, c.calculate)
|
||||
self.assertEquals(job.instance, c)
|
||||
self.assertEquals(job.args, (3, 4))
|
||||
self.assertEquals(job.func, n.div)
|
||||
self.assertEquals(job.instance, n)
|
||||
self.assertEquals(job.args, (4,))
|
||||
|
||||
def test_create_job_from_string_function(self):
|
||||
"""Creation of jobs using string specifier."""
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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.job import Job, Status
|
||||
from rq.exceptions import InvalidJobOperationError
|
||||
|
@ -161,14 +161,14 @@ class TestQueue(RQTestCase):
|
|||
def test_dequeue_instance_method(self):
|
||||
"""Dequeueing instance method jobs from queues."""
|
||||
q = Queue()
|
||||
c = Calculator(2)
|
||||
result = q.enqueue(c.calculate, 3, 4)
|
||||
n = Number(2)
|
||||
q.enqueue(n.div, 4)
|
||||
|
||||
job = q.dequeue()
|
||||
# The instance has been pickled and unpickled, so it is now a separate
|
||||
# object. Test for equality using each object's __dict__ instead.
|
||||
self.assertEquals(job.instance.__dict__, c.__dict__)
|
||||
self.assertEquals(job.func.__name__, 'calculate')
|
||||
self.assertEquals(job.instance.__dict__, Number.__dict__)
|
||||
self.assertEquals(job.func.__name__, 'divide')
|
||||
self.assertEquals(job.args, (3, 4))
|
||||
|
||||
def test_dequeue_ignores_nonexisting_jobs(self):
|
||||
|
|
Loading…
Reference in New Issue