Python pickle.loads() Examples

The following are code examples for showing how to use pickle.loads(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: pyblish-win   Author: pyblish   File: test_pickling.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def test_struct(self):
        X.init_called = 0

        x = X()
        x.a = 42
        self.assertEqual(X.init_called, 1)

        y = self.loads(self.dumps(x))

        # loads must NOT call __init__
        self.assertEqual(X.init_called, 1)

        # ctypes instances are identical when the instance __dict__
        # and the memory buffer are identical
        self.assertEqual(y.__dict__, x.__dict__)
        self.assertEqual(memoryview(y).tobytes(),
                             memoryview(x).tobytes()) 
Example 2
Project: pyblish-win   Author: pyblish   File: dbtables.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def ListTableColumns(self, table):
        """Return a list of columns in the given table.
        [] if the table doesn't exist.
        """
        assert isinstance(table, str)
        if contains_metastrings(table):
            raise ValueError, "bad table name: contains reserved metastrings"

        columnlist_key = _columns_key(table)
        if not getattr(self.db, "has_key")(columnlist_key):
            return []
        pickledcolumnlist = getattr(self.db, "get_bytes",
                self.db.get)(columnlist_key)
        if pickledcolumnlist:
            return pickle.loads(pickledcolumnlist)
        else:
            return [] 
Example 3
Project: pyblish-win   Author: pyblish   File: test_datetime.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def test_pickling_subclass(self):
        # Make sure we can pickle/unpickle an instance of a subclass.
        offset = timedelta(minutes=-300)
        orig = PicklableFixedOffset(offset, 'cookie')
        self.assertIsInstance(orig, tzinfo)
        self.assertTrue(type(orig) is PicklableFixedOffset)
        self.assertEqual(orig.utcoffset(None), offset)
        self.assertEqual(orig.tzname(None), 'cookie')
        for pickler, unpickler, proto in pickle_choices:
            green = pickler.dumps(orig, proto)
            derived = unpickler.loads(green)
            self.assertIsInstance(derived, tzinfo)
            self.assertTrue(type(derived) is PicklableFixedOffset)
            self.assertEqual(derived.utcoffset(None), offset)
            self.assertEqual(derived.tzname(None), 'cookie')

#############################################################################
# Base class for testing a particular aspect of timedelta, time, date and
# datetime comparisons. 
Example 4
Project: pyblish-win   Author: pyblish   File: test_datetime.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def test_pickling(self):
        # Try one without a tzinfo.
        args = 6, 7, 23, 20, 59, 1, 64**2
        orig = self.theclass(*args)
        for pickler, unpickler, proto in pickle_choices:
            green = pickler.dumps(orig, proto)
            derived = unpickler.loads(green)
            self.assertEqual(orig, derived)

        # Try one with a tzinfo.
        tinfo = PicklableFixedOffset(-300, 'cookie')
        orig = self.theclass(*args, **{'tzinfo': tinfo})
        derived = self.theclass(1, 1, 1, tzinfo=FixedOffset(0, "", 0))
        for pickler, unpickler, proto in pickle_choices:
            green = pickler.dumps(orig, proto)
            derived = unpickler.loads(green)
            self.assertEqual(orig, derived)
            self.assertIsInstance(derived.tzinfo, PicklableFixedOffset)
            self.assertEqual(derived.utcoffset(), timedelta(minutes=-300))
            self.assertEqual(derived.tzname(), 'cookie') 
Example 5
Project: pyblish-win   Author: pyblish   File: test_collections.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def test_copying(self):
        # Check that ordered dicts are copyable, deepcopyable, picklable,
        # and have a repr/eval round-trip
        pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
        od = OrderedDict(pairs)
        update_test = OrderedDict()
        update_test.update(od)
        for i, dup in enumerate([
                    od.copy(),
                    copy.copy(od),
                    copy.deepcopy(od),
                    pickle.loads(pickle.dumps(od, 0)),
                    pickle.loads(pickle.dumps(od, 1)),
                    pickle.loads(pickle.dumps(od, 2)),
                    pickle.loads(pickle.dumps(od, -1)),
                    eval(repr(od)),
                    update_test,
                    OrderedDict(od),
                    ]):
            self.assertTrue(dup is not od)
            self.assertEqual(dup, od)
            self.assertEqual(list(dup.items()), list(od.items()))
            self.assertEqual(len(dup), len(od))
            self.assertEqual(type(dup), type(od)) 
Example 6
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: cache.py    Apache License 2.0 6 votes vote down vote up
def load_object(self, value):
        """The reversal of :meth:`dump_object`.  This might be callde with
        None.
        """
        if value is None:
            return None
        if value.startswith(b'!'):
            try:
                return pickle.loads(value[1:])
            except pickle.PickleError:
                return None
        try:
            return int(value)
        except ValueError:
            # before 0.8 we did not have serialization.  Still support that.
            return value 
Example 7
Project: flasky   Author: RoseOu   File: cache.py    MIT License 6 votes vote down vote up
def load_object(self, value):
        """The reversal of :meth:`dump_object`.  This might be callde with
        None.
        """
        if value is None:
            return None
        if value.startswith(b'!'):
            try:
                return pickle.loads(value[1:])
            except pickle.PickleError:
                return None
        try:
            return int(value)
        except ValueError:
            # before 0.8 we did not have serialization.  Still support that.
            return value 
Example 8
Project: dynamic-training-with-apache-mxnet-on-aws   Author: awslabs   File: kvstore_server.py    Apache License 2.0 6 votes vote down vote up
def _controller(self):
        """Return the server controller."""
        def server_controller(cmd_id, cmd_body, _):
            """Server controler."""
            if not self.init_logginig:
                # the reason put the codes here is because we cannot get
                # kvstore.rank earlier
                head = '%(asctime)-15s Server[' + str(
                    self.kvstore.rank) + '] %(message)s'
                logging.basicConfig(level=logging.DEBUG, format=head)
                self.init_logginig = True

            if cmd_id == 0:
                try:
                    optimizer = pickle.loads(cmd_body)
                except:
                    raise
                self.kvstore.set_optimizer(optimizer)
            else:
                print("server %d, unknown command (%d, %s)" % (
                    self.kvstore.rank, cmd_id, cmd_body))
        return server_controller 
Example 9
Project: pyblish-win   Author: pyblish   File: test_runner.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_pickle_unpickle(self):
        # Issue #7197: a TextTestRunner should be (un)pickleable. This is
        # required by test_multiprocessing under Windows (in verbose mode).
        from StringIO import StringIO as PickleableIO
        # cStringIO objects are not pickleable, but StringIO objects are.
        stream = PickleableIO("foo")
        runner = unittest.TextTestRunner(stream)
        for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
            s = pickle.dumps(runner, protocol=protocol)
            obj = pickle.loads(s)
            # StringIO objects never compare equal, a cheap test instead.
            self.assertEqual(obj.stream.getvalue(), stream.getvalue()) 
Example 10
Project: pyblish-win   Author: pyblish   File: test_case.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def testPickle(self):
        # Issue 10326

        # Can't use TestCase classes defined in Test class as
        # pickle does not work with inner classes
        test = unittest.TestCase('run')
        for protocol in range(pickle.HIGHEST_PROTOCOL + 1):

            # blew up prior to fix
            pickled_test = pickle.dumps(test, protocol=protocol)

            unpickled_test = pickle.loads(pickled_test)
            self.assertEqual(test, unpickled_test) 
Example 11
Project: pyblish-win   Author: pyblish   File: Cookie.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def value_decode(self, val):
        # This could raise an exception!
        return loads( _unquote(val) ), val 
Example 12
Project: pyblish-win   Author: pyblish   File: Cookie.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def value_decode(self, val):
        strval = _unquote(val)
        try:
            return loads(strval), val
        except:
            return strval, val 
Example 13
Project: pyblish-win   Author: pyblish   File: test_pickling.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def loads(self, item):
        return pickle.loads(item) 
Example 14
Project: pyblish-win   Author: pyblish   File: dbtables.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def ListTables(self):
        """Return a list of tables in this database."""
        pickledtablelist = self.db.get_get(_table_names_key)
        if pickledtablelist:
            return pickle.loads(pickledtablelist)
        else:
            return [] 
Example 15
Project: pyblish-win   Author: pyblish   File: test_dbtables.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test01(self):
        tabname = "test01"
        colname = 'cool numbers'
        try:
            self.tdb.Drop(tabname)
        except dbtables.TableDBError:
            pass
        self.tdb.CreateTable(tabname, [colname])
        import sys
        if sys.version_info[0] < 3 :
            self.tdb.Insert(tabname, {colname: pickle.dumps(3.14159, 1)})
        else :
            self.tdb.Insert(tabname, {colname: pickle.dumps(3.14159,
                1).decode("iso8859-1")})  # 8 bits

        if verbose:
            self.tdb._db_print()

        values = self.tdb.Select(
            tabname, [colname], conditions={colname: None})

        import sys
        if sys.version_info[0] < 3 :
            colval = pickle.loads(values[0][colname])
        else :
            colval = pickle.loads(bytes(values[0][colname], "iso8859-1"))
        self.assertTrue(colval > 3.141)
        self.assertTrue(colval < 3.142) 
Example 16
Project: pyblish-win   Author: pyblish   File: test_pickle.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def _base_test_pickle_DBError(self, pickle):
        self.env = db.DBEnv()
        self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL)
        self.db = db.DB(self.env)
        self.db.open(self.db_name, db.DB_HASH, db.DB_CREATE)
        self.db.put('spam', 'eggs')
        self.assertEqual(self.db['spam'], 'eggs')
        try:
            self.db.put('spam', 'ham', flags=db.DB_NOOVERWRITE)
        except db.DBError, egg:
            pickledEgg = pickle.dumps(egg)
            #print repr(pickledEgg)
            rottenEgg = pickle.loads(pickledEgg)
            if rottenEgg.args != egg.args or type(rottenEgg) != type(egg):
                raise Exception, (rottenEgg, '!=', egg) 
