diff options
author | Guido van Rossum <guido@python.org> | 1999-03-25 22:38:49 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1999-03-25 22:38:49 (GMT) |
commit | aa3828aa354e1f50a8d073c40c41027c2bd43739 (patch) | |
tree | 493adab7512b6e8e6416882d1b559f1bc06ee0dc /Lib | |
parent | 7c6a90de8ad5fd75527c82dbb9cc1d6d24ddec07 (diff) | |
download | cpython-aa3828aa354e1f50a8d073c40c41027c2bd43739.zip cpython-aa3828aa354e1f50a8d073c40c41027c2bd43739.tar.gz cpython-aa3828aa354e1f50a8d073c40c41027c2bd43739.tar.bz2 |
Basic regr tests for pickle/cPickle
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/output/test_cpickle | 11 | ||||
-rw-r--r-- | Lib/test/output/test_pickle | 11 | ||||
-rw-r--r-- | Lib/test/test_cpickle.py | 75 | ||||
-rw-r--r-- | Lib/test/test_pickle.py | 75 |
4 files changed, 172 insertions, 0 deletions
diff --git a/Lib/test/output/test_cpickle b/Lib/test/output/test_cpickle new file mode 100644 index 0000000..4f78690 --- /dev/null +++ b/Lib/test/output/test_cpickle @@ -0,0 +1,11 @@ +test_cpickle +dumps() +loads() +ok +loads() DATA +ok +dumps() binary +loads() binary +ok +loads() BINDATA +ok diff --git a/Lib/test/output/test_pickle b/Lib/test/output/test_pickle new file mode 100644 index 0000000..78a80a9 --- /dev/null +++ b/Lib/test/output/test_pickle @@ -0,0 +1,11 @@ +test_pickle +dumps() +loads() +ok +loads() DATA +ok +dumps() binary +loads() binary +ok +loads() BINDATA +ok diff --git a/Lib/test/test_cpickle.py b/Lib/test/test_cpickle.py new file mode 100644 index 0000000..bedb321 --- /dev/null +++ b/Lib/test/test_cpickle.py @@ -0,0 +1,75 @@ +# Test the cPickle module + +DATA = """(lp0 +I0 +aL1L +aF2.0 +ac__builtin__ +complex +p1 +(F3.0 +F0.0 +tp2 +Rp3 +a(S'abc' +p4 +g4 +(i__main__ +C +p5 +(dp6 +S'foo' +p7 +I1 +sS'bar' +p8 +I2 +sbg5 +tp9 +ag9 +aI5 +a. +""" + +BINDATA = ']q\000(K\000L1L\012G@\000\000\000\000\000\000\000c__builtin__\012complex\012q\001(G@\010\000\000\000\000\000\000G\000\000\000\000\000\000\000\000tq\002Rq\003(U\003abcq\004h\004(c__main__\012C\012q\005oq\006}q\007(U\003fooq\010K\001U\003barq\011K\002ubh\006tq\012h\012K\005e.' + +import cPickle + +class C: + def __cmp__(self, other): + return cmp(self.__dict__, other.__dict__) + +import __main__ +__main__.C = C + +def dotest(): + c = C() + c.foo = 1 + c.bar = 2 + x = [0, 1L, 2.0, 3.0+0j] + y = ('abc', 'abc', c, c) + x.append(y) + x.append(y) + x.append(5) + print "dumps()" + s = cPickle.dumps(x) + print "loads()" + x2 = cPickle.loads(s) + if x2 == x: print "ok" + else: print "bad" + print "loads() DATA" + x2 = cPickle.loads(DATA) + if x2 == x: print "ok" + else: print "bad" + print "dumps() binary" + s = cPickle.dumps(x, 1) + print "loads() binary" + x2 = cPickle.loads(s) + if x2 == x: print "ok" + else: print "bad" + print "loads() BINDATA" + x2 = cPickle.loads(BINDATA) + if x2 == x: print "ok" + else: print "bad" + +dotest() diff --git a/Lib/test/test_pickle.py b/Lib/test/test_pickle.py new file mode 100644 index 0000000..8fb534d --- /dev/null +++ b/Lib/test/test_pickle.py @@ -0,0 +1,75 @@ +# Test the pickle module + +DATA = """(lp0 +I0 +aL1L +aF2.0 +ac__builtin__ +complex +p1 +(F3.0 +F0.0 +tp2 +Rp3 +a(S'abc' +p4 +g4 +(i__main__ +C +p5 +(dp6 +S'foo' +p7 +I1 +sS'bar' +p8 +I2 +sbg5 +tp9 +ag9 +aI5 +a. +""" + +BINDATA = ']q\000(K\000L1L\012G@\000\000\000\000\000\000\000c__builtin__\012complex\012q\001(G@\010\000\000\000\000\000\000G\000\000\000\000\000\000\000\000tq\002Rq\003(U\003abcq\004h\004(c__main__\012C\012q\005oq\006}q\007(U\003fooq\010K\001U\003barq\011K\002ubh\006tq\012h\012K\005e.' + +import pickle + +class C: + def __cmp__(self, other): + return cmp(self.__dict__, other.__dict__) + +import __main__ +__main__.C = C + +def dotest(): + c = C() + c.foo = 1 + c.bar = 2 + x = [0, 1L, 2.0, 3.0+0j] + y = ('abc', 'abc', c, c) + x.append(y) + x.append(y) + x.append(5) + print "dumps()" + s = pickle.dumps(x) + print "loads()" + x2 = pickle.loads(s) + if x2 == x: print "ok" + else: print "bad" + print "loads() DATA" + x2 = pickle.loads(DATA) + if x2 == x: print "ok" + else: print "bad" + print "dumps() binary" + s = pickle.dumps(x, 1) + print "loads() binary" + x2 = pickle.loads(s) + if x2 == x: print "ok" + else: print "bad" + print "loads() BINDATA" + x2 = pickle.loads(BINDATA) + if x2 == x: print "ok" + else: print "bad" + +dotest() |