rq/tests/fixtures.py

51 lines
1.1 KiB
Python
Raw Normal View History

"""
This file contains all jobs that are used in tests. Each of these test
fixtures has a slighty different characteristics.
"""
import time
2012-02-22 16:39:14 +00:00
def say_hello(name=None):
"""A job with a single argument and a return value."""
if name is None:
name = 'Stranger'
return 'Hi there, %s!' % (name,)
2012-02-22 16:39:14 +00:00
def do_nothing():
"""The best job in the world."""
pass
2012-02-22 16:39:14 +00:00
def div_by_zero(x):
"""Prepare for a division-by-zero exception."""
return x / 0
2012-02-22 16:39:14 +00:00
def some_calculation(x, y, z=1):
"""Some arbitrary calculation with three numbers. Choose z smartly if you
want a division by zero exception.
"""
return x * y / z
2012-02-22 16:39:14 +00:00
def create_file(path):
"""Creates a file at the given path. Actually, leaves evidence that the
job ran."""
with open(path, 'w') as f:
f.write('Just a sentinel.')
def create_file_after_timeout(path, timeout):
time.sleep(timeout)
create_file(path)
class Calculator(object):
"""Test instance methods."""
def __init__(self, denominator):
self.denominator = denominator
def calculate(x, y):
return x * y / self.denominator