Commit a7ec3e89 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #19949: The test_xpickle test now tests compatibility with installed

Python 2.7 and reports skipped tests.  Based on patch by Zachary Ware.
parent fb0c640f
...@@ -56,7 +56,7 @@ class DumpPickle_LoadCPickle(AbstractPickleTests): ...@@ -56,7 +56,7 @@ class DumpPickle_LoadCPickle(AbstractPickleTests):
# Ignore fast # Ignore fast
return cPickle.loads(buf) return cPickle.loads(buf)
def have_python_version(name): def have_python_version(name, cache={}):
"""Check whether the given name is a valid Python binary and has """Check whether the given name is a valid Python binary and has
test.test_support. test.test_support.
...@@ -68,7 +68,9 @@ def have_python_version(name): ...@@ -68,7 +68,9 @@ def have_python_version(name):
Returns: Returns:
True if the name is valid, False otherwise. True if the name is valid, False otherwise.
""" """
return os.system(name + " -c 'import test.test_support'") == 0 if name not in cache:
cache[name] = os.system(name + ' -c "import test.test_support"') == 0
return cache[name]
class AbstractCompatTests(AbstractPickleTests): class AbstractCompatTests(AbstractPickleTests):
...@@ -81,6 +83,9 @@ class AbstractCompatTests(AbstractPickleTests): ...@@ -81,6 +83,9 @@ class AbstractCompatTests(AbstractPickleTests):
self.assertTrue(self.python) self.assertTrue(self.python)
self.assertTrue(self.module) self.assertTrue(self.module)
self.assertTrue(self.error) self.assertTrue(self.error)
test_support.requires("xpickle")
if not have_python_version(self.python):
self.skipTest('%s not available' % self.python)
def send_to_worker(self, python, obj, proto): def send_to_worker(self, python, obj, proto):
"""Bounce a pickled object through another version of Python. """Bounce a pickled object through another version of Python.
...@@ -119,14 +124,9 @@ class AbstractCompatTests(AbstractPickleTests): ...@@ -119,14 +124,9 @@ class AbstractCompatTests(AbstractPickleTests):
# These tests are disabled because they require some special setup # These tests are disabled because they require some special setup
# on the worker that's hard to keep in sync. # on the worker that's hard to keep in sync.
def test_global_ext1(self): test_global_ext1 = None
pass test_global_ext2 = None
test_global_ext4 = None
def test_global_ext2(self):
pass
def test_global_ext4(self):
pass
# This is a cut-down version of pickletester's test_float. Backwards # This is a cut-down version of pickletester's test_float. Backwards
# compatibility for the values in for_bin_protos was explicitly broken in # compatibility for the values in for_bin_protos was explicitly broken in
...@@ -151,18 +151,16 @@ class AbstractCompatTests(AbstractPickleTests): ...@@ -151,18 +151,16 @@ class AbstractCompatTests(AbstractPickleTests):
self.assertEqual(value, got) self.assertEqual(value, got)
# Backwards compatibility was explicitly broken in r67934 to fix a bug. # Backwards compatibility was explicitly broken in r67934 to fix a bug.
def test_unicode_high_plane(self): test_unicode_high_plane = None
pass
# This tests a fix that's in 2.7 only # This tests a fix that's in 2.7 only
def test_dynamic_class(self): test_dynamic_class = None
pass
if test_support.have_unicode:
# This is a cut-down version of pickletester's test_unicode. Backwards # This is a cut-down version of pickletester's test_unicode. Backwards
# compatibility was explicitly broken in r67934 to fix a bug. # compatibility was explicitly broken in r67934 to fix a bug.
@unittest.skipUnless(test_support.have_unicode, 'no unicode support')
def test_unicode(self): def test_unicode(self):
endcases = [u'', u'<\\u>', u'<\\\u1234>', u'<\n>', u'<\\>'] endcases = [u'', u'<\\u>', u'<\\%c>' % 0x1234, u'<\n>', u'<\\>']
for proto in pickletester.protocols: for proto in pickletester.protocols:
for u in endcases: for u in endcases:
p = self.dumps(u, proto) p = self.dumps(u, proto)
...@@ -170,17 +168,8 @@ class AbstractCompatTests(AbstractPickleTests): ...@@ -170,17 +168,8 @@ class AbstractCompatTests(AbstractPickleTests):
self.assertEqual(u2, u) self.assertEqual(u2, u)
def run_compat_test(python_name):
return (test_support.is_resource_enabled("xpickle") and
have_python_version(python_name))
# Test backwards compatibility with Python 2.4. # Test backwards compatibility with Python 2.4.
if not run_compat_test("python2.4"): class CPicklePython24Compat(AbstractCompatTests):
class CPicklePython24Compat(unittest.TestCase):
pass
else:
class CPicklePython24Compat(AbstractCompatTests):
module = cPickle module = cPickle
python = "python2.4" python = "python2.4"
...@@ -188,11 +177,8 @@ else: ...@@ -188,11 +177,8 @@ else:
# Disable these tests for Python 2.4. Making them pass would require # Disable these tests for Python 2.4. Making them pass would require
# nontrivially monkeypatching the pickletester module in the worker. # nontrivially monkeypatching the pickletester module in the worker.
def test_reduce_calls_base(self): test_reduce_calls_base = None
pass test_reduce_ex_calls_base = None
def test_reduce_ex_calls_base(self):
pass
class PicklePython24Compat(CPicklePython24Compat): class PicklePython24Compat(CPicklePython24Compat):
...@@ -201,11 +187,7 @@ class PicklePython24Compat(CPicklePython24Compat): ...@@ -201,11 +187,7 @@ class PicklePython24Compat(CPicklePython24Compat):
# Test backwards compatibility with Python 2.5. # Test backwards compatibility with Python 2.5.
if not run_compat_test("python2.5"): class CPicklePython25Compat(AbstractCompatTests):
class CPicklePython25Compat(unittest.TestCase):
pass
else:
class CPicklePython25Compat(AbstractCompatTests):
module = cPickle module = cPickle
python = "python2.5" python = "python2.5"
...@@ -218,11 +200,7 @@ class PicklePython25Compat(CPicklePython25Compat): ...@@ -218,11 +200,7 @@ class PicklePython25Compat(CPicklePython25Compat):
# Test backwards compatibility with Python 2.6. # Test backwards compatibility with Python 2.6.
if not run_compat_test("python2.6"): class CPicklePython26Compat(AbstractCompatTests):
class CPicklePython26Compat(unittest.TestCase):
pass
else:
class CPicklePython26Compat(AbstractCompatTests):
module = cPickle module = cPickle
python = "python2.6" python = "python2.6"
...@@ -234,6 +212,18 @@ class PicklePython26Compat(CPicklePython26Compat): ...@@ -234,6 +212,18 @@ class PicklePython26Compat(CPicklePython26Compat):
error = KeyError error = KeyError
class CPicklePython27Compat(AbstractCompatTests):
module = cPickle
python = "python2.7"
error = cPickle.BadPickleGet
class PicklePython27Compat(CPicklePython26Compat):
module = pickle
error = KeyError
def worker_main(in_stream, out_stream): def worker_main(in_stream, out_stream):
message = cPickle.load(in_stream) message = cPickle.load(in_stream)
protocol, obj = message protocol, obj = message
...@@ -241,20 +231,17 @@ def worker_main(in_stream, out_stream): ...@@ -241,20 +231,17 @@ def worker_main(in_stream, out_stream):
def test_main(): def test_main():
if not test_support.is_resource_enabled("xpickle"):
print >>sys.stderr, "test_xpickle -- skipping backwards compat tests."
print >>sys.stderr, "Use 'regrtest.py -u xpickle' to run them."
sys.stderr.flush()
test_support.run_unittest( test_support.run_unittest(
DumpCPickle_LoadPickle, DumpCPickle_LoadPickle,
DumpPickle_LoadCPickle, DumpPickle_LoadCPickle,
CPicklePython24Compat, CPicklePython24Compat,
CPicklePython25Compat, CPicklePython25Compat,
CPicklePython26Compat, CPicklePython26Compat,
CPicklePython27Compat,
PicklePython24Compat, PicklePython24Compat,
PicklePython25Compat, PicklePython25Compat,
PicklePython26Compat, PicklePython26Compat,
PicklePython27Compat,
) )
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -86,6 +86,8 @@ Tools/Demos ...@@ -86,6 +86,8 @@ Tools/Demos
Tests Tests
----- -----
- Issue #19949: The test_xpickle test now
- Issue #11578: Backported test for the timeit module. - Issue #11578: Backported test for the timeit module.
- Issue #22943: bsddb tests are locale independend now. - Issue #22943: bsddb tests are locale independend now.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment