[py-svn] r10850 - in py/dist/py/execnet: . testing
hpk at codespeak.net
hpk at codespeak.net
Tue Apr 19 14:13:44 CEST 2005
Author: hpk
Date: Tue Apr 19 14:13:44 2005
New Revision: 10850
Modified:
py/dist/py/execnet/channel.py
py/dist/py/execnet/gateway.py
py/dist/py/execnet/message.py
py/dist/py/execnet/testing/test_gateway.py
Log:
- move RemoteError to channel object.
- test makefile()
Modified: py/dist/py/execnet/channel.py
==============================================================================
--- py/dist/py/execnet/channel.py (original)
+++ py/dist/py/execnet/channel.py Tue Apr 19 14:13:44 2005
@@ -3,9 +3,22 @@
if 'Message' not in globals():
from py.__impl__.execnet.message import Message
+class RemoteError(EOFError):
+ """ Contains an Exceptions from the other side. """
+ def __init__(self, formatted):
+ self.formatted = formatted
+ EOFError.__init__(self)
+
+ def __str__(self):
+ return self.formatted
+
+ def __repr__(self):
+ return "%s: %s" %(self.__class__.__name__, self.formatted)
+
class Channel(object):
"""Communication channel between two possibly remote threads of code. """
_callback = None
+ RemoteError = RemoteError
def __init__(self, gateway, id):
assert isinstance(id, int)
self.gateway = gateway
@@ -64,13 +77,13 @@
"""
return self._closeevent.isSet()
- def makefile(self, mode='w', proxyclose=True):
+ def makefile(self, mode='w', proxyclose=False):
""" return a file-like object. Only supported mode right
- now is 'w' for binary writes. By default, closing
- the file will close the channel. Pass proxyclose=False
- if you want to ignore file.close()s.
+ now is 'w' for binary writes. If you want to have
+ a subsequent file.close() mean to close the channel
+ as well, then pass proxyclose=True.
"""
- assert mode == 'w'
+ assert mode == 'w', "mode %r not availabe" %(mode,)
return ChannelFile(channel=self, proxyclose=proxyclose)
def close(self, error=None):
@@ -95,13 +108,13 @@
""" wait until this channel is closed. Note that a closed
channel may still hold items that can be received or
send. Also note that exceptions from the other side will be
- reraised as gateway.RemoteError exceptions containing
+ reraised as channel.RemoteError exceptions containing
a textual representation of the remote traceback.
"""
self._closeevent.wait(timeout=timeout)
if not self._closeevent.isSet():
raise IOError, "Timeout"
- if isinstance(self._finalitem, self.gateway.RemoteError):
+ if isinstance(self._finalitem, self.RemoteError):
raise self._finalitem
def send(self, item):
@@ -119,7 +132,7 @@
"""receives an item that was sent from the other side,
possibly blocking if there is none.
Note that exceptions from the other side will be
- reraised as gateway.RemoteError exceptions containing
+ reraised as channel.RemoteError exceptions containing
a textual representation of the remote traceback.
"""
if self._callback:
Modified: py/dist/py/execnet/gateway.py
==============================================================================
--- py/dist/py/execnet/gateway.py (original)
+++ py/dist/py/execnet/gateway.py Tue Apr 19 14:13:44 2005
@@ -23,21 +23,8 @@
sysex = (KeyboardInterrupt, SystemExit)
-class RemoteError(EOFError):
- """ Contains an Exceptions from the other side. """
- def __init__(self, formatted):
- self.formatted = formatted
- EOFError.__init__(self)
-
- def __str__(self):
- return self.formatted
-
- def __repr__(self):
- return "%s: %s" %(self.__class__.__name__, self.formatted)
-
class Gateway(object):
num_worker_threads = 2
- RemoteError = RemoteError
ThreadOut = ThreadOut
def __init__(self, io, startcount=2, maxthreads=None):
Modified: py/dist/py/execnet/message.py
==============================================================================
--- py/dist/py/execnet/message.py (original)
+++ py/dist/py/execnet/message.py Tue Apr 19 14:13:44 2005
@@ -113,7 +113,7 @@
class CHANNEL_CLOSE_ERROR(Message):
def received(self, gateway):
channel = gateway.channelfactory[self.channelid]
- channel._do_close(gateway.RemoteError(self.data))
+ channel._do_close(channel.RemoteError(self.data))
classes = [x for x in locals().values() if hasattr(x, '__bases__')]
classes.sort(lambda x,y : cmp(x.__name__, y.__name__))
Modified: py/dist/py/execnet/testing/test_gateway.py
==============================================================================
--- py/dist/py/execnet/testing/test_gateway.py (original)
+++ py/dist/py/execnet/testing/test_gateway.py Tue Apr 19 14:13:44 2005
@@ -95,7 +95,7 @@
def test_channel_close_and_then_receive_error(self):
channel = self.gw.remote_exec('raise ValueError')
- py.test.raises(gateway.RemoteError, channel.receive)
+ py.test.raises(channel.RemoteError, channel.receive)
def test_channel_finish_and_then_EOFError(self):
channel = self.gw.remote_exec('channel.send(42)')
@@ -109,7 +109,7 @@
channel = self.gw.remote_exec('channel.send(42) ; raise ValueError')
x = channel.receive()
assert x == 42
- py.test.raises(gateway.RemoteError, channel.receive)
+ py.test.raises(channel.RemoteError, channel.receive)
def test_channel__do_close(self):
channel = self.gw.channelfactory.new()
@@ -118,8 +118,8 @@
def test_channel__do_close_error(self):
channel = self.gw.channelfactory.new()
- channel._do_close(gateway.RemoteError("error"))
- py.test.raises(gateway.RemoteError, channel.waitclose, 0.01)
+ channel._do_close(channel.RemoteError("error"))
+ py.test.raises(channel.RemoteError, channel.waitclose, 0.01)
def test_channel_iter(self):
channel = self.gw.remote_exec("""
@@ -206,16 +206,28 @@
s = subl[0]
assert s.strip() == str(i)
- def future_test_channel_file(self):
- self.gw.remote_exec("""
+ def test_channel_file(self):
+ channel = self.gw.remote_exec("""
f = channel.makefile()
print >>f, "hello world"
f.close()
channel.send(42)
""")
- for x in channel.receive():
- print x
- assert 0
+ first = channel.receive() + channel.receive()
+ assert first.strip() == 'hello world'
+ second = channel.receive()
+ assert second == 42
+
+ def test_channel_file_proxyclose(self):
+ channel = self.gw.remote_exec("""
+ f = channel.makefile(proxyclose=True)
+ print >>f, "hello world"
+ f.close()
+ channel.send(42)
+ """)
+ first = channel.receive() + channel.receive()
+ assert first.strip() == 'hello world'
+ py.test.raises(EOFError, channel.receive)
class TestBasicPopenGateway(PopenGatewayTestSetup, BasicRemoteExecution):
#disabled = True
More information about the pytest-commit
mailing list