Skip to content

Commit

Permalink
Fix queue serialization test on PyPy
Browse files Browse the repository at this point in the history
It is not affected by Twisted bug #7989 and is more permissive
with pickling (especially with protocol=2).
  • Loading branch information
lopuhin committed Jun 15, 2017
1 parent 6014856 commit c3d1765
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions tests/test_squeues.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -30,11 +48,7 @@ def test_serialize(self):
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
Expand Down Expand Up @@ -110,11 +124,7 @@ def test_serialize(self):
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):
Expand Down

0 comments on commit c3d1765

Please sign in to comment.