Add ArtifactNotFound exception

This commit is contained in:
c-bata
2023-06-02 18:02:55 +09:00
parent 1f79649cb1
commit 9646f6367e
7 changed files with 101 additions and 7 deletions
+6
View File
@@ -6,6 +6,7 @@ from unittest.mock import patch
import boto3
from moto import mock_s3
from optuna_dashboard.artifact.boto3 import Boto3Backend
from optuna_dashboard.artifact.exceptions import ArtifactNotFound
@mock_s3
@@ -63,3 +64,8 @@ class Boto3BackendTestCase(TestCase):
backend.remove(artifact_id)
objects = self.s3_client.list_objects(Bucket=self.bucket_name).get("Contents", [])
assert len([obj for obj in objects if obj["Key"] == artifact_id]) == 0
def test_file_not_found_exception(self) -> None:
backend = Boto3Backend(self.bucket_name)
with self.assertRaises(ArtifactNotFound):
backend.open("not-found-id")
@@ -3,6 +3,7 @@ import tempfile
from unittest import TestCase
from optuna_dashboard.artifact.file_system import FileSystemBackend
from optuna_dashboard.artifact.exceptions import ArtifactNotFound
class FileSystemBackendTestCase(TestCase):
@@ -20,3 +21,10 @@ class FileSystemBackendTestCase(TestCase):
with backend.open(artifact_id) as f:
actual = f.read()
self.assertEqual(actual, dummy_content)
def test_file_not_found(self) -> None:
backend = FileSystemBackend(self.dir.name)
with self.assertRaises(ArtifactNotFound):
backend.open("not-found-id")
with self.assertRaises(ArtifactNotFound):
backend.remove("not-found-id")