示例#1
0
 def test(obj):
     self.dump(obj)
     with (open(FILE_SERIALIZE, "rb")) as fd:
         new_obj = rpickle.load(fd)
     self.assertTrue(new_obj.equals(obj))
     for key, value in new_obj.__dict__.items():
         is_primitive = any([isinstance(value, t)
               for t in [int, str, float]])
         if not is_primitive:
             false = id(new_obj.__dict__[key]) ==  id(obj.__dict__[key])
             self.assertFalse(false)
示例#2
0
 def testRPickleSucceeds(self):
     if IGNORE_TEST:
         return
     if not IS_TEST_PICKLE:
         return
     if IS_SERIALIZE:
         obj = _DClass()
         with (open(FILE_SERIALIZE2, "wb")) as fd:
             rpickle.dump(obj, fd)
     else:
         with (open(FILE_SERIALIZE2, "rb")) as fd:
             new_obj = rpickle.load(fd)
         try:
             _ = new_obj.get()
             self.assertTrue(True)  # Should get here
         except:
             self.assertTrue(False)  # Should not fail
示例#3
0
    def deserialize(cls, path):
        """
        Deserialize the model from a path.

        Parameters
        ----------
        path: str
            File path

        Return
        ------
        ModelFitter
            Model is initialized.
        """
        with open(path, "rb") as fd:
            fitter = rpickle.load(fd)
        fitter.initializeRoadRunnerModel()
        return fitter