[py-svn] r56964 - in py/branch/event/py/execnet: . testing
hpk at codespeak.net
hpk at codespeak.net
Mon Aug 4 12:56:48 CEST 2008
Author: hpk
Date: Mon Aug 4 12:56:48 2008
New Revision: 56964
Modified:
py/branch/event/py/execnet/channel.py
py/branch/event/py/execnet/testing/test_gateway.py
Log:
also raise ValueError if a non-picklable item is sent over a pickle channel
Modified: py/branch/event/py/execnet/channel.py
==============================================================================
--- py/branch/event/py/execnet/channel.py (original)
+++ py/branch/event/py/execnet/channel.py Mon Aug 4 12:56:48 2008
@@ -1,6 +1,6 @@
import threading, weakref, sys
import Queue
-from cPickle import Pickler, Unpickler
+from cPickle import Pickler, Unpickler, PickleError
import marshal
if 'Message' not in globals():
@@ -170,7 +170,10 @@
f = StringIO()
pickler = Pickler(f, protocol=-1) # use best protocol
pickler.memo = self._picklememo
- pickler.dump(item)
+ try:
+ pickler.dump(item)
+ except PickleError, e:
+ raise ValueError(str(e))
item = f.getvalue()
else:
if not isinstance(item, str):
Modified: py/branch/event/py/execnet/testing/test_gateway.py
==============================================================================
--- py/branch/event/py/execnet/testing/test_gateway.py (original)
+++ py/branch/event/py/execnet/testing/test_gateway.py Mon Aug 4 12:56:48 2008
@@ -78,13 +78,13 @@
channel = self.fac.new()
py.test2.raises(ValueError, 'channel.makefile("rw")')
- def test_channel_send_with_pickle_false(self):
+ def test_channel_send_errors_nopickling(self):
channel = self.fac.new(pickle=False)
class A:
pass
- py.test.raises(ValueError, "channel.send(A)")
py.test.raises(ValueError, "channel.send(A())")
+
class PopenGatewayTestSetup:
def setup_class(cls):
cls.gw = py.execnet.PopenGateway()
@@ -388,6 +388,12 @@
s = f.readline()
assert s == "45"
+ def test_channel_send_errors_pickling(self):
+ channel = self.gw.remote_exec("", _pickle=True)
+ channel.send(object()) # works here
+ class A: pass
+ py.test.raises(ValueError, "channel.send(A)")
+
def test_pickling(self):
channel = self.gw.remote_exec("""
l1 = channel.receive()
More information about the pytest-commit
mailing list