mirror of
https://github.com/wassname/optuna-dashboard.git
synced 2026-08-21 11:18:45 +08:00
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Callable
|
|
|
|
import optuna
|
|
from optuna_dashboard.preferential._system_attrs import get_preferences
|
|
from optuna_dashboard.preferential._system_attrs import report_preferences
|
|
|
|
from ..storage_supplier import parametrize_storages
|
|
from ..storage_supplier import StorageSupplier
|
|
|
|
|
|
@parametrize_storages
|
|
def test_report_and_get_preferences(storage_supplier: Callable[[], StorageSupplier]) -> None:
|
|
with storage_supplier() as storage:
|
|
study = optuna.create_study(storage=storage)
|
|
study.ask()
|
|
study.ask()
|
|
|
|
study_id = study._study_id
|
|
|
|
assert len(get_preferences(storage.get_study_system_attrs(study_id))) == 0
|
|
|
|
better, worse = study.trials[0], study.trials[1]
|
|
report_preferences(study_id, storage, [(better.number, worse.number)])
|
|
assert len(get_preferences(storage.get_study_system_attrs(study_id))) == 1
|
|
|
|
actual_better, actual_worse = get_preferences(storage.get_study_system_attrs(study_id))[0]
|
|
assert actual_better == better.number
|
|
assert actual_worse == worse.number
|