Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya Trushkin <ilya.trushkin@intel.com>
  • Loading branch information
itrushkin committed Jul 29, 2024
1 parent 95d7c18 commit 1874a9c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
Binary file added tests/assets/image_dir_dataset/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/assets/image_dir_dataset/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 31 additions & 12 deletions tests/unit/test_image_dir_format.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
from unittest import TestCase

import numpy as np
import pytest

from datumaro.components.dataset import Dataset, StreamDataset
from datumaro.components.dataset_base import DatasetItem
from datumaro.components.media import Image
from datumaro.components.project import Dataset
from datumaro.plugins.data_formats.image_dir import ImageDirExporter

from ..requirements import Requirements, mark_requirement

from tests.utils.test_utils import TestDir, check_save_and_load
from tests.utils.assets import get_test_asset_path
from tests.utils.test_utils import TestDir, check_save_and_load, compare_datasets

DUMMY_DATASET_DIR = get_test_asset_path("image_dir_dataset")
FORMAT_NAME = "image_dir"


class ImageDirFormatTest(TestCase):
class ImageDirFormatTest:
@mark_requirement(Requirements.DATUM_GENERAL_REQ)
def test_can_load(self):
def test_can_load(self, helper_tc):
dataset = Dataset.from_iterable(
[
DatasetItem(id=1, media=Image.from_numpy(data=np.ones((10, 6, 3)))),
Expand All @@ -24,16 +28,31 @@ def test_can_load(self):

with TestDir() as test_dir:
check_save_and_load(
self,
helper_tc,
dataset,
ImageDirExporter.convert,
test_dir,
importer="image_dir",
importer=FORMAT_NAME,
require_media=True,
)

@mark_requirement(Requirements.DATUM_GENERAL_REQ)
def test_can_save_dataset_with_cyrillic_and_spaces_in_filename(self):
@pytest.mark.parametrize("dataset_cls, is_stream", [(Dataset, False), (StreamDataset, True)])
def test_can_import(self, dataset_cls, is_stream, helper_tc):
expected_dataset = Dataset.from_iterable(
[
DatasetItem(id="1", media=Image.from_numpy(data=np.zeros((4, 3, 3)), ext=".JPEG")),
DatasetItem(id="2", media=Image.from_numpy(data=np.zeros((3, 4, 3)), ext=".bmp")),
]
)

actual_dataset = dataset_cls.import_from(DUMMY_DATASET_DIR, FORMAT_NAME)

assert actual_dataset.is_stream == is_stream
compare_datasets(helper_tc, expected_dataset, actual_dataset)

@mark_requirement(Requirements.DATUM_GENERAL_REQ)
def test_can_save_dataset_with_cyrillic_and_spaces_in_filename(self, helper_tc):
dataset = Dataset.from_iterable(
[
DatasetItem(
Expand All @@ -44,11 +63,11 @@ def test_can_save_dataset_with_cyrillic_and_spaces_in_filename(self):

with TestDir() as test_dir:
check_save_and_load(
self, dataset, ImageDirExporter.convert, test_dir, importer="image_dir"
helper_tc, dataset, ImageDirExporter.convert, test_dir, importer=FORMAT_NAME
)

@mark_requirement(Requirements.DATUM_GENERAL_REQ)
def test_can_save_and_load_image_with_arbitrary_extension(self):
def test_can_save_and_load_image_with_arbitrary_extension(self, helper_tc):
dataset = Dataset.from_iterable(
[
DatasetItem(id="1", media=Image.from_numpy(data=np.zeros((4, 3, 3)), ext=".JPEG")),
Expand All @@ -58,10 +77,10 @@ def test_can_save_and_load_image_with_arbitrary_extension(self):

with TestDir() as test_dir:
check_save_and_load(
self,
helper_tc,
dataset,
ImageDirExporter.convert,
test_dir,
importer="image_dir",
importer=FORMAT_NAME,
require_media=True,
)

0 comments on commit 1874a9c

Please sign in to comment.