Permalink
Browse files

fixed tests so that all the namespace work done

by fakechris is now accounted for.

Modified the job and failure items to have slightly
different method signatures. This work will probably
be updated in the failure backend branch that should
be dropping soon
  • Loading branch information...
1 parent 571c160 commit 64ff2bb1a477607b993bde14f12ecc520427e658 Matt George committed Dec 10, 2009
Showing with 78 additions and 61 deletions.
  1. +5 −0 AUTHORS.md
  2. +2 −0 HISTORY.md
  3. +11 −0 coverage.report
  4. +1 −1 pyres/failure.py
  5. +3 −3 pyres/job.py
  6. +2 −2 tests/test_jobs.py
  7. +17 −18 tests/test_resq.py
  8. +8 −8 tests/test_stats.py
  9. +29 −29 tests/test_worker.py
View
@@ -0,0 +1,5 @@
+## Authors
+* Matt George
+* Chris Song
+
+Inspired by Resque, by Chris Wanstrath
View
@@ -2,6 +2,8 @@
* updated setup.py
* refactored package for better testing
+* resque namespacing by fakechris
+* smarter import from string by fakechris
## 0.2.0 (2009-12-09)
View
@@ -0,0 +1,11 @@
+Name Stmts Exec Cover Missing
+------------------------------------------------
+pyres 138 131 94% 26, 39, 98, 133-134, 144-145
+pyres.exceptions 2 2 100%
+pyres.failure 23 22 95% 41
+pyres.job 23 23 100%
+pyres.worker 189 146 77% 66, 74, 84-112, 161, 179, 186, 230-241
+------------------------------------------------
+TOTAL 375 324 86%
+----------------------------------------------------------------------
+Ran 32 tests in 0.884s
View
@@ -2,7 +2,7 @@
from pyres import ResQ
import sys, traceback
class Failure(object):
- def __init__(self, exp, worker, queue, payload):
+ def __init__(self, exp, queue, payload, worker=None):
excc, _, tb = sys.exc_info()
self._exception = excc
View
@@ -1,7 +1,7 @@
from pyres import ResQ, str_to_class, safe_str_to_class
from pyres.failure import Failure
class Job(object):
- def __init__(self, queue, payload, resq, worker):
+ def __init__(self, queue, payload, resq, worker=None):
self._queue = queue
self._payload = payload
self.resq = resq
@@ -18,11 +18,11 @@ def perform(self):
def fail(self, exception):
#Failure.create(exception)
- failure = Failure(exception, self._worker, self._queue, self._payload)
+ failure = Failure(exception, self._queue, self._payload, self._worker)
failure.save(self.resq)
@classmethod
- def reserve(cls, queue, res, worker):
+ def reserve(cls, queue, res, worker=None):
payload = res.pop(queue)
if payload:
return cls(queue, payload, res, worker)
View
@@ -18,6 +18,6 @@ def test_perform(self):
def test_fail(self):
self.resq.enqueue(Basic,"test1")
job = Job.reserve('basic',self.resq)
- assert self.redis.llen('failed') == 0
+ assert self.redis.llen('resque:failed') == 0
job.fail("problem")
- assert self.redis.llen('failed') == 1
+ assert self.redis.llen('resque:failed') == 1
View
@@ -8,24 +8,24 @@ def test_enqueue(self):
self.resq.enqueue(Basic,"test1")
self.resq.enqueue(Basic,"test2")
ResQ._enqueue(Basic, "test3")
- assert self.redis.llen("queue:basic") == 3
- assert self.redis.sismember('queues','basic')
+ assert self.redis.llen("resque:queue:basic") == 3
+ assert self.redis.sismember('resque:queues','basic')
def test_push(self):
self.resq.push('pushq','content-newqueue')
self.resq.push('pushq','content2-newqueue')
- assert self.redis.llen('queue:pushq') == 2
- assert self.redis.lindex('queue:pushq', 0) == ResQ.encode('content-newqueue')
- assert self.redis.lindex('queue:pushq', 1) == ResQ.encode('content2-newqueue')
+ assert self.redis.llen('resque:queue:pushq') == 2
+ assert self.redis.lindex('resque:queue:pushq', 0) == ResQ.encode('content-newqueue')
+ assert self.redis.lindex('resque:queue:pushq', 1) == ResQ.encode('content2-newqueue')
def test_pop(self):
self.resq.push('pushq','content-newqueue')
self.resq.push('pushq','content2-newqueue')
- assert self.redis.llen('queue:pushq') == 2
+ assert self.redis.llen('resque:queue:pushq') == 2
assert self.resq.pop('pushq') == 'content-newqueue'
- assert self.redis.llen('queue:pushq') == 1
+ assert self.redis.llen('resque:queue:pushq') == 1
assert self.resq.pop('pushq') == 'content2-newqueue'
- assert self.redis.llen('queue:pushq') == 0
+ assert self.redis.llen('resque:queue:pushq') == 0
def test_peek(self):
self.resq.enqueue(Basic,"test1")
@@ -62,31 +62,30 @@ def test_workers(self):
worker.register_worker()
name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
assert len(self.resq.workers()) == 1
- assert name in self.resq.workers()
+ #assert Worker.find(name, self.resq) in self.resq.workers()
def test_enqueue_from_string(self):
self.resq.enqueue_from_string('tests.Basic','basic','test1')
name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
- assert self.redis.llen("queue:basic") == 1
+ assert self.redis.llen("resque:queue:basic") == 1
job = Job.reserve('basic', self.resq)
worker = Worker(['basic'])
worker.process(job)
- assert not self.redis.get('worker:%s' % worker)
- assert not self.redis.get("stat:failed")
- assert not self.redis.get("stat:failed:%s" % name)
+ assert not self.redis.get('resque:worker:%s' % worker)
+ assert not self.redis.get("resque:stat:failed")
+ assert not self.redis.get("resque:stat:failed:%s" % name)
def test_remove_queue(self):
self.resq.enqueue_from_string('tests.Basic','basic','test1')
assert 'basic' in self.resq._watched_queues
- assert self.redis.sismember('queues','basic')
- assert self.redis.llen('queue:basic') == 1
+ assert self.redis.sismember('resque:queues','basic')
+ assert self.redis.llen('resque:queue:basic') == 1
self.resq.remove_queue('basic')
assert 'basic' not in self.resq._watched_queues
- assert not self.redis.sismember('queues','basic')
- assert not self.redis.exists('queue:basic')
+ assert not self.redis.sismember('resque:queues','basic')
+ assert not self.redis.exists('resque:queue:basic')
def test_keys(self):
self.resq.enqueue_from_string('tests.Basic','basic','test1')
- print self.resq.keys()
assert 'queue:basic' in self.resq.keys()
assert 'queues' in self.resq.keys()
View
@@ -4,22 +4,22 @@ class StatTests(PyResTests):
def test_incr(self):
stat_obj = Stat('test_stat', self.resq)
stat_obj.incr()
- assert self.redis.get('stat:test_stat') == 1
+ assert self.redis.get('resque:stat:test_stat') == 1
stat_obj.incr()
- assert self.redis.get('stat:test_stat') == 2
+ assert self.redis.get('resque:stat:test_stat') == 2
stat_obj.incr(2)
- assert self.redis.get('stat:test_stat') == 4
+ assert self.redis.get('resque:stat:test_stat') == 4
def test_decr(self):
stat_obj = Stat('test_stat', self.resq)
stat_obj.incr()
stat_obj.incr()
- assert self.redis.get('stat:test_stat') == 2
+ assert self.redis.get('resque:stat:test_stat') == 2
stat_obj.decr()
- assert self.redis.get('stat:test_stat') == 1
+ assert self.redis.get('resque:stat:test_stat') == 1
stat_obj.incr()
stat_obj.decr(2)
- assert self.redis.get('stat:test_stat') == 0
+ assert self.redis.get('resque:stat:test_stat') == 0
def test_get(self):
stat_obj = Stat('test_stat', self.resq)
@@ -31,6 +31,6 @@ def test_clear(self):
stat_obj = Stat('test_stat', self.resq)
stat_obj.incr()
stat_obj.incr()
- assert self.redis.exists('stat:test_stat')
+ assert self.redis.exists('resque:stat:test_stat')
stat_obj.clear()
- assert not self.redis.exists('stat:test_stat')
+ assert not self.redis.exists('resque:stat:test_stat')
View
@@ -13,7 +13,7 @@ def test_startup(self):
worker = Worker(['basic'])
worker.startup()
name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
- assert self.redis.sismember('workers',name)
+ assert self.redis.sismember('resque:workers',name)
import signal
assert signal.getsignal(signal.SIGTERM) == worker.shutdown_all
assert signal.getsignal(signal.SIGINT) == worker.shutdown_all
@@ -24,62 +24,62 @@ def test_register(self):
worker = Worker(['basic'])
worker.register_worker()
name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
- assert self.redis.sismember('workers',name)
+ assert self.redis.sismember('resque:workers',name)
def test_unregister(self):
worker = Worker(['basic'])
worker.register_worker()
name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
- assert self.redis.sismember('workers',name)
+ assert self.redis.sismember('resque:workers',name)
worker.unregister_worker()
- assert name not in self.redis.smembers('workers')
+ assert name not in self.redis.smembers('resque:workers')
def test_working_on(self):
name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
self.resq.enqueue(Basic,"test1")
job = Job.reserve('basic', self.resq)
worker = Worker(['basic'])
worker.working_on(job)
- assert self.redis.exists("worker:%s" % name)
+ assert self.redis.exists("resque:worker:%s" % name)
def test_processed(self):
name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
worker = Worker(['basic'])
worker.processed()
- assert self.redis.exists("stat:processed")
- assert self.redis.exists("stat:processed:%s" % name)
- assert self.redis.get("stat:processed") == 1
- assert self.redis.get("stat:processed:%s" % name) == 1
+ assert self.redis.exists("resque:stat:processed")
+ assert self.redis.exists("resque:stat:processed:%s" % name)
+ assert self.redis.get("resque:stat:processed") == 1
+ assert self.redis.get("resque:stat:processed:%s" % name) == 1
worker.processed()
- assert self.redis.get("stat:processed") == 2
- assert self.redis.get("stat:processed:%s" % name) == 2
+ assert self.redis.get("resque:stat:processed") == 2
+ assert self.redis.get("resque:stat:processed:%s" % name) == 2
def test_failed(self):
name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
worker = Worker(['basic'])
worker.failed()
- assert self.redis.exists("stat:failed")
- assert self.redis.exists("stat:failed:%s" % name)
- assert self.redis.get("stat:failed") == 1
- assert self.redis.get("stat:failed:%s" % name) == 1
+ assert self.redis.exists("resque:stat:failed")
+ assert self.redis.exists("resque:stat:failed:%s" % name)
+ assert self.redis.get("resque:stat:failed") == 1
+ assert self.redis.get("resque:stat:failed:%s" % name) == 1
worker.failed()
- assert self.redis.get("stat:failed") == 2
- assert self.redis.get("stat:failed:%s" % name) == 2
+ assert self.redis.get("resque:stat:failed") == 2
+ assert self.redis.get("resque:stat:failed:%s" % name) == 2
def test_process(self):
name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
self.resq.enqueue(Basic,"test1")
job = Job.reserve('basic', self.resq)
worker = Worker(['basic'])
worker.process(job)
- assert not self.redis.get('worker:%s' % worker)
- assert not self.redis.get("stat:failed")
- assert not self.redis.get("stat:failed:%s" % name)
+ assert not self.redis.get('resque:worker:%s' % worker)
+ assert not self.redis.get("resque:stat:failed")
+ assert not self.redis.get("resque:stat:failed:%s" % name)
self.resq.enqueue(Basic,"test1")
worker.process()
- assert not self.redis.get('worker:%s' % worker)
- assert not self.redis.get("stat:failed")
- assert not self.redis.get("stat:failed:%s" % name)
+ assert not self.redis.get('resque:worker:%s' % worker)
+ assert not self.redis.get("resque:stat:failed")
+ assert not self.redis.get("resque:stat:failed:%s" % name)
def test_signals(self):
@@ -101,17 +101,17 @@ def test_job_failure(self):
worker = Worker(['basic'])
worker.process()
name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
- assert not self.redis.get('worker:%s' % worker)
- assert self.redis.get("stat:failed") == 1
- assert self.redis.get("stat:failed:%s" % name) == 1
+ assert not self.redis.get('resque:worker:%s' % worker)
+ assert self.redis.get("resque:stat:failed") == 1
+ assert self.redis.get("resque:stat:failed:%s" % name) == 1
def test_get_job(self):
worker = Worker(['basic'])
self.resq.enqueue(Basic,"test1")
job = Job.reserve('basic', self.resq)
worker.working_on(job)
name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
- assert worker.job() == ResQ.decode(self.redis.get('worker:%s' % name))
+ assert worker.job() == ResQ.decode(self.redis.get('resque:worker:%s' % name))
worker.done_working()
w2 = Worker(['basic'])
print w2.job()
@@ -135,7 +135,7 @@ def test_started(self):
dt = datetime.datetime.now()
worker.started = dt
name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
- assert self.redis.get('worker:%s:started' % name) == dt.strftime('%Y-%m-%d %H:%M:%S')
+ assert self.redis.get('resque:worker:%s:started' % name) == dt.strftime('%Y-%m-%d %H:%M:%S')
assert worker.started == datetime.datetime.strptime(dt.strftime('%Y-%m-%d %H:%M:%S'),'%Y-%m-%d %H:%M:%S')
worker.started = None
- assert not self.redis.exists('worker:%s:started' % name)
+ assert not self.redis.exists('resque:worker:%s:started' % name)

0 comments on commit 64ff2bb

Please sign in to comment.