Test and fix "pickleability" of Binary objects
which has been recently broken while some cubes rely on this (eg fastimport).
Do some licensing/pep8 cleanup along the way.
Closes #13385274
--- a/__init__.py Wed May 25 17:19:14 2016 +0200
+++ b/__init__.py Wed Jun 01 15:36:18 2016 +0200
@@ -33,8 +33,9 @@
CW_SOFTWARE_ROOT = __path__[0]
-import sys, os, logging
-if (2, 7) <= sys.version_info < (2, 7, 4):
+import sys
+import logging
+if PY2:
# http://bugs.python.org/issue10211
from StringIO import StringIO as BytesIO
else:
--- a/test/unittest_binary.py Wed May 25 17:19:14 2016 +0200
+++ b/test/unittest_binary.py Wed Jun 01 15:36:18 2016 +0200
@@ -1,10 +1,29 @@
-from six import PY2
+# copyright 2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
+#
+# This file is part of CubicWeb.
+#
+# CubicWeb is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
from unittest import TestCase
-from tempfile import NamedTemporaryFile
import os.path as osp
+import pickle
+
+from six import PY2
from logilab.common.shellutils import tempdir
+
from cubicweb import Binary
@@ -48,6 +67,11 @@
bobj = Binary.from_file(fpath)
self.assertEqual(bobj.getvalue(), b'binaryblob')
+ def test_pickleable(self):
+ b = Binary(b'toto')
+ bb = pickle.loads(pickle.dumps(b))
+ self.assertEqual(b, bb)
+
if __name__ == '__main__':
from unittest import main