Skip to content

Commit ddd1269

Browse files
committed
fix upload_images_to_project in case of duplicate paths
1 parent 601b44a commit ddd1269

File tree

3 files changed

+55
-46
lines changed

3 files changed

+55
-46
lines changed

src/superannotate/lib/core/usecases/images.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ def filter_paths(self, paths: List[str]):
10241024
duplicated_paths = []
10251025
for file_name in name_path_map:
10261026
if len(name_path_map[file_name]) > 1:
1027-
duplicated_paths.append(name_path_map[file_name][1:])
1027+
duplicated_paths.extend(name_path_map[file_name][1:])
10281028
filtered_paths.append(name_path_map[file_name][0])
10291029

10301030
image_list = []

tests/integration/test_duplicate_image_upload.py renamed to tests/integration/test_image_upload.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import io
12
import os
23
from os.path import dirname
34

@@ -7,8 +8,8 @@
78
sa = SAClient()
89

910

10-
class TestDuplicateImage(BaseTestCase):
11-
PROJECT_NAME = "duplicate_image"
11+
class TestSingleImageUpload(BaseTestCase):
12+
PROJECT_NAME = "single_image_upload"
1213
PROJECT_DESCRIPTION = "Desc"
1314
PROJECT_TYPE = "Vector"
1415
TEST_FOLDER_PTH = "data_set"
@@ -25,6 +26,41 @@ def classes_path(self):
2526
)
2627

2728
def test_single_image_upload(self):
29+
sa.upload_image_to_project(
30+
self.PROJECT_NAME,
31+
self.folder_path + "/example_image_1.jpg",
32+
annotation_status="InProgress",
33+
)
34+
assert len(sa.search_items(self.PROJECT_NAME)) == 1
35+
36+
with open(self.folder_path + "/example_image_1.jpg", "rb") as f:
37+
img = io.BytesIO(f.read())
38+
39+
sa.upload_image_to_project(
40+
self.PROJECT_NAME, img, image_name="rr.jpg", annotation_status="InProgress"
41+
)
42+
43+
assert len(sa.search_items(self.PROJECT_NAME)) == 2
44+
45+
46+
class TestMultipleImageUpload(BaseTestCase):
47+
PROJECT_NAME = "test_multiple_image_upload"
48+
PROJECT_DESCRIPTION = "Desc"
49+
PROJECT_TYPE = "Vector"
50+
TEST_FOLDER_PTH = "data_set"
51+
TEST_FOLDER_PATH = "data_set/sample_project_vector"
52+
53+
@property
54+
def folder_path(self):
55+
return os.path.join(dirname(dirname(__file__)), self.TEST_FOLDER_PATH)
56+
57+
@property
58+
def classes_path(self):
59+
return os.path.join(
60+
dirname(dirname(__file__)), self.TEST_FOLDER_PATH, "classes/classes.json"
61+
)
62+
63+
def test_multiple_image_upload(self):
2864
(uploaded, could_not_upload, existing_images,) = sa.upload_images_to_project(
2965
self.PROJECT_NAME,
3066
[
@@ -59,3 +95,19 @@ def test_single_image_upload(self):
5995
self.assertEqual(len(uploaded), 0)
6096
self.assertEqual(len(could_not_upload), 1)
6197
self.assertEqual(len(existing_images), 0)
98+
99+
def test_multiple_image_upload_with_duplicates(self):
100+
(uploaded, could_not_upload, existing_images,) = sa.upload_images_to_project(
101+
self.PROJECT_NAME,
102+
[
103+
f"{self.folder_path}/example_image_1.jpg",
104+
f"{self.folder_path}/example_image_1.jpg",
105+
f"{self.folder_path}/example_image_1.jpg",
106+
f"{self.folder_path}/example_image_3.jpg",
107+
f"{self.folder_path}/example_image_4.jpg",
108+
],
109+
annotation_status="InProgress",
110+
)
111+
self.assertEqual(len(uploaded), 3)
112+
self.assertEqual(len(could_not_upload), 0)
113+
self.assertEqual(len(existing_images), 2)

tests/integration/test_single_image_upload.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)