main
Vincent Driessen 12 years ago
parent 57ea6203d1
commit 90fcb6c9d0

@ -158,14 +158,13 @@ class Queue(object):
meaningful to the import context of the workers)
"""
if not isinstance(f, string_types) and f.__module__ == '__main__':
raise ValueError(
'Functions from the __main__ module cannot be processed '
'by workers.')
raise ValueError('Functions from the __main__ module cannot be processed '
'by workers.')
# Detect explicit invocations, i.e. of the form:
# q.enqueue(foo, args=(1, 2), kwargs={'a': 1}, timeout=30)
timeout = None
description=None
description = None
result_ttl = None
if 'args' in kwargs or 'kwargs' in kwargs:
assert args == (), 'Extra positional arguments cannot be used when using explicit args and kwargs.' # noqa

@ -88,9 +88,9 @@ class TestJob(RQTestCase):
"""Fetching jobs."""
# Prepare test
self.testconn.hset('rq:job:some_id', 'data',
"(S'tests.fixtures.some_calculation'\nN(I3\nI4\nt(dp1\nS'z'\nI2\nstp2\n.") # noqa
"(S'tests.fixtures.some_calculation'\nN(I3\nI4\nt(dp1\nS'z'\nI2\nstp2\n.")
self.testconn.hset('rq:job:some_id', 'created_at',
"2012-02-07 22:13:24+0000")
'2012-02-07 22:13:24+0000')
# Fetch returns a job
job = Job.fetch('some_id')
@ -110,13 +110,13 @@ class TestJob(RQTestCase):
expected_date = strip_milliseconds(job.created_at)
stored_date = self.testconn.hget(job.key, 'created_at').decode('utf-8')
self.assertEquals(
times.to_universal(stored_date),
expected_date)
times.to_universal(stored_date),
expected_date)
# ... and no other keys are stored
self.assertEqual(
self.testconn.hkeys(job.key),
[b'created_at'])
self.testconn.hkeys(job.key),
[b'created_at'])
def test_persistence_of_typical_jobs(self):
"""Storing typical jobs."""
@ -126,13 +126,13 @@ class TestJob(RQTestCase):
expected_date = strip_milliseconds(job.created_at)
stored_date = self.testconn.hget(job.key, 'created_at').decode('utf-8')
self.assertEquals(
times.to_universal(stored_date),
expected_date)
times.to_universal(stored_date),
expected_date)
# ... and no other keys are stored
self.assertEqual(
sorted(self.testconn.hkeys(job.key)),
[b'created_at', b'data', b'description'])
sorted(self.testconn.hkeys(job.key)),
[b'created_at', b'data', b'description'])
def test_store_then_fetch(self):
"""Store, then fetch."""
@ -195,12 +195,12 @@ class TestJob(RQTestCase):
"""Ensure that job's result_ttl is set properly"""
job = Job.create(func=say_hello, args=('Lionel',), result_ttl=10)
job.save()
job_from_queue = Job.fetch(job.id, connection=self.testconn)
Job.fetch(job.id, connection=self.testconn)
self.assertEqual(job.result_ttl, 10)
job = Job.create(func=say_hello, args=('Lionel',))
job.save()
job_from_queue = Job.fetch(job.id, connection=self.testconn)
Job.fetch(job.id, connection=self.testconn)
self.assertEqual(job.result_ttl, None)
def test_description_is_persisted(self):
@ -208,13 +208,13 @@ class TestJob(RQTestCase):
description = 'Say hello!'
job = Job.create(func=say_hello, args=('Lionel',), description=description)
job.save()
job_from_queue = Job.fetch(job.id, connection=self.testconn)
Job.fetch(job.id, connection=self.testconn)
self.assertEqual(job.description, description)
# Ensure job description is constructed from function call string
job = Job.create(func=say_hello, args=('Lionel',))
job.save()
job_from_queue = Job.fetch(job.id, connection=self.testconn)
Job.fetch(job.id, connection=self.testconn)
self.assertEqual(job.description, job.get_call_string())
def test_job_access_within_job_function(self):

Loading…
Cancel
Save