tested django-newsletter

This commit is contained in:
Esther Kleinhenz
2018-10-26 15:21:17 +02:00
parent 7ed667d043
commit 811b7c5453
2352 changed files with 448169 additions and 1 deletions
@@ -0,0 +1,11 @@
import sys
if sys.version_info[0] < 3:
class binary(bytes):
"""Mark a given string as explicitly binary
I.e., it should be unpickled as bytes on Py3k, rather than being
forcibly promoted to unicode.
"""
else:
binary = bytes
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,32 @@
import sys
'''
The zodbpickle.pickle module exposes the standard behavior of
the pickle module.
This is backward compatible, but has the effect that by default,
on Python3 you get the fast implementation, while on Python2
you get the slow implementation.
This module is a version that always exposes the fast implementation
of pickling and avoids the need to explicitly touch internals.
'''
'''
Note: We are intentionally using "import *" in this context.
The imported modules define an __all__ variable, which contains
all the names that it wants to export.
So this is a rare case where 'import *' is exactly the right thing to do.
'''
# pick up all names that the module defines
if sys.version_info[0] >= 3:
from .pickle_3 import *
# do not share the globals with a slow version
del sys.modules['zodbpickle.pickle_3']
else:
from .pickle_2 import *
# also make sure that we really have the fast version, although
# python3 tries to import them by default
from ._pickle import *
del sys
@@ -0,0 +1,7 @@
import sys
if sys.version_info[0] >= 3:
from .pickle_3 import *
else:
from .pickle_2 import *
del sys
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,35 @@
import sys
'''
The zodbpickle.pickle module exposes the standard behavior of
the pickle module.
This is backward compatible, but has the effect that by default,
on Python3 you get the fast implementation, while on Python2
you get the slow implementation.
This module is a version that always exposes the slow implementation
of pickling and avoids the need to explicitly touch internals.
'''
'''
Note: We are intentionally using "import *" in this context.
The imported modules define an __all__ variable, which contains
all the names that it wants to export.
So this is a rare case where 'import *' is exactly the right thing to do.
'''
if sys.version_info[0] >= 3:
import zodbpickle.pickle_3 as p
# undo the replacement with fast versions
p.Pickler, p.Unpickler = p._Pickler, p._Pickler
p.dump, p.dumps, p.load, p.loads = p._dump, p._dumps, p._load, p._loads
del p
# pick up all names that the module defines
from .pickle_3 import *
# do not share the globals with a fast version
del sys.modules['zodbpickle.pickle_3']
else:
# pick up all names that the module defines
from .pickle_2 import *
del sys
@@ -0,0 +1,7 @@
import os
import platform
py_impl = getattr(platform, 'python_implementation', lambda: None)
_is_pypy = py_impl() == 'PyPy'
_is_jython = py_impl() == 'Jython'
_is_pure = 'PURE_PYTHON' in os.environ
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,33 @@
import unittest
class TestImportability(unittest.TestCase):
def test_Pickler(self):
from zodbpickle.pickle import Pickler
def test_Unpickler(self):
from zodbpickle.pickle import Unpickler
def test_load(self):
from zodbpickle.pickle import load
def test_loads(self):
from zodbpickle.pickle import load
def test_dump(self):
from zodbpickle.pickle import dumps
def test_dumps(self):
from zodbpickle.pickle import dumps
def test_suite():
import sys
if sys.version_info[0] >= 3:
from .test_pickle_3 import test_suite
else:
from .test_pickle_2 import test_suite
return unittest.TestSuite((
test_suite(),
unittest.makeSuite(TestImportability),
))
@@ -0,0 +1,371 @@
import cStringIO
import io
import unittest
from cStringIO import StringIO
from .pickletester_2 import (AbstractPickleTests,
AbstractPickleModuleTests,
AbstractPersistentPicklerTests,
AbstractPicklerUnpicklerObjectTests,
BigmemPickleTests,
has_c_implementation)
from test import test_support
class cStringIOMixin:
output = input = cStringIO.StringIO
def close(self, f):
pass
class BytesIOMixin:
output = input = io.BytesIO
def close(self, f):
pass
class FileIOMixin:
def output(self):
return open(test_support.TESTFN, 'wb+')
def input(self, data):
f = open(test_support.TESTFN, 'wb+')
try:
f.write(data)
f.seek(0)
return f
except:
f.close()
raise
def close(self, f):
f.close()
test_support.unlink(test_support.TESTFN)
class PickleTests(AbstractPickleTests, AbstractPickleModuleTests):
def dumps(self, arg, proto=0, fast=0):
from zodbpickle.pickle_2 import dumps
# Ignore fast
return dumps(arg, proto)
def loads(self, buf):
from zodbpickle.pickle_2 import loads
# Ignore fast
return loads(buf)
@property
def module(self):
from zodbpickle import pickle_2
return pickle_2
error = KeyError
class PicklerTests(AbstractPickleTests):
error = KeyError
def dumps(self, arg, proto=0, fast=0):
from zodbpickle.pickle_2 import Pickler
f = cStringIO.StringIO()
p = Pickler(f, proto)
if fast:
p.fast = fast
p.dump(arg)
f.seek(0)
return f.read()
def loads(self, buf):
from zodbpickle.pickle_2 import Unpickler
f = cStringIO.StringIO(buf)
u = Unpickler(f)
return u.load()
class PersPicklerTests(AbstractPersistentPicklerTests):
def dumps(self, arg, proto=0, fast=0):
from zodbpickle.pickle_2 import Pickler
class PersPickler(Pickler):
def persistent_id(subself, obj):
return self.persistent_id(obj)
f = cStringIO.StringIO()
p = PersPickler(f, proto)
if fast:
p.fast = fast
p.dump(arg)
f.seek(0)
return f.read()
def loads(self, buf):
from zodbpickle.pickle_2 import Unpickler
class PersUnpickler(Unpickler):
def persistent_load(subself, obj):
return self.persistent_load(obj)
f = cStringIO.StringIO(buf)
u = PersUnpickler(f)
return u.load()
class PicklerUnpicklerObjectTests(AbstractPicklerUnpicklerObjectTests):
@property
def pickler_class(self):
from zodbpickle.pickle_2 import Pickler
return Pickler
@property
def unpickler_class(self):
from zodbpickle.pickle_2 import Unpickler
return Unpickler
class PickleBigmemPickleTests(BigmemPickleTests):
def dumps(self, arg, proto=0, fast=0):
from zodbpickle import pickle_2
# Ignore fast
return pickle_2.dumps(arg, proto)
def loads(self, buf):
from zodbpickle import pickle_2
# Ignore fast
return pickle_2.loads(buf)
class cPickleBase(object):
@property
def error(self):
from zodbpickle._pickle import BadPickleGet
return BadPickleGet
class cPickleTests(AbstractPickleTests,
AbstractPickleModuleTests,
cPickleBase,
):
def setUp(self):
from zodbpickle._pickle import dumps
from zodbpickle._pickle import loads
self.dumps = dumps
self.loads = loads
@property
def module(self):
from zodbpickle import _pickle
return _pickle
class cPicklePicklerTests(AbstractPickleTests, cPickleBase):
def dumps(self, arg, proto=0):
from zodbpickle import _pickle
f = self.output()
try:
p = _pickle.Pickler(f, proto)
p.dump(arg)
f.seek(0)
return f.read()
finally:
self.close(f)
def loads(self, buf):
from zodbpickle import _pickle
f = self.input(buf)
try:
p = _pickle.Unpickler(f)
return p.load()
finally:
self.close(f)
class cStringIOCPicklerTests(cStringIOMixin, cPicklePicklerTests):
pass
class BytesIOCPicklerTests(BytesIOMixin, cPicklePicklerTests):
pass
class FileIOCPicklerTests(FileIOMixin, cPicklePicklerTests):
pass
class cPickleListPicklerTests(AbstractPickleTests, cPickleBase):
def dumps(self, arg, proto=0):
from zodbpickle import _pickle
p = _pickle.Pickler(proto)
p.dump(arg)
return p.getvalue()
def loads(self, *args):
from zodbpickle import _pickle
f = self.input(args[0])
try:
p = _pickle.Unpickler(f)
return p.load()
finally:
self.close(f)
class cStringIOCPicklerListTests(cStringIOMixin, cPickleListPicklerTests):
pass
class BytesIOCPicklerListTests(BytesIOMixin, cPickleListPicklerTests):
pass
class FileIOCPicklerListTests(FileIOMixin, cPickleListPicklerTests):
pass
class cPickleFastPicklerTests(AbstractPickleTests, cPickleBase):
def dumps(self, arg, proto=0):
from zodbpickle import _pickle
f = self.output()
try:
p = _pickle.Pickler(f, proto)
p.fast = 1
p.dump(arg)
f.seek(0)
return f.read()
finally:
self.close(f)
def loads(self, *args):
from zodbpickle import _pickle
f = self.input(args[0])
try:
p = _pickle.Unpickler(f)
return p.load()
finally:
self.close(f)
def test_recursive_list(self):
self.assertRaises(ValueError,
AbstractPickleTests.test_recursive_list,
self)
def test_recursive_tuple(self):
self.assertRaises(ValueError,
AbstractPickleTests.test_recursive_tuple,
self)
def test_recursive_inst(self):
self.assertRaises(ValueError,
AbstractPickleTests.test_recursive_inst,
self)
def test_recursive_dict(self):
self.assertRaises(ValueError,
AbstractPickleTests.test_recursive_dict,
self)
def test_recursive_multi(self):
self.assertRaises(ValueError,
AbstractPickleTests.test_recursive_multi,
self)
def test_nonrecursive_deep(self):
# If it's not cyclic, it should pickle OK even if the nesting
# depth exceeds PY_CPICKLE_FAST_LIMIT. That happens to be
# 50 today. Jack Jansen reported stack overflow on Mac OS 9
# at 64.
a = []
for i in range(60):
a = [a]
b = self.loads(self.dumps(a))
self.assertEqual(a, b)
class cStringIOCPicklerFastTests(cStringIOMixin, cPickleFastPicklerTests):
pass
class BytesIOCPicklerFastTests(BytesIOMixin, cPickleFastPicklerTests):
pass
class FileIOCPicklerFastTests(FileIOMixin, cPickleFastPicklerTests):
pass
class cPicklePicklerUnpicklerObjectTests(AbstractPicklerUnpicklerObjectTests):
@property
def pickler_class(self):
from zodbpickle._pickle import Pickler
return Pickler
@property
def unpickler_class(self):
from zodbpickle._pickle import Unpickler
return Unpickler
class cPickleBigmemPickleTests(BigmemPickleTests):
def dumps(self, arg, proto=0, fast=0):
from zodbpickle import _pickle
# Ignore fast
return _pickle.dumps(arg, proto)
def loads(self, buf):
from zodbpickle import _pickle
# Ignore fast
return _pickle.loads(buf)
class Node(object):
pass
class cPickleDeepRecursive(unittest.TestCase):
def test_issue2702(self):
# This should raise a RecursionLimit but in some
# platforms (FreeBSD, win32) sometimes raises KeyError instead,
# or just silently terminates the interpreter (=crashes).
from zodbpickle import _pickle
nodes = [Node() for i in range(500)]
for n in nodes:
n.connections = list(nodes)
n.connections.remove(n)
self.assertRaises((AttributeError, RuntimeError), _pickle.dumps, n)
def test_issue3179(self):
# Safe test, because I broke this case when fixing the
# behaviour for the previous test.
from zodbpickle import _pickle
res=[]
for x in range(1,2000):
res.append(dict(doc=x, similar=[]))
_pickle.dumps(res)
def test_suite():
import unittest
tests = [
unittest.makeSuite(PickleTests),
unittest.makeSuite(PicklerTests),
unittest.makeSuite(PersPicklerTests),
unittest.makeSuite(PicklerUnpicklerObjectTests),
unittest.makeSuite(PickleBigmemPickleTests),
]
if has_c_implementation:
tests.extend([
unittest.makeSuite(cPickleTests),
unittest.makeSuite(cStringIOCPicklerTests),
unittest.makeSuite(BytesIOCPicklerTests),
unittest.makeSuite(FileIOCPicklerTests),
unittest.makeSuite(cStringIOCPicklerListTests),
unittest.makeSuite(BytesIOCPicklerListTests),
unittest.makeSuite(FileIOCPicklerListTests),
unittest.makeSuite(cStringIOCPicklerFastTests),
unittest.makeSuite(BytesIOCPicklerFastTests),
unittest.makeSuite(FileIOCPicklerFastTests),
unittest.makeSuite(cPickleDeepRecursive),
unittest.makeSuite(cPicklePicklerUnpicklerObjectTests),
unittest.makeSuite(cPickleBigmemPickleTests),
])
return unittest.TestSuite(tests)
if __name__ == '__main__':
test_support.run_unittest(test_suite())
@@ -0,0 +1,190 @@
import io
import collections
import unittest
import doctest
from test import support as test_support
from .pickletester_3 import AbstractPickleTests
from .pickletester_3 import AbstractPickleModuleTests
from .pickletester_3 import AbstractPersistentPicklerTests
from .pickletester_3 import AbstractPicklerUnpicklerObjectTests
from .pickletester_3 import AbstractDispatchTableTests
from .pickletester_3 import BigmemPickleTests
from .pickletester_3 import AbstractBytestrTests
from .pickletester_3 import AbstractBytesFallbackTests
from . import _is_pypy
from . import _is_pure
from zodbpickle import pickle_3 as pickle
try:
from zodbpickle import _pickle
has_c_implementation = not _is_pypy and not _is_pure
except ImportError:
has_c_implementation = False
class PickleTests(AbstractPickleModuleTests):
pass
class PyPicklerBase(object):
pickler = pickle._Pickler
unpickler = pickle._Unpickler
def dumps(self, arg, proto=None, **kwds):
f = io.BytesIO()
p = self.pickler(f, proto, **kwds)
p.dump(arg)
f.seek(0)
return bytes(f.read())
def loads(self, buf, **kwds):
f = io.BytesIO(buf)
u = self.unpickler(f, **kwds)
return u.load()
class PyPicklerTests(PyPicklerBase, AbstractPickleTests):
pass
class PyPicklerBytestrTests(PyPicklerBase, AbstractBytestrTests):
pass
class PyPicklerBytesFallbackTests(PyPicklerBase, AbstractBytesFallbackTests):
pass
class InMemoryPickleTests(AbstractPickleTests, BigmemPickleTests):
pickler = pickle._Pickler
unpickler = pickle._Unpickler
def dumps(self, arg, protocol=None):
return pickle.dumps(arg, protocol)
def loads(self, buf, **kwds):
return pickle.loads(buf, **kwds)
class PyPersPicklerTests(AbstractPersistentPicklerTests):
pickler = pickle._Pickler
unpickler = pickle._Unpickler
def dumps(self, arg, proto=None):
class PersPickler(self.pickler):
def persistent_id(subself, obj):
return self.persistent_id(obj)
f = io.BytesIO()
p = PersPickler(f, proto)
p.dump(arg)
f.seek(0)
return f.read()
def loads(self, buf, **kwds):
class PersUnpickler(self.unpickler):
def persistent_load(subself, obj):
return self.persistent_load(obj)
f = io.BytesIO(buf)
u = PersUnpickler(f, **kwds)
return u.load()
class PyPicklerUnpicklerObjectTests(AbstractPicklerUnpicklerObjectTests):
pickler_class = pickle._Pickler
unpickler_class = pickle._Unpickler
class PyDispatchTableTests(AbstractDispatchTableTests):
pickler_class = pickle._Pickler
def get_dispatch_table(self):
return pickle.dispatch_table.copy()
class PyChainDispatchTableTests(AbstractDispatchTableTests):
pickler_class = pickle._Pickler
def get_dispatch_table(self):
return collections.ChainMap({}, pickle.dispatch_table)
if has_c_implementation:
class CPicklerTests(PyPicklerTests):
pickler = _pickle.Pickler
unpickler = _pickle.Unpickler
class CPicklerBytestrTests(PyPicklerBytestrTests):
pickler = _pickle.Pickler
unpickler = _pickle.Unpickler
class CPicklerBytesFallbackTests(PyPicklerBytesFallbackTests):
pickler = _pickle.Pickler
unpickler = _pickle.Unpickler
class CPersPicklerTests(PyPersPicklerTests):
pickler = _pickle.Pickler
unpickler = _pickle.Unpickler
class CDumpPickle_LoadPickle(PyPicklerTests):
pickler = _pickle.Pickler
unpickler = pickle._Unpickler
class DumpPickle_CLoadPickle(PyPicklerTests):
pickler = pickle._Pickler
unpickler = _pickle.Unpickler
class CPicklerUnpicklerObjectTests(AbstractPicklerUnpicklerObjectTests):
pickler_class = _pickle.Pickler
unpickler_class = _pickle.Unpickler
class CDispatchTableTests(AbstractDispatchTableTests):
pickler_class = pickle.Pickler
def get_dispatch_table(self):
return pickle.dispatch_table.copy()
class CChainDispatchTableTests(AbstractDispatchTableTests):
pickler_class = pickle.Pickler
def get_dispatch_table(self):
return collections.ChainMap({}, pickle.dispatch_table)
def choose_tests():
tests = [
PickleTests,
PyPicklerTests,
PyPersPicklerTests,
PyPicklerBytestrTests,
PyPicklerBytesFallbackTests,
PyDispatchTableTests,
PyChainDispatchTableTests,
]
if has_c_implementation:
tests.extend([
CPicklerTests,
CPersPicklerTests,
CPicklerBytestrTests,
CPicklerBytesFallbackTests,
CDumpPickle_LoadPickle,
DumpPickle_CLoadPickle,
PyPicklerUnpicklerObjectTests,
CPicklerUnpicklerObjectTests,
InMemoryPickleTests,
CDispatchTableTests,
CChainDispatchTableTests,
])
return tests
def test_suite():
return unittest.TestSuite([
unittest.makeSuite(t) for t in choose_tests()
] + [
doctest.DocTestSuite(pickle),
])
if __name__ == '__main__':
test_support.run_unittest(test_suite())