def testDump(self): try: obj = self.Type() self.assertIsInstance(obj, self.Type) if issubclass(self.Type, core.Unpicklable): return except TypeError as e: self.logger.debug('PicklingError: Not testing {} because its init failed: {}'.format(self.Type, str(e))) return with tempfile.NamedTemporaryFile(mode='wb', delete=False) as dump_file: core.dump(obj, dump_file) dump_file.close() f = open(dump_file.name, 'rb') unpickled = core.load(f) self.assertEqual(obj.__class__, unpickled.__class__) os.unlink(dump_file.name)
def testDump(basicinterface_subclass): try: obj = basicinterface_subclass() assert isinstance(obj, basicinterface_subclass) if issubclass(basicinterface_subclass, core.Unpicklable): return except TypeError as e: logger = getLogger('pymortests.core.pickling') logger.debug('PicklingError: Not testing {} because its init failed: {}'.format(basicinterface_subclass, str(e))) return with tempfile.NamedTemporaryFile(mode='wb', delete=False) as dump_file: core.dump(obj, dump_file) dump_file.close() f = open(dump_file.name, 'rb') unpickled = core.load(f) assert obj.__class__ == unpickled.__class__ os.unlink(dump_file.name)