|
3 | 3 | # Copyright (C) 2023 Intel Corporation |
4 | 4 | # SPDX-License-Identifier: Apache-2.0 |
5 | 5 | # |
| 6 | +import tempfile |
| 7 | + |
6 | 8 | import numpy as np |
7 | 9 | import pytest |
8 | 10 |
|
@@ -95,48 +97,48 @@ def test_convert_action_cls_dataset_to_datumaro(mocker) -> None: |
95 | 97 | """Test convert_jester_dataset_to_datumaro function.""" |
96 | 98 |
|
97 | 99 | src_path = "dummy_src_path" |
98 | | - dst_path = "dummy_dst_path" |
99 | 100 | ann_file = "dummy_ann_file" |
100 | 101 |
|
101 | | - mocker.patch("otx.algorithms.action.utils.convert_public_data_to_cvat.open", return_value=MockFileObject()) |
102 | | - mocker.patch("otx.algorithms.action.utils.convert_public_data_to_cvat.pathlib.Path.mkdir", return_value=True) |
103 | | - # mocker.patch("otx.algorithms.action.utils.convert_public_data_to_cvat.os.makedirs", return_value=True) |
104 | | - mocker.patch("otx.algorithms.action.utils.convert_public_data_to_cvat.shutil.copy", return_value=True) |
105 | | - mocker.patch( |
106 | | - "otx.algorithms.action.utils.convert_public_data_to_cvat.generate_default_cvat_xml_fields", |
107 | | - return_value=([], (256, 256, 3), []), |
108 | | - ) |
109 | | - mocker.patch( |
110 | | - "otx.algorithms.action.utils.convert_public_data_to_cvat.os.listdir", return_value=(["frame0", "frame1"]) |
111 | | - ) |
112 | | - mocker.patch( |
113 | | - "otx.algorithms.action.utils.convert_public_data_to_cvat.etree.ElementTree", return_value=MockElementTree() |
114 | | - ) |
115 | | - convert_action_cls_dataset_to_datumaro(src_path, dst_path, ann_file) |
| 102 | + with tempfile.TemporaryDirectory() as dst_path: |
| 103 | + mocker.patch("otx.algorithms.action.utils.convert_public_data_to_cvat.open", return_value=MockFileObject()) |
| 104 | + mocker.patch("otx.algorithms.action.utils.convert_public_data_to_cvat.pathlib.Path.mkdir", return_value=True) |
| 105 | + # mocker.patch("otx.algorithms.action.utils.convert_public_data_to_cvat.os.makedirs", return_value=True) |
| 106 | + mocker.patch("otx.algorithms.action.utils.convert_public_data_to_cvat.shutil.copy", return_value=True) |
| 107 | + mocker.patch( |
| 108 | + "otx.algorithms.action.utils.convert_public_data_to_cvat.generate_default_cvat_xml_fields", |
| 109 | + return_value=([], (256, 256, 3), []), |
| 110 | + ) |
| 111 | + mocker.patch( |
| 112 | + "otx.algorithms.action.utils.convert_public_data_to_cvat.os.listdir", return_value=(["frame0", "frame1"]) |
| 113 | + ) |
| 114 | + mocker.patch( |
| 115 | + "otx.algorithms.action.utils.convert_public_data_to_cvat.etree.ElementTree", return_value=MockElementTree() |
| 116 | + ) |
| 117 | + convert_action_cls_dataset_to_datumaro(src_path, dst_path, ann_file) |
116 | 118 |
|
117 | 119 |
|
118 | 120 | @e2e_pytest_unit |
119 | 121 | def test_convert_ava_dataset_to_datumaro(mocker) -> None: |
120 | 122 | """Test convert_ava_dataset_to_datumaro function.""" |
121 | 123 |
|
122 | 124 | src_path = "dummy_src_path" |
123 | | - dst_path = "dummy_dst_path" |
124 | 125 | ann_file = "dummy_ann_file" |
125 | 126 |
|
126 | | - mocker.patch( |
127 | | - "otx.algorithms.action.utils.convert_public_data_to_cvat.read_ava_csv", |
128 | | - return_value={"video_0": {"frame_idx": [[0, 0, 1, 1, "action"]]}}, |
129 | | - ) |
130 | | - mocker.patch("otx.algorithms.action.utils.convert_public_data_to_cvat.os.listdir", return_value=["video_0"]) |
131 | | - mocker.patch("otx.algorithms.action.utils.convert_public_data_to_cvat.shutil.copytree", return_value=True) |
132 | | - mocker.patch( |
133 | | - "otx.algorithms.action.utils.convert_public_data_to_cvat.generate_default_cvat_xml_fields", |
134 | | - return_value=([], (256, 256, 3), []), |
135 | | - ) |
136 | | - mocker.patch( |
137 | | - "otx.algorithms.action.utils.convert_public_data_to_cvat.etree.ElementTree", return_value=MockElementTree() |
138 | | - ) |
139 | | - convert_ava_dataset_to_datumaro(src_path, dst_path, ann_file) |
| 127 | + with tempfile.TemporaryDirectory() as dst_path: |
| 128 | + mocker.patch( |
| 129 | + "otx.algorithms.action.utils.convert_public_data_to_cvat.read_ava_csv", |
| 130 | + return_value={"video_0": {"frame_idx": [[0, 0, 1, 1, "action"]]}}, |
| 131 | + ) |
| 132 | + mocker.patch("otx.algorithms.action.utils.convert_public_data_to_cvat.os.listdir", return_value=["video_0"]) |
| 133 | + mocker.patch("otx.algorithms.action.utils.convert_public_data_to_cvat.shutil.copytree", return_value=True) |
| 134 | + mocker.patch( |
| 135 | + "otx.algorithms.action.utils.convert_public_data_to_cvat.generate_default_cvat_xml_fields", |
| 136 | + return_value=([], (256, 256, 3), []), |
| 137 | + ) |
| 138 | + mocker.patch( |
| 139 | + "otx.algorithms.action.utils.convert_public_data_to_cvat.etree.ElementTree", return_value=MockElementTree() |
| 140 | + ) |
| 141 | + convert_ava_dataset_to_datumaro(src_path, dst_path, ann_file) |
140 | 142 |
|
141 | 143 |
|
142 | 144 | @e2e_pytest_unit |
|
0 commit comments