Fixed tests

This commit is contained in:
gen740
2022-12-01 12:28:44 +09:00
parent 91a8de1d55
commit 188b88f26b
2 changed files with 20 additions and 11 deletions
-5
View File
@@ -249,11 +249,6 @@ def create_app(storage: BaseStorage, debug: bool = False) -> Bottle:
return {"reason": "You need to set study_name and direction"}
try:
# if version.parse(optuna_ver) >= version.Version("3.0.0rc0.dev"):
# frozen_studies = storage.get_all_studies() # type: ignore
# return [_frozen_study_to_study_summary(s) for s in frozen_studies]
# elif version.parse(optuna_ver) >= version.Version("3.0.0b0.dev"):
# return storage.get_all_study_summaries(include_best_trial=False) # type: ignore
if version.parse(optuna_ver) >= version.Version("3.1.0.dev"):
study_id = storage.create_new_study(
study_name,
+20 -6
View File
@@ -2,9 +2,11 @@ import json
from unittest import TestCase
import optuna
from optuna.study import StudyDirection
from optuna import get_all_study_summaries
from optuna.study import StudyDirection
from optuna.version import __version__ as optuna_ver
from optuna_dashboard._app import create_app
from packaging import version
from .wsgi_client import send_request
@@ -17,8 +19,13 @@ def objective(trial: optuna.trial.Trial) -> float:
class APITestCase(TestCase):
def test_get_study_summaries(self) -> None:
storage = optuna.storages.InMemoryStorage()
storage.create_new_study(study_name="foo1", directions=[StudyDirection.MINIMIZE])
storage.create_new_study(study_name="foo2", directions=[StudyDirection.MINIMIZE])
if version.parse(optuna_ver) >= version.Version("3.1.0.dev"):
storage.create_new_study(study_name="foo1", directions=[StudyDirection.MINIMIZE])
storage.create_new_study(study_name="foo2", directions=[StudyDirection.MINIMIZE])
else:
storage.create_new_study("foo1")
storage.create_new_study("foo2")
app = create_app(storage)
status, _, body = send_request(
@@ -127,7 +134,10 @@ class APITestCase(TestCase):
def test_create_study_duplicated(self) -> None:
storage = optuna.storages.InMemoryStorage()
storage.create_new_study(study_name="foo", directions=[StudyDirection.MINIMIZE])
if version.parse(optuna_ver) >= version.Version("3.1.0.dev"):
storage.create_new_study(study_name="foo", directions=[StudyDirection.MINIMIZE])
else:
storage.create_new_study("foo")
self.assertEqual(len(get_all_study_summaries(storage)), 1)
app = create_app(storage)
@@ -147,8 +157,12 @@ class APITestCase(TestCase):
def test_delete_study(self) -> None:
storage = optuna.storages.InMemoryStorage()
storage.create_new_study(study_name="foo1", directions=[StudyDirection.MINIMIZE])
storage.create_new_study(study_name="foo2", directions=[StudyDirection.MINIMIZE])
if version.parse(optuna_ver) >= version.Version("3.1.0.dev"):
storage.create_new_study(study_name="foo1", directions=[StudyDirection.MINIMIZE])
storage.create_new_study(study_name="foo2", directions=[StudyDirection.MINIMIZE])
else:
storage.create_new_study(study_name="foo1")
storage.create_new_study(study_name="foo2")
self.assertEqual(len(get_all_study_summaries(storage)), 2)
app = create_app(storage)