mirror of https://github.com/scrapy/scrapy.git
Fix queue serialization test on PyPy
It is not affected by Twisted bug #7989 and is more permissive with pickling (especially with protocol=2).
This commit is contained in:
parent
6014856df5
commit
c3d17659b3
|
|
@ -1,3 +1,5 @@
|
|||
import pickle
|
||||
|
||||
from queuelib.tests import test_queue as t
|
||||
from scrapy.squeues import MarshalFifoDiskQueue, MarshalLifoDiskQueue, PickleFifoDiskQueue, PickleLifoDiskQueue
|
||||
from scrapy.item import Item, Field
|
||||
|
|
@ -14,6 +16,22 @@ class TestLoader(ItemLoader):
|
|||
default_item_class = TestItem
|
||||
name_out = staticmethod(_test_procesor)
|
||||
|
||||
def nonserializable_object_test(self):
|
||||
try:
|
||||
pickle.dumps(lambda x: x)
|
||||
except Exception:
|
||||
# Trigger Twisted bug #7989
|
||||
import twisted.persisted.styles # NOQA
|
||||
q = self.queue()
|
||||
self.assertRaises(ValueError, q.push, lambda x: x)
|
||||
else:
|
||||
# Use a different unpickleable object
|
||||
class A(object): pass
|
||||
a = A()
|
||||
a.__reduce__ = a.__reduce_ex__ = None
|
||||
q = self.queue()
|
||||
self.assertRaises(ValueError, q.push, a)
|
||||
|
||||
class MarshalFifoDiskQueueTest(t.FifoDiskQueueTest):
|
||||
|
||||
chunksize = 100000
|
||||
|
|
@ -30,11 +48,7 @@ class MarshalFifoDiskQueueTest(t.FifoDiskQueueTest):
|
|||
self.assertEqual(q.pop(), 123)
|
||||
self.assertEqual(q.pop(), {'a': 'dict'})
|
||||
|
||||
def test_nonserializable_object(self):
|
||||
# Trigger Twisted bug #7989
|
||||
import twisted.persisted.styles # NOQA
|
||||
q = self.queue()
|
||||
self.assertRaises(ValueError, q.push, lambda x: x)
|
||||
test_nonserializable_object = nonserializable_object_test
|
||||
|
||||
class ChunkSize1MarshalFifoDiskQueueTest(MarshalFifoDiskQueueTest):
|
||||
chunksize = 1
|
||||
|
|
@ -110,11 +124,7 @@ class MarshalLifoDiskQueueTest(t.LifoDiskQueueTest):
|
|||
self.assertEqual(q.pop(), 123)
|
||||
self.assertEqual(q.pop(), 'a')
|
||||
|
||||
def test_nonserializable_object(self):
|
||||
# Trigger Twisted bug #7989
|
||||
import twisted.persisted.styles # NOQA
|
||||
q = self.queue()
|
||||
self.assertRaises(ValueError, q.push, lambda x: x)
|
||||
test_nonserializable_object = nonserializable_object_test
|
||||
|
||||
|
||||
class PickleLifoDiskQueueTest(MarshalLifoDiskQueueTest):
|
||||
|
|
|
|||
Loading…
Reference in New Issue