mirror of
https://github.com/wassname/optuna-dashboard.git
synced 2026-09-09 11:28:14 +08:00
Convert Dashboard's ArtifactNotFound exception to Optuna's one
This commit is contained in:
@@ -9,6 +9,9 @@ from optuna.artifacts import upload_artifact
|
||||
from optuna.storages import BaseStorage
|
||||
from optuna_dashboard._app import create_app
|
||||
from optuna_dashboard.artifact import _backend
|
||||
from optuna_dashboard.artifact._backend_to_store import to_artifact_store
|
||||
from optuna_dashboard.artifact.file_system import FileSystemBackend
|
||||
from optuna_dashboard.artifact import upload_artifact as dashboard_upload_artifact
|
||||
import pytest
|
||||
|
||||
from ..wsgi_client import send_request
|
||||
@@ -298,3 +301,31 @@ def test_delete_trial_artifact() -> None:
|
||||
"DELETE",
|
||||
)
|
||||
assert status == 404
|
||||
|
||||
|
||||
# Check the backward compatibility with the artifact backend.
|
||||
def test_delete_artifact_with_dashboard_file_system_backend() -> None:
|
||||
storage = optuna.storages.InMemoryStorage()
|
||||
study = optuna.create_study(storage=storage)
|
||||
trial = study.ask()
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
artifact_backend = FileSystemBackend(tmpdir)
|
||||
with tempfile.NamedTemporaryFile() as f:
|
||||
f.write(b"dummy_content")
|
||||
f.flush()
|
||||
artifact_id = dashboard_upload_artifact(artifact_backend, trial, f.name)
|
||||
|
||||
artifact_store = to_artifact_store(artifact_backend)
|
||||
app = create_app(storage, artifact_store)
|
||||
status, _, _ = send_request(
|
||||
app,
|
||||
f"/api/artifacts/{study._study_id}/{trial._trial_id}/{artifact_id}",
|
||||
"DELETE",
|
||||
)
|
||||
assert status == 204
|
||||
status, _, _ = send_request(
|
||||
app,
|
||||
f"/api/artifacts/{study._study_id}/{trial._trial_id}/{artifact_id}",
|
||||
"DELETE",
|
||||
)
|
||||
assert status == 404
|
||||
|
||||
Reference in New Issue
Block a user