Permalink
Browse files

rename

  • Loading branch information...
1 parent 00bd711 commit 153ba602659aa708eeedc7ede23958e6ad08b55b @sublee committed Apr 4, 2013
Showing with 29 additions and 15 deletions.
  1. +15 −11 zeronimo/core.py
  2. +14 −4 zeronimotests.py
View
@@ -275,18 +275,22 @@ class Tunnel(object):
:type return_task: bool
"""
- def __init__(self, customer, workers, task=False, fanout=False, wait=True):
+ def __init__(self, customer, workers,
+ wait=True, fanout=False, as_task=False):
self._znm_customer = customer
self._znm_workers = workers
self._znm_sockets = {}
# options
- self._znm_task = task
- self._znm_fanout = fanout
self._znm_wait = wait
+ self._znm_fanout = fanout
+ self._znm_as_task = as_task
#self._znm_verify_workers(workers)
#self._znm_blueprint = workers[0].blueprint
#self._znm_reflect(self._znm_blueprint)
+ def _znm_is_alive(self):
+ return self in self._znm_customer.tunnels
+
def _znm_verify_workers(self, workers):
worker = workers[0]
for other_worker in workers[1:]:
@@ -315,17 +319,17 @@ def _znm_invoke(self, fn, *args, **kwargs):
spawn(self._znm_customer.run)
return task.collect()
- def __call__(self, task=None, fanout=None, wait=None):
+ def __call__(self, wait=None, fanout=None, as_task=None):
"""Creates a :class:`Tunnel` object which follows same consumer and
workers but replaced options.
"""
- if task is None:
- task = self._znm_task
- if fanout is None:
- fanout = self._znm_fanout
if wait is None:
wait = self._znm_wait
- opts = (task, fanout, wait)
+ if fanout is None:
+ fanout = self._znm_fanout
+ if as_task is None:
+ as_task = self._znm_as_task
+ opts = (wait, fanout, as_task)
tunnel = Tunnel(self._znm_customer, self._znm_workers, *opts)
tunnel._znm_sockets = self._znm_sockets
return tunnel
@@ -379,14 +383,14 @@ def collect(self, timeout=0.01):
each_task.worker_addr = worker_addr
tasks.append(each_task)
self.customer.register_task(each_task)
- return tasks if self.tunnel._znm_task else (t() for t in tasks)
+ return tasks if self.tunnel._znm_as_task else [t() for t in tasks]
else:
do, val = msgs[0]
assert len(msgs) == 1
assert do == ACK
self.worker_addr, self.run_id = val
self.customer.register_task(self)
- return self if self.tunnel._znm_task else self()
+ return self if self.tunnel._znm_as_task else self()
def put(self, do, val):
print 'task(%s:%s) recv %s %r' % \
View
@@ -103,7 +103,7 @@ def dont_yield(self):
assert 0
@zeronimo.register
- def divide_by_zero(self):
+ def zero_div(self):
0/0 /0/0 /0/0 /0/0 /0/0/0/0 /0/0
0/0 /0 /0/0 /0/0 /0/0 /0/0 /0/0 /0
0/0/0/0/0/0/0 /0/0/0/0/0/0 /0/0 /0/0 /0
@@ -259,7 +259,7 @@ def test_raise(customer, worker):
start_workers([worker])
with customer.link([worker]) as tunnel:
with pytest.raises(ZeroDivisionError):
- tunnel.divide_by_zero()
+ tunnel.zero_div()
rocket_launching = tunnel.launch_rocket()
assert rocket_launching.next() == 3
assert rocket_launching.next() == 2
@@ -275,7 +275,7 @@ def test(tunnel):
assert tunnel.add(1, 1) == 'cutie'
assert len(list(tunnel.jabberwocky())) == 4
with pytest.raises(ZeroDivisionError):
- tunnel.divide_by_zero()
+ tunnel.zero_div()
with customer1.link([worker]) as tunnel1, \
customer2.link([worker]) as tunnel2:
joinall([spawn(test, tunnel1), spawn(test, tunnel2)])
@@ -284,7 +284,7 @@ def test(tunnel):
@green
def test_1to2(customer, worker1, worker2):
start_workers([worker1, worker2])
- with customer.link([worker1, worker2], task=True) as tunnel:
+ with customer.link([worker1, worker2], as_task=True) as tunnel:
task1 = tunnel.add(1, 1)
task2 = tunnel.add(2, 2)
assert task1() == 'cutie'
@@ -296,13 +296,23 @@ def test_1to2(customer, worker1, worker2):
def test_fanout(customer, worker1, worker2):
start_workers([worker1, worker2])
with customer.link([worker1, worker2]) as tunnel:
+ assert list(tunnel.rycbar123()) == \
+ 'run, you clever boy; and remember.'.split()
for rycbar123 in tunnel(fanout=True).rycbar123():
assert rycbar123.next() == 'run,'
assert rycbar123.next() == 'you'
assert rycbar123.next() == 'clever'
assert rycbar123.next() == 'boy;'
assert rycbar123.next() == 'and'
assert rycbar123.next() == 'remember.'
+ with pytest.raises(ZeroDivisionError):
+ tunnel(fanout=True).zero_div()
+ failures = tunnel(as_task=True, fanout=True).zero_div()
+ assert len(failures) == 2
+ with pytest.raises(ZeroDivisionError):
+ failures[0]()
+ with pytest.raises(ZeroDivisionError):
+ failures[1]()
@green

0 comments on commit 153ba60

Please sign in to comment.