Skip to content

Commit

Permalink
test: test path exists
Browse files Browse the repository at this point in the history
Signed-off-by: Inhyuk Andy Cho <andy.inhyuk.jo@intel.com>
  • Loading branch information
cih9088 committed Apr 19, 2023
1 parent 862f086 commit 250bf4e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions tests/unit/core/data/manager/test_dataset_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
import shutil
from typing import List
from tempfile import TemporaryDirectory

import datumaro as dm
import pytest
Expand Down Expand Up @@ -76,6 +77,12 @@ def test_get_image_path(self, task, subset):
)
assert random_data is None

with TemporaryDirectory() as temp_dir:
random_data = DatasetManager.get_image_path(
generate_datumaro_dataset_item(item_id="0", subset=subset, task=task, temp_dir=temp_dir)
)
assert random_data is not None

@e2e_pytest_unit
@pytest.mark.parametrize("task", AVAILABLE_TASKS)
@pytest.mark.parametrize("subset", AVAILABLE_SUBSETS)
Expand Down
11 changes: 10 additions & 1 deletion tests/unit/core/data/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
from typing import List
from typing import List, Optional
import os

import cv2
import datumaro as dm
import numpy as np

Expand Down Expand Up @@ -86,6 +88,7 @@ def generate_datumaro_dataset_item(
task: str,
image_shape: np.array = np.array((5, 5, 3)),
mask_shape: np.array = np.array((5, 5)),
temp_dir: Optional[str] = None,
) -> dm.DatasetItem:
"""Generate Datumaro DatasetItem.
Expand All @@ -95,6 +98,7 @@ def generate_datumaro_dataset_item(
task (str): task type, e.g. "classification"
image_shape (np.array): the shape of image.
image_shape (np.array): the shape of mask.
temp_dir (str): directory to save image data
Returns:
dm.DatasetItem: Datumaro DatasetItem
Expand All @@ -105,6 +109,11 @@ def generate_datumaro_dataset_item(
"segmentation": dm.Mask(np.zeros(mask_shape)),
}

if temp_dir:
path = os.path.join(temp_dir, "image.png")
cv2.imwrite(path, np.ones(image_shape))
return dm.DatasetItem(id=item_id, subset=subset, image=path, annotations=[ann_task_dict[task]])

return dm.DatasetItem(id=item_id, subset=subset, image=np.ones(image_shape), annotations=[ann_task_dict[task]])


Expand Down

0 comments on commit 250bf4e

Please sign in to comment.