# HG changeset patch # User Sylvain Thénault # Date 1464788178 -7200 # Node ID d0f6fe008ec4ee721cbb49b9a939a78328a77e52 # Parent 9ae85b069325eb79ad9ce688b45e6df72884bff7 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 diff -r 9ae85b069325 -r d0f6fe008ec4 __init__.py --- 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: diff -r 9ae85b069325 -r d0f6fe008ec4 test/unittest_binary.py --- 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 . 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