mirror of
https://github.com/wassname/optuna-dashboard.git
synced 2026-09-11 12:30:25 +08:00
Merge pull request #675 from keisuke-umezawa/feature/add-db-import-test
Add an e2e test to upload a db file in standalone dashboard
This commit is contained in:
@@ -16,7 +16,7 @@ jobs:
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
matrix:
|
||||
optuna-version: ['optuna==2.10.0', 'git+https://github.com/optuna/optuna.git']
|
||||
optuna-version: ['git+https://github.com/optuna/optuna.git']
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
from playwright.sync_api import Page
|
||||
import pytest
|
||||
|
||||
@@ -20,3 +23,52 @@ def test_home(
|
||||
title = element.text_content()
|
||||
assert title is not None
|
||||
assert title == "Optuna Dashboard (Wasm ver.)"
|
||||
|
||||
|
||||
def test_load_storage(
|
||||
page: Page,
|
||||
server_url: str,
|
||||
) -> None:
|
||||
study_name = "single-objective"
|
||||
url = f"{server_url}"
|
||||
|
||||
def create_storage_file(filename: str):
|
||||
import optuna
|
||||
|
||||
storage = optuna.storages.RDBStorage(f"sqlite:///{filename}")
|
||||
study = optuna.create_study(study_name=study_name, storage=storage)
|
||||
|
||||
def objective(trial: optuna.Trial) -> float:
|
||||
x1 = trial.suggest_float("x1", 0, 10)
|
||||
x2 = trial.suggest_float("x2", 0, 10)
|
||||
return (x1 - 2) ** 2 + (x2 - 5) ** 2
|
||||
|
||||
study.optimize(objective, n_trials=100)
|
||||
|
||||
with tempfile.TemporaryDirectory() as dir:
|
||||
with tempfile.NamedTemporaryFile() as fp:
|
||||
filename = fp.name
|
||||
path = os.path.join(dir, filename)
|
||||
create_storage_file(filename)
|
||||
page.goto(url)
|
||||
with page.expect_file_chooser() as fc_info:
|
||||
page.get_by_role(
|
||||
"button",
|
||||
name="Load an Optuna Storage Drag your SQLite3 file here or click to browse.",
|
||||
).click()
|
||||
file_chooser = fc_info.value
|
||||
file_chooser.set_files(path)
|
||||
|
||||
page.get_by_role("link", name=study_name).click()
|
||||
|
||||
def count_components(page: Page, component_name: str):
|
||||
component_count = page.evaluate(
|
||||
f"""() => {{
|
||||
const components = document.querySelectorAll('.{component_name}');
|
||||
return components.length;
|
||||
}}"""
|
||||
)
|
||||
return component_count
|
||||
|
||||
count = count_components(page, "MuiCardContent-root")
|
||||
assert count == 6
|
||||
|
||||
Reference in New Issue
Block a user