Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for proxy_trial_artifact #714

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 49 additions & 6 deletions python_tests/artifact/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,18 @@ def test_list_trial_artifacts(init_storage_with_artifact_meta: MagicMock) -> Non
]


def test_artifact_store_none() -> None:
def test_study_artifact_store_none() -> None:
storage = optuna.storages.InMemoryStorage()
app = create_app(storage)
status, _, body = send_request(
app,
"/artifacts/0/0",
"GET",
content_type="application/json",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this is unnecessary because the content is not JSON.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true 👍 Good catch.

)
assert status == 400


def test_artifact_not_found() -> None:
def test_study_artifact_not_found() -> None:
storage = optuna.storages.InMemoryStorage()
study = optuna.create_study(storage=storage)
with tempfile.TemporaryDirectory() as tmpdir:
Expand All @@ -111,12 +110,11 @@ def test_artifact_not_found() -> None:
app,
f"/artifacts/{study._study_id}/abc123",
"GET",
content_type="application/json",
)
assert status == 404


def test_successful_artifact_retrieval() -> None:
def test_successful_study_artifact_retrieval() -> None:
storage = optuna.storages.InMemoryStorage()
study = optuna.create_study(storage=storage)
with tempfile.TemporaryDirectory() as tmpdir:
Expand All @@ -130,7 +128,52 @@ def test_successful_artifact_retrieval() -> None:
app,
f"/artifacts/{study._study_id}/{artifact_id}",
"GET",
content_type="application/json",
)
assert status == 200
assert body == b"dummy_content"


def test_trial_artifact_store_none() -> None:
storage = optuna.storages.InMemoryStorage()
app = create_app(storage)
status, _, body = send_request(
app,
"/artifacts/0/0/0",
"GET",
)
assert status == 400


def test_trial_artifact_not_found() -> None:
storage = optuna.storages.InMemoryStorage()
study = optuna.create_study(storage=storage)
trial = study.ask()
with tempfile.TemporaryDirectory() as tmpdir:
artifact_store = FileSystemArtifactStore(tmpdir)
app = create_app(storage, artifact_store)
status, _, body = send_request(
app,
f"/artifacts/{study._study_id}/{trial._trial_id}/abc123",
"GET",
)
assert status == 404


def test_successful_trial_artifact_retrieval() -> None:
storage = optuna.storages.InMemoryStorage()
study = optuna.create_study(storage=storage)
trial = study.ask()
with tempfile.TemporaryDirectory() as tmpdir:
artifact_store = FileSystemArtifactStore(tmpdir)
with tempfile.NamedTemporaryFile() as f:
f.write(b"dummy_content")
f.flush()
artifact_id = upload_artifact(trial, f.name, artifact_store=artifact_store)
app = create_app(storage, artifact_store)
status, _, body = send_request(
app,
f"/artifacts/{study._study_id}/{trial._trial_id}/{artifact_id}",
"GET",
)
assert status == 200
assert body == b"dummy_content"