Example 17
Project: pyblish-win   Author: pyblish   File: test_sets.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_pickling(self):
        p = pickle.dumps(self.set)
        copy = pickle.loads(p)
        self.assertEqual(self.set, copy,
                         "%s != %s" % (self.set, copy))

#------------------------------------------------------------------------------ 
Example 18
Project: pyblish-win   Author: pyblish   File: test_xrange.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_pickling(self):
        testcases = [(13,), (0, 11), (-22, 10), (20, 3, -1),
                     (13, 21, 3), (-2, 2, 2)]
        for proto in range(pickle.HIGHEST_PROTOCOL + 1):
            for t in testcases:
                r = xrange(*t)
                self.assertEqual(list(pickle.loads(pickle.dumps(r, proto))),
                                 list(r))

        M = min(sys.maxint, sys.maxsize)
        large_testcases = testcases + [
            (0, M, 1),
            (M, 0, -1),
            (0, M, M - 1),
            (M // 2, M, 1),
            (0, -M, -1),
            (0, -M, 1 - M),
            (-M, M, 2),
            (-M, M, 1024),
            (-M, M, 10585),
            (M, -M, -2),
            (M, -M, -1024),
            (M, -M, -10585),
            ]
        for proto in range(pickle.HIGHEST_PROTOCOL + 1):
            for t in large_testcases:
                r = xrange(*t)
                r_out = pickle.loads(pickle.dumps(r, proto))
                self.assert_xranges_equivalent(r_out, r) 
Example 19
Project: pyblish-win   Author: pyblish   File: audiotests.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def check_params(self, f, nchannels, sampwidth, framerate, nframes,
                     comptype, compname):
        self.assertEqual(f.getnchannels(), nchannels)
        self.assertEqual(f.getsampwidth(), sampwidth)
        self.assertEqual(f.getframerate(), framerate)
        self.assertEqual(f.getnframes(), nframes)
        self.assertEqual(f.getcomptype(), comptype)
        self.assertEqual(f.getcompname(), compname)

        params = f.getparams()
        self.assertEqual(params,
                (nchannels, sampwidth, framerate, nframes, comptype, compname))

        dump = pickle.dumps(params)
        self.assertEqual(pickle.loads(dump), params) 
Example 20
Project: pyblish-win   Author: pyblish   File: test_xpickle.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def loads(self, buf):
        # Ignore fast
        return pickle.loads(buf) 
Example 21
Project: pyblish-win   Author: pyblish   File: test_xpickle.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def loads(self, buf):
        # Ignore fast
        return cPickle.loads(buf) 
Example 22
Project: pyblish-win   Author: pyblish   File: test_xpickle.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def loads(self, input):
        return self.module.loads(input)

    # These tests are disabled because they require some special setup
    # on the worker that's hard to keep in sync. 
Example 23
Project: pyblish-win   Author: pyblish   File: test_xpickle.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_unicode(self):
            endcases = [u'', u'<\\u>', u'<\\\u1234>', u'<\n>', u'<\\>']
            for proto in pickletester.protocols:
                for u in endcases:
                    p = self.dumps(u, proto)
                    u2 = self.loads(p)
                    self.assertEqual(u2, u) 
Example 24
Project: pyblish-win   Author: pyblish   File: test_datetime.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_pickling_base(self):
        # There's no point to pickling tzinfo objects on their own (they
        # carry no data), but they need to be picklable anyway else
        # concrete subclasses can't be pickled.
        orig = tzinfo.__new__(tzinfo)
        self.assertIs(type(orig), tzinfo)
        for pickler, unpickler, proto in pickle_choices:
            green = pickler.dumps(orig, proto)
            derived = unpickler.loads(green)
            self.assertIs(type(derived), tzinfo) 
Example 25
Project: pyblish-win   Author: pyblish   File: test_datetime.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_pickling(self):
        args = 12, 34, 56
        orig = timedelta(*args)
        for pickler, unpickler, proto in pickle_choices:
            green = pickler.dumps(orig, proto)
            derived = unpickler.loads(green)
            self.assertEqual(orig, derived) 
Example 26
Project: pyblish-win   Author: pyblish   File: test_datetime.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_pickling(self):
        args = 6, 7, 23
        orig = self.theclass(*args)
        for pickler, unpickler, proto in pickle_choices:
            green = pickler.dumps(orig, proto)
            derived = unpickler.loads(green)
            self.assertEqual(orig, derived) 
Example 27
Project: pyblish-win   Author: pyblish   File: test_datetime.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_pickling(self):
        args = 6, 7, 23, 20, 59, 1, 64**2
        orig = self.theclass(*args)
        for pickler, unpickler, proto in pickle_choices:
            green = pickler.dumps(orig, proto)
            derived = unpickler.loads(green)
            self.assertEqual(orig, derived) 
Example 28
Project: pyblish-win   Author: pyblish   File: test_datetime.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_more_pickling(self):
        a = self.theclass(2003, 2, 7, 16, 48, 37, 444116)
        s = pickle.dumps(a)
        b = pickle.loads(s)
        self.assertEqual(b.year, 2003)
        self.assertEqual(b.month, 2)
        self.assertEqual(b.day, 7) 
Example 29
Project: pyblish-win   Author: pyblish   File: test_datetime.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_pickling_subclass_datetime(self):
        args = 6, 7, 23, 20, 59, 1, 64**2
        orig = SubclassDatetime(*args)
        for pickler, unpickler, proto in pickle_choices:
            green = pickler.dumps(orig, proto)
            derived = unpickler.loads(green)
            self.assertEqual(orig, derived) 
Example 30
Project: pyblish-win   Author: pyblish   File: test_datetime.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_pickling(self):
        args = 20, 59, 16, 64**2
        orig = self.theclass(*args)
        for pickler, unpickler, proto in pickle_choices:
            green = pickler.dumps(orig, proto)
            derived = unpickler.loads(green)
            self.assertEqual(orig, derived) 
Example 31
Project: pyblish-win   Author: pyblish   File: test_datetime.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_pickling_subclass_time(self):
        args = 20, 59, 16, 64**2
        orig = SubclassTime(*args)
        for pickler, unpickler, proto in pickle_choices:
            green = pickler.dumps(orig, proto)
            derived = unpickler.loads(green)
            self.assertEqual(orig, derived) 
Example 32
Project: pyblish-win   Author: pyblish   File: test_bytes.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_pickling(self):
        for proto in range(pickle.HIGHEST_PROTOCOL + 1):
            for b in b"", b"a", b"abc", b"\xffab\x80", b"\0\0\377\0\0":
                b = self.type2test(b)
                ps = pickle.dumps(b, proto)
                q = pickle.loads(ps)
                self.assertEqual(b, q) 
Example 33
Project: pyblish-win   Author: pyblish   File: test_bytes.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_pickle(self):
        a = ByteArraySubclass(b"abcd")
        a.x = 10
        a.y = ByteArraySubclass(b"efgh")
        for proto in range(pickle.HIGHEST_PROTOCOL + 1):
            b = pickle.loads(pickle.dumps(a, proto))
            self.assertNotEqual(id(a), id(b))
            self.assertEqual(a, b)
            self.assertEqual(a.x, b.x)
            self.assertEqual(a.y, b.y)
            self.assertEqual(type(a), type(b))
            self.assertEqual(type(a.y), type(b.y)) 
Example 34
Project: pyblish-win   Author: pyblish   File: test_collections.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_pickle(self):
        p = TestNT(x=10, y=20, z=30)
        for module in pickle, cPickle:
            loads = getattr(module, 'loads')
            dumps = getattr(module, 'dumps')
            for protocol in -1, 0, 1, 2:
                q = loads(dumps(p, protocol))
                self.assertEqual(p, q)
                self.assertEqual(p._fields, q._fields) 
Example 35
Project: pyblish-win   Author: pyblish   File: test_collections.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_pickling_bug_18015(self):
        # http://bugs.python.org/issue18015
        pt = pickle.loads(py273_named_tuple_pickle)
        self.assertEqual(pt.x, 10) 
Example 36
Project: pyblish-win   Author: pyblish   File: test_cfgparser.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_error(self):
        import pickle
        e1 = ConfigParser.Error('value')
        pickled = pickle.dumps(e1)
        e2 = pickle.loads(pickled)
        self.assertEqual(e1.message, e2.message)
        self.assertEqual(repr(e1), repr(e2)) 
Example 37
Project: pyblish-win   Author: pyblish   File: test_cfgparser.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_nosectionerror(self):
        import pickle
        e1 = ConfigParser.NoSectionError('section')
        pickled = pickle.dumps(e1)
        e2 = pickle.loads(pickled)
        self.assertEqual(e1.message, e2.message)
        self.assertEqual(e1.args, e2.args)
        self.assertEqual(e1.section, e2.section)
        self.assertEqual(repr(e1), repr(e2)) 
Example 38
Project: pyblish-win   Author: pyblish   File: test_cfgparser.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_nooptionerror(self):
        import pickle
        e1 = ConfigParser.NoOptionError('option', 'section')
        pickled = pickle.dumps(e1)
        e2 = pickle.loads(pickled)
        self.assertEqual(e1.message, e2.message)
        self.assertEqual(e1.args, e2.args)
        self.assertEqual(e1.section, e2.section)
        self.assertEqual(e1.option, e2.option)
        self.assertEqual(repr(e1), repr(e2)) 
Example 39
Project: pyblish-win   Author: pyblish   File: test_cfgparser.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_duplicatesectionerror(self):
        import pickle
        e1 = ConfigParser.DuplicateSectionError('section')
        pickled = pickle.dumps(e1)
        e2 = pickle.loads(pickled)
        self.assertEqual(e1.message, e2.message)
        self.assertEqual(e1.args, e2.args)
        self.assertEqual(e1.section, e2.section)
        self.assertEqual(repr(e1), repr(e2)) 
Example 40
Project: pyblish-win   Author: pyblish   File: test_cfgparser.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_interpolationmissingoptionerror(self):
        import pickle
        e1 = ConfigParser.InterpolationMissingOptionError('option', 'section',
            'rawval', 'reference')
        pickled = pickle.dumps(e1)
        e2 = pickle.loads(pickled)
        self.assertEqual(e1.message, e2.message)
        self.assertEqual(e1.args, e2.args)
        self.assertEqual(e1.section, e2.section)
        self.assertEqual(e1.option, e2.option)
        self.assertEqual(e1.reference, e2.reference)
        self.assertEqual(repr(e1), repr(e2)) 
Example 41
Project: pyblish-win   Author: pyblish   File: test_cfgparser.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_interpolationsyntaxerror(self):
        import pickle
        e1 = ConfigParser.InterpolationSyntaxError('option', 'section', 'msg')
        pickled = pickle.dumps(e1)
        e2 = pickle.loads(pickled)
        self.assertEqual(e1.message, e2.message)
        self.assertEqual(e1.args, e2.args)
        self.assertEqual(e1.section, e2.section)
        self.assertEqual(e1.option, e2.option)
        self.assertEqual(repr(e1), repr(e2)) 
Example 42
Project: pyblish-win   Author: pyblish   File: test_cfgparser.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_interpolationdeptherror(self):
        import pickle
        e1 = ConfigParser.InterpolationDepthError('option', 'section',
            'rawval')
        pickled = pickle.dumps(e1)
        e2 = pickle.loads(pickled)
        self.assertEqual(e1.message, e2.message)
        self.assertEqual(e1.args, e2.args)
        self.assertEqual(e1.section, e2.section)
        self.assertEqual(e1.option, e2.option)
        self.assertEqual(repr(e1), repr(e2)) 
Example 43
Project: pyblish-win   Author: pyblish   File: test_cfgparser.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_parsingerror(self):
        import pickle
        e1 = ConfigParser.ParsingError('source')
        e1.append(1, 'line1')
        e1.append(2, 'line2')
        e1.append(3, 'line3')
        pickled = pickle.dumps(e1)
        e2 = pickle.loads(pickled)
        self.assertEqual(e1.message, e2.message)
        self.assertEqual(e1.args, e2.args)
        self.assertEqual(e1.filename, e2.filename)
        self.assertEqual(e1.errors, e2.errors)
        self.assertEqual(repr(e1), repr(e2)) 
Example 44
Project: pyblish-win   Author: pyblish   File: test_cfgparser.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_missingsectionheadererror(self):
        import pickle
        e1 = ConfigParser.MissingSectionHeaderError('filename', 123, 'line')
        pickled = pickle.dumps(e1)
        e2 = pickle.loads(pickled)
        self.assertEqual(e1.message, e2.message)
        self.assertEqual(e1.args, e2.args)
        self.assertEqual(e1.line, e2.line)
        self.assertEqual(e1.filename, e2.filename)
        self.assertEqual(e1.lineno, e2.lineno)
        self.assertEqual(repr(e1), repr(e2)) 
Example 45
Project: pyblish-win   Author: pyblish   File: test_cookie.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_pickle(self):
        rawdata = 'Customer="WILE_E_COYOTE"; Path=/acme; Version=1'
        expected_output = 'Set-Cookie: %s' % rawdata

        C = Cookie.SimpleCookie()
        C.load(rawdata)
        self.assertEqual(C.output(), expected_output)

        for proto in range(pickle.HIGHEST_PROTOCOL + 1):
            C1 = pickle.loads(pickle.dumps(C, protocol=proto))
            self.assertEqual(C1.output(), expected_output) 
Example 46
Project: pyblish-win   Author: pyblish   File: test_set.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_pickling(self):
        for i in range(pickle.HIGHEST_PROTOCOL + 1):
            p = pickle.dumps(self.s, i)
            dup = pickle.loads(p)
            self.assertEqual(self.s, dup, "%s != %s" % (self.s, dup))
            if type(self.s) not in (set, frozenset):
                self.s.x = 10
                p = pickle.dumps(self.s)
                dup = pickle.loads(p)
                self.assertEqual(self.s.x, dup.x) 
Example 47
Project: pyblish-win   Author: pyblish   File: test_set.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_pickling(self):
        p = pickle.dumps(self.set)
        copy = pickle.loads(p)
        self.assertEqual(self.set, copy,
                         "%s != %s" % (self.set, copy))

#------------------------------------------------------------------------------ 
Example 48
Project: pyblish-win   Author: pyblish   File: test_itertools.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_count(self):
        self.assertEqual(zip('abc',count()), [('a', 0), ('b', 1), ('c', 2)])
        self.assertEqual(zip('abc',count(3)), [('a', 3), ('b', 4), ('c', 5)])
        self.assertEqual(take(2, zip('abc',count(3))), [('a', 3), ('b', 4)])
        self.assertEqual(take(2, zip('abc',count(-1))), [('a', -1), ('b', 0)])
        self.assertEqual(take(2, zip('abc',count(-3))), [('a', -3), ('b', -2)])
        self.assertRaises(TypeError, count, 2, 3, 4)
        self.assertRaises(TypeError, count, 'a')
        self.assertEqual(list(islice(count(maxsize-5), 10)), range(maxsize-5, maxsize+5))
        self.assertEqual(list(islice(count(-maxsize-5), 10)), range(-maxsize-5, -maxsize+5))
        c = count(3)
        self.assertEqual(repr(c), 'count(3)')
        c.next()
        self.assertEqual(repr(c), 'count(4)')
        c = count(-9)
        self.assertEqual(repr(c), 'count(-9)')
        c.next()
        self.assertEqual(repr(count(10.25)), 'count(10.25)')
        self.assertEqual(c.next(), -8)
        for i in (-sys.maxint-5, -sys.maxint+5 ,-10, -1, 0, 10, sys.maxint-5, sys.maxint+5):
            # Test repr (ignoring the L in longs)
            r1 = repr(count(i)).replace('L', '')
            r2 = 'count(%r)'.__mod__(i).replace('L', '')
            self.assertEqual(r1, r2)

        # check copy, deepcopy, pickle
        for value in -3, 3, sys.maxint-5, sys.maxint+5:
            c = count(value)
            self.assertEqual(next(copy.copy(c)), value)
            self.assertEqual(next(copy.deepcopy(c)), value)
            self.assertEqual(next(pickle.loads(pickle.dumps(c))), value) 
Example 49
Project: pyblish-win   Author: pyblish   File: test_pickle.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def loads(self, buf):
        # Ignore fast
        return pickle.loads(buf) 
Example 50
Project: pyblish-win   Author: pyblish   File: test_pickle.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def loads(self, buf):
        f = StringIO(buf)
        u = pickle.Unpickler(f)
        return u.load()