add tests

This commit is contained in:
moririn2528
2023-09-04 18:59:17 +09:00
parent 6928e0c304
commit da38286b69
3 changed files with 138 additions and 229 deletions
+63
View File
@@ -9,6 +9,7 @@ from optuna.study import StudyDirection
from optuna_dashboard._app import create_app
from optuna_dashboard._app import create_new_study
from optuna_dashboard.preferential import create_study
from optuna_dashboard._preference_setting import register_output_component
from .wsgi_client import send_request
@@ -151,6 +152,68 @@ class APITestCase(TestCase):
assert better.number == 2
assert worse.number == 1
def test_change_component(self) -> None:
storage = optuna.storages.InMemoryStorage()
study = create_study(storage=storage)
register_output_component(study, "Note")
for _ in range(3):
trial = study.ask()
study.mark_comparison_ready(trial)
app = create_app(storage)
study_id = study._study._study_id
status, _, _ = send_request(
app,
f"/api/studies/{study_id}/component",
"POST",
body=json.dumps({"component_type": "Artifact", "artifact_key": "image"}),
content_type="application/json",
)
self.assertEqual(status, 204)
status, _, body = send_request(
app,
f"/api/studies/{study_id}",
"GET",
content_type="application/json",
)
self.assertEqual(status, 200)
study_detail = json.loads(body)
assert study_detail["feedback_component_type"] == "Artifact"
assert study_detail["feedback_artifact_key"] == "image"
def test_change_component_type_only(self) -> None:
storage = optuna.storages.InMemoryStorage()
study = create_study(storage=storage)
register_output_component(study, "Artifact", "audio")
for _ in range(3):
trial = study.ask()
study.mark_comparison_ready(trial)
app = create_app(storage)
study_id = study._study._study_id
status, _, _ = send_request(
app,
f"/api/studies/{study_id}/component",
"POST",
body=json.dumps({"component_type": "Note"}),
content_type="application/json",
)
self.assertEqual(status, 204)
status, _, body = send_request(
app,
f"/api/studies/{study_id}",
"GET",
content_type="application/json",
)
self.assertEqual(status, 200)
study_detail = json.loads(body)
assert study_detail["feedback_component_type"] == "Note"
assert study_detail["feedback_artifact_key"] == "audio"
def test_skip_trial(self) -> None:
storage = optuna.storages.InMemoryStorage()
study = create_study(storage=storage)