[shpy-commit] r2839 - shpy/trunk/dist/shpy/net/test
hpk@codespeak.net
hpk@codespeak.net
Mon, 19 Jan 2004 17:30:31 +0100 (MET)
Author: hpk
Date: Mon Jan 19 17:30:31 2004
New Revision: 2839
Added:
shpy/trunk/dist/shpy/net/test/test_all.py (contents, props changed)
- copied, changed from r2830, user/hpk/unittest2/test/test_all.py
shpy/trunk/dist/shpy/net/test/test_pickle.py
Log:
- added a pickle test which presents a pickle-hack to sync
"structures" across hosts.
- and a test_all script.
Copied: shpy/trunk/dist/shpy/net/test/test_all.py (from r2830, user/hpk/unittest2/test/test_all.py)
==============================================================================
--- user/hpk/unittest2/test/test_all.py (original)
+++ shpy/trunk/dist/shpy/net/test/test_all.py Mon Jan 19 17:30:31 2004
@@ -4,4 +4,4 @@
from unittest2 import main, collect
if __name__ == '__main__':
- main(collector=collect.PackageDirectoryCollector(autopath.packagedir) )
+ main(collector=collect.PackageDirectoryCollector(autopath.projectdir) )
Added: shpy/trunk/dist/shpy/net/test/test_pickle.py
==============================================================================
--- (empty file)
+++ shpy/trunk/dist/shpy/net/test/test_pickle.py Mon Jan 19 17:30:31 2004
@@ -0,0 +1,48 @@
+import autopath
+from unittest2 import check, main
+
+from StringIO import StringIO
+
+def pickletest(mod):
+ f1 = StringIO()
+ f2 = StringIO()
+
+ pickler1 = mod.Pickler(f1)
+ unpickler1 = mod.Unpickler(f2)
+
+ pickler2 = mod.Pickler(f2)
+ unpickler2 = mod.Unpickler(f1)
+
+ #pickler1.memo = unpickler1.memo = {}
+ #pickler2.memo = unpickler2.memo = {}
+
+ d = {}
+
+ pickler1.dump(d)
+ f1.seek(0)
+ d_other = unpickler2.load()
+
+ # translate unpickler2 memo to pickler2
+ pickler2.memo = dict([(id(obj), (int(x), obj))
+ for x, obj in unpickler2.memo.items()])
+
+ pickler2.dump(d_other)
+ f2.seek(0)
+
+ unpickler1.memo = dict([(str(x), y) for x, y in pickler1.memo.values()])
+
+ d_back = unpickler1.load()
+
+ check.is_(d, d_back)
+
+def test_cpickle():
+ import cPickle
+ pickletest(cPickle)
+
+def test_pickle():
+ import pickle
+ pickletest(pickle)
+
+if __name__ == '__main__':
+ main()
+