Skip to content

Commit c8ac78c

Browse files
authored
Merge pull request #233 from superannotateai/sdk_351
Fixed friday-351
2 parents fe1419a + 3fc5f31 commit c8ac78c

File tree

8 files changed

+50
-25
lines changed

8 files changed

+50
-25
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,8 @@ def upload_images_from_folder_to_project(
13501350
raise AppException(
13511351
"extensions should be a list or a tuple in upload_images_from_folder_to_project"
13521352
)
1353+
elif len(extensions) < 1:
1354+
return [], [], []
13531355

13541356
if exclude_file_patterns:
13551357
exclude_file_patterns = list(exclude_file_patterns) + list(

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,17 @@ def wrapped(*args, **kwargs):
7070
except ValidationError as e:
7171
error_messages = defaultdict(list)
7272
for error in e.errors():
73-
error_messages[error["loc"][0]].append(
74-
f"{''.join([f' {i[0]} -> {i[1]}' for i in to_chunks(error['loc'])])} {error['loc'][-1]} {error['msg']}"
75-
)
73+
errors_list = list(error["loc"])
74+
errors_list[1::2] = [f"[{i}]" for i in errors_list[1::2]]
75+
errors_list[2::2] = [f".{i}" for i in errors_list[2::2]]
76+
error_messages["".join(errors_list)].append(error["msg"])
7677
texts = ["\n"]
77-
for error, text in error_messages.items():
78+
for field, text in error_messages.items():
7879
texts.append(
7980
"{} {}{}".format(
80-
error, " " * (21 - len(error)), f"\n {' ' * 21}".join(text)
81+
field, " " * (48 - len(field)), f"\n {' ' * 48}".join(text)
8182
)
8283
)
83-
raise AppException("\n".join(texts))
84+
raise Exception("\n".join(texts))
8485

8586
return wrapped

tests/integration/test_annotation_classes.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
import os
33
from os.path import dirname
44
import src.superannotate as sa
5-
from src.superannotate import AppException
65
from tests.integration.base import BaseTestCase
76

87

9-
108
class TestAnnotationClasses(BaseTestCase):
119
PROJECT_NAME_ = "TestAnnotationClasses"
1210
PROJECT_DESCRIPTION = "desc"
@@ -20,8 +18,8 @@ def classes_path(self):
2018
def test_invalid_json(self):
2119
try:
2220
sa.create_annotation_classes_from_classes_json(self.PROJECT_NAME, self.classes_path)
23-
except AppException as e:
24-
self.assertIn("name field required", str(e))
21+
except Exception as e:
22+
self.assertIn("field required", str(e))
2523

2624
def test_annotation_classes(self):
2725
annotation_classes = sa.search_annotation_classes(self.PROJECT_NAME)

tests/integration/test_folders.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,8 @@ def test_basic_folders(self):
6666
self.assertIsInstance(folder, dict)
6767
self.assertEqual(folder["name"], self.TEST_FOLDER_NAME_1)
6868

69-
# todo fix
70-
# with pytest.raises(EmptyOutputError) as exc_info:
71-
# sa.get_folder_metadata(self.PROJECT_NAME, self.TEST_FOLDER_NAME_2)
72-
# self.assertTrue("Folder not found" in str(exc_info))
69+
with self.assertRaisesRegexp(Exception, "Folder not found"):
70+
sa.get_folder_metadata(self.PROJECT_NAME, self.TEST_FOLDER_NAME_2)
7371

7472
sa.upload_images_from_folder_to_project(
7573
f"{self.PROJECT_NAME}/{self.TEST_FOLDER_NAME_1}",
@@ -89,15 +87,6 @@ def test_basic_folders(self):
8987
images = sa.search_images(f"{self.PROJECT_NAME}/{self.TEST_FOLDER_NAME_1}")
9088
self.assertEqual(len(images), 4)
9189

92-
# todo fix
93-
# with pytest.raises(AppException) as e:
94-
# sa.upload_images_from_folder_to_project(
95-
# f"{self.PROJECT_NAME}/{self.TEST_FOLDER_NAME_1}",
96-
# self.folder_path,
97-
# annotation_status="InProgress",
98-
# )
99-
# self.assertTrue("Folder not found" in str(e))
100-
10190
folder_metadata = sa.create_folder(self.PROJECT_NAME, self.TEST_FOLDER_NAME_2)
10291
self.assertEqual(folder_metadata["name"], self.TEST_FOLDER_NAME_2)
10392

tests/integration/test_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def test_upload_images_to_project_returned_data(self):
158158

159159
def test_upload_images_to_project_image_quality_in_editor(self):
160160
self.assertRaises(
161-
AppException,
161+
Exception,
162162
sa.upload_images_to_project,
163163
self.PROJECT_NAME,
164164
[self.EXAMPLE_IMAGE_1],

tests/integration/test_single_annotation_download.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ def test_annotation_download_upload_vector(self):
5555
for j in i["attributes"]:
5656
j.pop("groupId", None)
5757
j.pop("id", None)
58-
# TODO check teplateId -1 when
58+
self.assertTrue(
59+
all(
60+
[instance["templateId"] == -1 for instance in downloaded_json["instances"] if
61+
instance.get("templateId")]
62+
)
63+
)
5964
assert downloaded_json == uploaded_json
6065

6166

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import os
2+
from os.path import dirname
3+
4+
import src.superannotate as sa
5+
from src.superannotate import AppException
6+
from src.superannotate.lib.core import ATTACHING_UPLOAD_STATE_ERROR
7+
from src.superannotate.lib.core import UPLOADING_UPLOAD_STATE_ERROR
8+
from tests.integration.base import BaseTestCase
9+
10+
11+
class TestUploadImages(BaseTestCase):
12+
PROJECT_NAME = "TestUploadImages"
13+
PROJECT_DESCRIPTION = "Desc"
14+
PROJECT_TYPE = "Vector"
15+
TEST_FOLDER_PATH = "data_set"
16+
TEST_IMAGES_PATH = "sample_project_vector"
17+
PATH_TO_VIDEOS = "sample_videos"
18+
IMAGE_NAME = "example_image_1.jpg"
19+
20+
@property
21+
def folder_path(self):
22+
return os.path.join(dirname(dirname(__file__)), self.TEST_FOLDER_PATH)
23+
24+
def test_upload_images_with_empty_extensions_list(self):
25+
result = sa.upload_images_from_folder_to_project(
26+
self.PROJECT_NAME,
27+
os.path.join(self.folder_path, self.TEST_IMAGES_PATH),
28+
extensions=[]
29+
)
30+
self.assertEqual(([], [], []), result)
File renamed without changes.

0 commit comments

Comments
 (0)