mirror of
https://github.com/wassname/optuna-dashboard.git
synced 2026-09-13 12:50:51 +08:00
add test for skip api
This commit is contained in:
@@ -40,7 +40,8 @@ from .artifact._backend import register_artifact_route
|
||||
from .artifact._backend_to_store import to_artifact_store
|
||||
from .preferential._study import _SYSTEM_ATTR_PREFERENTIAL_STUDY
|
||||
from .preferential._study import get_best_trials as get_best_preferential_trials
|
||||
from .preferential._system_attrs import report_preferences, report_skip
|
||||
from .preferential._system_attrs import report_preferences
|
||||
from .preferential._system_attrs import report_skip
|
||||
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
|
||||
@@ -12,11 +12,9 @@ from optuna.samplers import BaseSampler
|
||||
from optuna.samplers import RandomSampler
|
||||
from optuna.trial import FrozenTrial
|
||||
from optuna.trial import TrialState
|
||||
from optuna_dashboard.preferential._system_attrs import (
|
||||
get_preferences,
|
||||
report_preferences,
|
||||
_SYSTEM_ATTR_SKIP_TRIAL,
|
||||
)
|
||||
from optuna_dashboard.preferential._system_attrs import _SYSTEM_ATTR_SKIP_TRIAL
|
||||
from optuna_dashboard.preferential._system_attrs import get_preferences
|
||||
from optuna_dashboard.preferential._system_attrs import report_preferences
|
||||
|
||||
|
||||
_logger = logging.get_logger(__name__)
|
||||
|
||||
@@ -151,6 +151,30 @@ class APITestCase(TestCase):
|
||||
assert better.number == 2
|
||||
assert worse.number == 1
|
||||
|
||||
def test_skip_trial(self) -> None:
|
||||
storage = optuna.storages.InMemoryStorage()
|
||||
study = create_study(storage=storage)
|
||||
trials: list[optuna.Trial] = []
|
||||
for _ in range(3):
|
||||
trial = study.ask()
|
||||
study.mark_comparison_ready(trial)
|
||||
trials.append(trial)
|
||||
|
||||
app = create_app(storage)
|
||||
study_id = study._study._study_id
|
||||
status, _, _ = send_request(
|
||||
app,
|
||||
f"/api/studies/{study_id}/{trials[1]._trial_id}/skip",
|
||||
"POST",
|
||||
content_type="application/json",
|
||||
)
|
||||
self.assertEqual(status, 204)
|
||||
|
||||
best_trials = study.best_trials
|
||||
assert len(best_trials) == 2
|
||||
assert best_trials[0].number == 0
|
||||
assert best_trials[1].number == 2
|
||||
|
||||
def test_create_study(self) -> None:
|
||||
for name, directions, expected_status in [
|
||||
("single-objective success", ["minimize"], 201),
|
||||
|
||||
Reference in New Issue
Block a user