def test_pickle(self): md = PyMimeData(data=0) self.assertEqual(md._local_instance, 0) self.assertTrue(md.hasFormat(PyMimeData.MIME_TYPE)) self.assertFalse(md.hasFormat(PyMimeData.NOPICKLE_MIME_TYPE)) self.assertEqual(md.data(PyMimeData.MIME_TYPE).data(), dumps(int) + dumps(0))
def test_nopickle(self): md = PyMimeData(data=0, pickle=False) self.assertEqual(md._local_instance, 0) self.assertTrue(md.hasFormat(PyMimeData.NOPICKLE_MIME_TYPE)) self.assertFalse(md.hasFormat(PyMimeData.MIME_TYPE)) self.assertEqual(bytes(md.data(PyMimeData.NOPICKLE_MIME_TYPE)), str(id(0)))
def test_pickle(self): md = PyMimeData(data=0) self.assertEqual(md._local_instance, 0) self.assertTrue(md.hasFormat(PyMimeData.MIME_TYPE)) self.assertFalse(md.hasFormat(PyMimeData.NOPICKLE_MIME_TYPE)) self.assertEqual(bytes(md.data(PyMimeData.MIME_TYPE)), dumps(int) + dumps(0))
def test_cant_pickle(self): unpicklable = lambda: None md = PyMimeData(data=unpicklable) self.assertEqual(md._local_instance, unpicklable) self.assertTrue(md.hasFormat(PyMimeData.NOPICKLE_MIME_TYPE)) self.assertFalse(md.hasFormat(PyMimeData.MIME_TYPE)) self.assertEqual(bytes(md.data(PyMimeData.NOPICKLE_MIME_TYPE)), str(id(unpicklable)))
def test_nopickle(self): md = PyMimeData(data=0, pickle=False) self.assertEqual(md._local_instance, 0) self.assertTrue(md.hasFormat(PyMimeData.NOPICKLE_MIME_TYPE)) self.assertFalse(md.hasFormat(PyMimeData.MIME_TYPE)) self.assertEqual( md.data(PyMimeData.NOPICKLE_MIME_TYPE).data(), str2bytes(str(id(0))) )