def testCloneModelWithCheckpoint(self):
        checkpointMgr = ModelCheckpointMgr()

        modelID = uuid.uuid1().hex
        destModelID = uuid.uuid1().hex

        # Create the source model with meta-info only (no checkpoint)
        modelDef = {'a': 1, 'b': 2, 'c': 3}
        checkpointMgr.define(modelID, modelDef)

        # Create a model that we can clone
        model1 = ModelFactory.create(self._getModelParams("variant1"))
        checkpointMgr.save(modelID, model1, attributes="attributes1")

        # Clone the source model
        checkpointMgr.clone(modelID, destModelID)

        # Discard the source model checkpoint
        checkpointMgr.remove(modelID)

        # Verify that the destination model's definition is the same as the
        # source model's
        destModelDef = checkpointMgr.loadModelDefinition(destModelID)
        self.assertDictEqual(destModelDef, modelDef)

        # Verify that the destination model's attributes match the source's
        attributes = checkpointMgr.loadCheckpointAttributes(destModelID)
        self.assertEqual(attributes, "attributes1")

        # Attempt to load the cloned model from checkpoint
        model = checkpointMgr.load(destModelID)
        self.assertEqual(str(model.getFieldInfo()), str(model1.getFieldInfo()))
  def testCloneModelWithCheckpoint(self):
    checkpointMgr = ModelCheckpointMgr()

    modelID = uuid.uuid1().hex
    destModelID = uuid.uuid1().hex

    # Create the source model with meta-info only (no checkpoint)
    modelDef = {'a': 1, 'b': 2, 'c':3}
    checkpointMgr.define(modelID, modelDef)

    # Create a model that we can clone
    model1 = ModelFactory.create(self._getModelParams("variant1"))
    checkpointMgr.save(modelID, model1, attributes="attributes1")

    # Clone the source model
    checkpointMgr.clone(modelID, destModelID)

    # Discard the source model checkpoint
    checkpointMgr.remove(modelID)

    # Verify that the destination model's definition is the same as the
    # source model's
    destModelDef = checkpointMgr.loadModelDefinition(destModelID)
    self.assertDictEqual(destModelDef, modelDef)

    # Verify that the destination model's attributes match the source's
    attributes = checkpointMgr.loadCheckpointAttributes(destModelID)
    self.assertEqual(attributes, "attributes1")

    # Attempt to load the cloned model from checkpoint
    model = checkpointMgr.load(destModelID)
    self.assertEqual(str(model.getFieldInfo()), str(model1.getFieldInfo()))
  def testRemoveAndGetModelIDs(self):
    """
    Test getModelIDs and remove methods
    """
    checkpointMgr = ModelCheckpointMgr()

    # Should be empty at first
    ids = checkpointMgr.getModelIDs()
    self.assertListEqual(ids, [])


    # Create some checkpoints using meta info
    expModelIDs = [uuid.uuid1().hex, uuid.uuid1().hex]
    expModelIDs.sort()
    for modelID in expModelIDs:
      checkpointMgr.define(modelID, definition={'a':1})

    ids = checkpointMgr.getModelIDs()
    ids.sort()
    self.assertListEqual(ids, expModelIDs)


    # Delete one of them
    checkpointMgr.remove(expModelIDs[0])
    expModelIDs.remove(expModelIDs[0])

    ids = checkpointMgr.getModelIDs()
    ids.sort()
    self.assertListEqual(ids, expModelIDs)


    # Delete all of them
    for modelID in expModelIDs:
      checkpointMgr.remove(modelID)
    ids = checkpointMgr.getModelIDs()
    self.assertListEqual(ids, [])


    # If we try and delete a non-existing model, should get an exception
    self.assertRaises(ModelNotFound, checkpointMgr.remove, "IDx")
  def testRemoveAndGetModelIDs(self):
    """
    Test getModelIDs and remove methods
    """
    checkpointMgr = ModelCheckpointMgr()

    # Should be empty at first
    ids = checkpointMgr.getModelIDs()
    self.assertListEqual(ids, [])


    # Create some checkpoints using meta info
    expModelIDs = [uuid.uuid1().hex, uuid.uuid1().hex]
    expModelIDs.sort()
    for modelID in expModelIDs:
      checkpointMgr.define(modelID, definition={'a':1})

    ids = checkpointMgr.getModelIDs()
    ids.sort()
    self.assertListEqual(ids, expModelIDs)


    # Delete one of them
    checkpointMgr.remove(expModelIDs[0])
    expModelIDs.remove(expModelIDs[0])

    ids = checkpointMgr.getModelIDs()
    ids.sort()
    self.assertListEqual(ids, expModelIDs)


    # Delete all of them
    for modelID in expModelIDs:
      checkpointMgr.remove(modelID)
    ids = checkpointMgr.getModelIDs()
    self.assertListEqual(ids, [])


    # If we try and delete a non-existing model, should get an exception
    self.assertRaises(ModelNotFound, checkpointMgr.remove, "IDx")