test_dict.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:web_ctp 作者: molebot 项目源码 文件源码
def test_itemiterator_pickling(self):
        data = {1:"a", 2:"b", 3:"c"}
        # dictviews aren't picklable, only their iterators
        itorg = iter(data.items())
        d = pickle.dumps(itorg)
        it = pickle.loads(d)
        # note that the type of type of the unpickled iterator
        # is not necessarily the same as the original.  It is
        # merely an object supporting the iterator protocol, yielding
        # the same objects as the original one.
        # self.assertEqual(type(itorg), type(it))
        #self.assertTrue(isinstance(it, collections.abc.Iterator))
        self.assertEqual(dict(it), data)

        it = pickle.loads(d)
        drop = next(it)
        d = pickle.dumps(it)
        it = pickle.loads(d)
        del data[drop[0]]
        self.assertEqual(dict(it), data)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号