Esempio n. 1
0
    def test_delete(self):
        # check project is not initialized if wrong home
        Config().set_home(os.path.join("does", "not", "exist"))
        failed = False
        try:
            delete()
        except InvalidProjectPath:
            failed = True
        assert failed

        # check for snapshot id that does not exist
        Config().set_home(self.temp_dir)
        failed = False
        try:
            delete(snapshot_id="does_not_exist")
        except EntityNotFound:
            failed = True
        assert failed

        # delete a snapshot
        test_filepath = os.path.join(self.temp_dir, "script.py")
        with open(test_filepath, "wb") as f:
            f.write(to_bytes("import numpy\n"))
            f.write(to_bytes("import sklearn\n"))

        snapshot_obj = create(message="delete_test")

        snapshot_list_before_delete = ls(filter='delete_test')

        delete(snapshot_id=snapshot_obj.id)

        snapshot_list_after_delete = ls(filter='delete_test')

        assert len(snapshot_list_before_delete) == 1
        assert len(snapshot_list_after_delete) == 0
Esempio n. 2
0
    def test_update(self):
        # check project is not initialized if wrong home
        Config().set_home(os.path.join("does", "not", "exist"))
        failed = False
        try:
            delete()
        except InvalidProjectPath:
            failed = True
        assert failed

        # check for snapshot id that does not exist
        Config().set_home(self.temp_dir)
        failed = False
        try:
            update(snapshot_id="does_not_exist")
        except EntityNotFound:
            failed = True
        assert failed
        test_config = {"config_foo": "bar"}
        test_stats = {"stats_foo": "bar"}
        test_message = "new_message"
        test_label = "new_label"
        # update both message and label
        snapshot_entity = self.__setup()

        updated_snapshot_obj = update(snapshot_id=snapshot_entity.id,
                                      message=test_message,
                                      label=test_label)

        assert updated_snapshot_obj.id == snapshot_entity.id
        assert updated_snapshot_obj.message == test_message
        assert updated_snapshot_obj.label == test_label

        # update message
        snapshot_obj_1 = create(message="test")

        updated_snapshot_obj_1 = update(snapshot_id=snapshot_obj_1.id,
                                        message=test_message)

        assert updated_snapshot_obj_1.id == snapshot_obj_1.id
        assert updated_snapshot_obj_1.message == test_message

        # update label
        snapshot_obj_2 = create(message="test")

        updated_snapshot_obj_2 = update(snapshot_id=snapshot_obj_2.id,
                                        label=test_label)

        assert updated_snapshot_obj_2.id == snapshot_obj_2.id
        assert updated_snapshot_obj_2.message == test_message

        # test config
        snapshot_obj_3 = create(message="test")

        updated_snapshot_obj_3 = update(snapshot_id=snapshot_obj_3.id,
                                        config=test_config)

        assert updated_snapshot_obj_3.id == snapshot_obj_3.id
        assert updated_snapshot_obj_3.config == test_config

        # test stats
        snapshot_obj_4 = create(message="test")

        updated_snapshot_obj_4 = update(snapshot_id=snapshot_obj_4.id,
                                        stats=test_stats)

        assert updated_snapshot_obj_4.id == snapshot_obj_4.id
        assert updated_snapshot_obj_4.stats == test_stats