File: test_cpickle_jy.py

package info (click to toggle)
jython 2.5.1-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 41,624 kB
  • ctags: 101,579
  • sloc: python: 351,444; java: 204,338; xml: 1,316; sh: 330; ansic: 126; perl: 114; makefile: 94
file content (43 lines) | stat: -rw-r--r-- 958 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Misc cPickle tests.

Made for Jython.
"""
import cPickle
import pickle
import unittest
from test import test_support

class MyClass(object):
    pass


class CPickleTestCase(unittest.TestCase):

    def test_zero_long(self):
        self.assertEqual(cPickle.loads(cPickle.dumps(0L, 2)), 0L)
        self.assertEqual(cPickle.dumps(0L, 2), pickle.dumps(0L, 2))

    def test_cyclic_memoize(self):
        # http://bugs.python.org/issue998998 - cPickle shouldn't fail
        # this, though pickle.py still does
        m = MyClass()
        m2 = MyClass()

        s = set([m])
        m.foo = set([m2])
        m2.foo = s

        s2 = cPickle.loads(cPickle.dumps(s))
        self.assertEqual(len(s2), 1)
        m3 = iter(s2).next()
        self.assertEqual(len(m3.foo), 1)
        m4 = iter(m3.foo).next()
        self.assertEqual(m4.foo, s2)


def test_main():
    test_support.run_unittest(CPickleTestCase)


if __name__ == '__main__':
    test_main()