10a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# test_pickle dumps and loads pickles via pickle.py.
20a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# test_cpickle does the same, but via the cPickle module.
30a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# This test covers the other two cases, making pickles with one module and
40a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# loading them via the other. It also tests backwards compatibility with
50a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# previous version of Python by bouncing pickled objects through Python 2.4
60a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# and Python 2.5 running this file.
70a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
80a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport cPickle
90a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport os
100a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport os.path
110a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport pickle
120a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport subprocess
130a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport sys
140a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport types
150a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport unittest
160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
170a8c90248264a8b26970b4473770bcc3df8515fJosh Gaofrom test import test_support
180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# Most distro-supplied Pythons don't include the tests
200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# or test support files, and some don't include a way to get these back even if
210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# you're will to install extra packages (like Ubuntu). Doing things like this
220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# "provides" a pickletester module for older versions of Python that may be
230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# installed without it. Note that one other design for this involves messing
240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# with sys.path, which is less precise.
250a8c90248264a8b26970b4473770bcc3df8515fJosh Gaomod_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                                        "pickletester.py"))
270a8c90248264a8b26970b4473770bcc3df8515fJosh Gaopickletester = types.ModuleType("test.pickletester")
280a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoexec compile(open(mod_path).read(), mod_path, 'exec') in pickletester.__dict__
290a8c90248264a8b26970b4473770bcc3df8515fJosh GaoAbstractPickleTests = pickletester.AbstractPickleTests
300a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoif pickletester.__name__ in sys.modules:
310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    raise RuntimeError("Did not expect to find test.pickletester loaded")
320a8c90248264a8b26970b4473770bcc3df8515fJosh Gaosys.modules[pickletester.__name__] = pickletester
330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
350a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass DumpCPickle_LoadPickle(AbstractPickleTests):
360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    error = KeyError
380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    def dumps(self, arg, proto=0, fast=False):
400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # Ignore fast
410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        return cPickle.dumps(arg, proto)
420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    def loads(self, buf):
440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # Ignore fast
450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        return pickle.loads(buf)
460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
470a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass DumpPickle_LoadCPickle(AbstractPickleTests):
480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    error = cPickle.BadPickleGet
500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    def dumps(self, arg, proto=0, fast=False):
520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # Ignore fast
530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        return pickle.dumps(arg, proto)
540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    def loads(self, buf):
560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # Ignore fast
570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        return cPickle.loads(buf)
580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
590a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef have_python_version(name):
600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    """Check whether the given name is a valid Python binary and has
610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    test.test_support.
620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    This respects your PATH.
640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    Args:
660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        name: short string name of a Python binary such as "python2.4".
670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    Returns:
690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        True if the name is valid, False otherwise.
700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    """
710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    return os.system(name + " -c 'import test.test_support'") == 0
720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
740a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass AbstractCompatTests(AbstractPickleTests):
750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    module = None
770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    python = None
780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    error = None
790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    def setUp(self):
810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.assertTrue(self.python)
820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.assertTrue(self.module)
830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.assertTrue(self.error)
840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    def send_to_worker(self, python, obj, proto):
860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        """Bounce a pickled object through another version of Python.
870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        This will pickle the object, send it to a child process where it will be
890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        unpickled, then repickled and sent back to the parent process.
900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        Args:
920a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            python: the name of the Python binary to start.
930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            obj: object to pickle.
940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            proto: pickle protocol number to use.
950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        Returns:
970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            The pickled data received from the child process.
980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        """
990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # Prevent the subprocess from picking up invalid .pyc files.
1000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        target = __file__
1010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        if target[-1] in ("c", "o"):
1020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            target = target[:-1]
1030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        data = self.module.dumps((proto, obj), proto)
1050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        worker = subprocess.Popen([python, target, "worker"],
1060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                                  stdin=subprocess.PIPE,
1070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                                  stdout=subprocess.PIPE,
1080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                                  stderr=subprocess.PIPE)
1090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        stdout, stderr = worker.communicate(data)
1100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        if worker.returncode != 0:
1110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            raise RuntimeError(stderr)
1120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        return stdout
1130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    def dumps(self, arg, proto=0, fast=False):
1150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        return self.send_to_worker(self.python, arg, proto)
1160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    def loads(self, input):
1180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        return self.module.loads(input)
1190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    # These tests are disabled because they require some special setup
1210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    # on the worker that's hard to keep in sync.
1220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    def test_global_ext1(self):
1230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        pass
1240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    def test_global_ext2(self):
1260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        pass
1270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    def test_global_ext4(self):
1290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        pass
1300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    # This is a cut-down version of pickletester's test_float. Backwards
1320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    # compatibility for the values in for_bin_protos was explicitly broken in
1330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    # r68903 to fix a bug.
1340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    def test_float(self):
1350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        for_bin_protos = [4.94e-324, 1e-310]
1360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        neg_for_bin_protos = [-x for x in for_bin_protos]
1370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        test_values = [0.0, 7e-308, 6.626e-34, 0.1, 0.5,
1380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                       3.14, 263.44582062374053, 6.022e23, 1e30]
1390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        test_proto0_values = test_values + [-x for x in test_values]
1400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        test_values = test_proto0_values + for_bin_protos + neg_for_bin_protos
1410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        for value in test_proto0_values:
1430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            pickle = self.dumps(value, 0)
1440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            got = self.loads(pickle)
1450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            self.assertEqual(value, got)
1460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        for proto in pickletester.protocols[1:]:
1480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            for value in test_values:
1490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                pickle = self.dumps(value, proto)
1500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                got = self.loads(pickle)
1510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                self.assertEqual(value, got)
1520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    # Backwards compatibility was explicitly broken in r67934 to fix a bug.
1540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    def test_unicode_high_plane(self):
1550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        pass
1560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    # This tests a fix that's in 2.7 only
1580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    def test_dynamic_class(self):
1590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        pass
1600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    if test_support.have_unicode:
1620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # This is a cut-down version of pickletester's test_unicode. Backwards
1630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # compatibility was explicitly broken in r67934 to fix a bug.
1640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        def test_unicode(self):
1650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            endcases = [u'', u'<\\u>', u'<\\\u1234>', u'<\n>', u'<\\>']
1660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            for proto in pickletester.protocols:
1670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                for u in endcases:
1680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                    p = self.dumps(u, proto)
1690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                    u2 = self.loads(p)
1700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                    self.assertEqual(u2, u)
1710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1730a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef run_compat_test(python_name):
1740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    return (test_support.is_resource_enabled("xpickle") and
1750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            have_python_version(python_name))
1760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# Test backwards compatibility with Python 2.4.
1790a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoif not run_compat_test("python2.4"):
1800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    class CPicklePython24Compat(unittest.TestCase):
1810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        pass
1820a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoelse:
1830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    class CPicklePython24Compat(AbstractCompatTests):
1840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        module = cPickle
1860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        python = "python2.4"
1870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        error = cPickle.BadPickleGet
1880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # Disable these tests for Python 2.4. Making them pass would require
1900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # nontrivially monkeypatching the pickletester module in the worker.
1910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        def test_reduce_calls_base(self):
1920a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            pass
1930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        def test_reduce_ex_calls_base(self):
1950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            pass
1960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1970a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass PicklePython24Compat(CPicklePython24Compat):
1980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    module = pickle
2000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    error = KeyError
2010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# Test backwards compatibility with Python 2.5.
2040a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoif not run_compat_test("python2.5"):
2050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    class CPicklePython25Compat(unittest.TestCase):
2060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        pass
2070a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoelse:
2080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    class CPicklePython25Compat(AbstractCompatTests):
2090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        module = cPickle
2110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        python = "python2.5"
2120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        error = cPickle.BadPickleGet
2130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2140a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass PicklePython25Compat(CPicklePython25Compat):
2150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    module = pickle
2170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    error = KeyError
2180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# Test backwards compatibility with Python 2.6.
2210a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoif not run_compat_test("python2.6"):
2220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    class CPicklePython26Compat(unittest.TestCase):
2230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        pass
2240a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoelse:
2250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    class CPicklePython26Compat(AbstractCompatTests):
2260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        module = cPickle
2280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        python = "python2.6"
2290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        error = cPickle.BadPickleGet
2300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2310a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass PicklePython26Compat(CPicklePython26Compat):
2320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    module = pickle
2340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    error = KeyError
2350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2370a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef worker_main(in_stream, out_stream):
2380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    message = cPickle.load(in_stream)
2390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    protocol, obj = message
2400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    cPickle.dump(obj, out_stream, protocol)
2410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2430a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef test_main():
2440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    if not test_support.is_resource_enabled("xpickle"):
2450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        print >>sys.stderr, "test_xpickle -- skipping backwards compat tests."
2460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        print >>sys.stderr, "Use 'regrtest.py -u xpickle' to run them."
2470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        sys.stderr.flush()
2480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    test_support.run_unittest(
2500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        DumpCPickle_LoadPickle,
2510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        DumpPickle_LoadCPickle,
2520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        CPicklePython24Compat,
2530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        CPicklePython25Compat,
2540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        CPicklePython26Compat,
2550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        PicklePython24Compat,
2560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        PicklePython25Compat,
2570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        PicklePython26Compat,
2580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    )
2590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2600a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoif __name__ == "__main__":
2610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    if "worker" in sys.argv:
2620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        worker_main(sys.stdin, sys.stdout)
2630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    else:
2640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        test_main()
265