add tests

This commit is contained in:
Hiroki Takizawa
2023-12-06 16:36:00 +09:00
committed by GitHub
parent 2a03cd5285
commit 8eac8fc6f3
+50 -2
View File
@@ -1,12 +1,60 @@
from typing import Any
import optuna
from optuna.trial import TrialState
from optuna_dashboard._app import create_app
import pytest
from .wsgi_client import send_request
def test_download_csv_no_trial() -> None:
def objective(trial: optuna.Trial) -> float:
x = trial.suggest_float("x", -100, 100)
y = trial.suggest_categorical("y", [-1, 0, 1])
return x**2 + y
storage = optuna.storages.InMemoryStorage()
study = optuna.create_study(storage=storage)
study.optimize(objective, n_trials=0)
app = create_app(storage)
status, _, body = send_request(
app,
"/csv/0",
"GET",
content_type="application/json",
)
assert status == 200
def test_download_csv_all_waiting() -> None:
storage = optuna.storages.InMemoryStorage()
study = optuna.create_study(storage=storage)
study.add_trial(optuna.trial.create_trial(state=TrialState.WAITING))
app = create_app(storage)
status, _, body = send_request(
app,
"/csv/0",
"GET",
content_type="application/json",
)
assert status == 200
def test_download_csv_all_running() -> None:
storage = optuna.storages.InMemoryStorage()
study = optuna.create_study(storage=storage)
study.add_trial(optuna.trial.create_trial(state=TrialState.RUNNING))
app = create_app(storage)
status, _, body = send_request(
app,
"/csv/0",
"GET",
content_type="application/json",
)
assert status == 200
@pytest.mark.parametrize("id", [0, 1])
def test_download_csv_fail(id: int) -> None:
def objective(trial: optuna.Trial) -> float:
@@ -47,7 +95,7 @@ def test_download_csv_multi_obj(is_multi_obj: bool) -> None:
app = create_app(storage)
status, _, body = send_request(
app,
f"/csv/{0}",
"/csv/0",
"GET",
content_type="application/json",
)
@@ -68,7 +116,7 @@ def test_download_csv_user_attr() -> None:
app = create_app(storage)
status, _, body = send_request(
app,
f"/csv/{0}",
"/csv/0",
"GET",
content_type="application/json",
)