Skip to content

Commit 5e32e03

Browse files
Narek MkhitaryanNarek Mkhitaryan
authored andcommitted
added new logicaly case in copy_items
1 parent 55360dd commit 5e32e03

File tree

3 files changed

+63
-8
lines changed

3 files changed

+63
-8
lines changed

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2927,7 +2927,7 @@ def copy_items(
29272927
source: Union[NotEmptyStr, dict],
29282928
destination: Union[NotEmptyStr, dict],
29292929
items: Optional[List[NotEmptyStr]] = None,
2930-
include_annotations: Optional[bool] = True,
2930+
include_annotations: bool = True,
29312931
duplicate_strategy: Literal[
29322932
"skip", "replace", "replace_annotations_only"
29332933
] = "skip",
@@ -2961,6 +2961,12 @@ def copy_items(
29612961
:rtype: list of strs
29622962
"""
29632963

2964+
if not include_annotations and duplicate_strategy != "skip":
2965+
duplicate_strategy = "skip"
2966+
logger.warning(
2967+
"Copy operation continuing without annotations and metadata due to include_annotations=False."
2968+
)
2969+
29642970
project_name, source_folder = extract_project_folder(source)
29652971
to_project_name, destination_folder = extract_project_folder(destination)
29662972
if project_name != to_project_name:

src/superannotate/lib/infrastructure/controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ def move_multiple(
599599
duplicate_strategy=duplicate_strategy,
600600
include_annotations=True,
601601
operation="move",
602-
chunk_size=1000,
602+
chunk_size=500,
603603
)
604604
return use_case.execute()
605605

tests/integration/items/test_copy_items.py

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ class TestCopyItems(BaseTestCase):
1818
FOLDER_1 = "folder_1"
1919
FOLDER_2 = "folder_2"
2020
CSV_PATH = "data_set/attach_urls.csv"
21+
Attachment = [
22+
{
23+
"url": "https://drive.google.com/uc?export=download&id=1vwfCpTzcjxoEA4hhDxqapPOVvLVeS7ZS",
24+
"name": IMAGE_NAME,
25+
},
26+
{
27+
"url": "https://drive.google.com/uc?export=download&id=1vwfCpTzcjxoEA4hhDxqapPOVvLVeS7Zw",
28+
"name": IMAGE_NAME_2,
29+
},
30+
]
2131

2232
@property
2333
def scv_path(self):
@@ -69,12 +79,7 @@ def test_skipped_count(self):
6979
def test_copy_items_wrong_items_list(self):
7080
uploaded, _, _ = sa.attach_items(
7181
self.PROJECT_NAME,
72-
[
73-
{
74-
"url": "https://drive.google.com/uc?export=download&id=1vwfCpTzcjxoEA4hhDxqapPOVvLVeS7ZS",
75-
"name": self.IMAGE_NAME,
76-
}
77-
],
82+
self.Attachment,
7883
)
7984
sa.set_approval_statuses(self.PROJECT_NAME, "Approved", items=[self.IMAGE_NAME])
8085
sa.set_annotation_statuses(
@@ -92,3 +97,47 @@ def test_copy_items_wrong_items_list(self):
9297
assert items[0]["annotation_status"] == "Completed"
9398
assert items[0]["approval_status"] == "Approved"
9499
assert Counter(skipped_items) == Counter(["as", "asd"])
100+
101+
def test_copy_duplicated_items_without_data_with_replace_strategy(self):
102+
sa.create_folder(self.PROJECT_NAME, self.FOLDER_1)
103+
sa.create_folder(self.PROJECT_NAME, self.FOLDER_2)
104+
uploaded, _, _ = sa.attach_items(
105+
f"{self.PROJECT_NAME}/{self.FOLDER_1}", self.Attachment
106+
)
107+
assert len(uploaded) == 2
108+
sa.set_approval_statuses(
109+
f"{self.PROJECT_NAME}/{self.FOLDER_1}",
110+
"Approved",
111+
items=[self.IMAGE_NAME, self.IMAGE_NAME_2],
112+
)
113+
sa.set_annotation_statuses(
114+
f"{self.PROJECT_NAME}/{self.FOLDER_1}",
115+
"Completed",
116+
items=[self.IMAGE_NAME, self.IMAGE_NAME_2],
117+
)
118+
119+
uploaded_2, _, _ = sa.attach_items(
120+
f"{self.PROJECT_NAME}/{self.FOLDER_2}", self.Attachment
121+
)
122+
assert len(uploaded_2) == 2
123+
124+
with self.assertLogs("sa", level="WARNING") as cm:
125+
skipped_items = sa.copy_items(
126+
f"{self.PROJECT_NAME}/{self.FOLDER_1}",
127+
f"{self.PROJECT_NAME}/{self.FOLDER_2}",
128+
include_annotations=False,
129+
duplicate_strategy="replace",
130+
)
131+
assert (
132+
"WARNING:sa:Copy operation continuing without annotations and metadata"
133+
" due to include_annotations=False." == cm.output[0]
134+
)
135+
assert len(skipped_items) == 2
136+
folder_1_items = sa.search_items(f"{self.PROJECT_NAME}/{self.FOLDER_1}")
137+
folder_2_items = sa.search_items(f"{self.PROJECT_NAME}/{self.FOLDER_2}")
138+
assert len(folder_1_items) == 2
139+
assert len(folder_2_items) == 2
140+
141+
folder_2_items = sa.search_items(f"{self.PROJECT_NAME}/{self.FOLDER_2}")
142+
assert folder_2_items[0]["annotation_status"] == "NotStarted"
143+
assert not folder_2_items[0]["approval_status"]

0 commit comments

Comments
 (0)