Skip to content

Commit 213702d

Browse files
Vaghinak BasentsyanVaghinak Basentsyan
authored andcommitted
tests refactor, tags fix
1 parent afcce60 commit 213702d

File tree

10 files changed

+90
-66
lines changed

10 files changed

+90
-66
lines changed

src/superannotate/__init__.py

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -206,41 +206,41 @@
206206
sys.path.append(WORKING_DIR)
207207
logging.getLogger("botocore").setLevel(logging.CRITICAL)
208208

209-
logging.config.dictConfig(
210-
{
211-
"version": 1,
212-
"disable_existing_loggers": False,
213-
"handlers": {
214-
"console": {
215-
"class": "logging.StreamHandler",
216-
"level": "INFO",
217-
"formatter": "consoleFormatter",
218-
"stream": "ext://sys.stdout",
219-
},
220-
"fileHandler": {
221-
"class": "logging.handlers.RotatingFileHandler",
222-
"level": "DEBUG",
223-
"formatter": "fileFormatter",
224-
"filename": expanduser(constances.LOG_FILE_LOCATION),
225-
"mode": "a",
226-
"maxBytes": 5 * 1024 * 1024,
227-
"backupCount": 5,
228-
},
229-
},
230-
"formatters": {
231-
"consoleFormatter": {
232-
"format": "SA-PYTHON-SDK - %(levelname)s - %(message)s",
233-
},
234-
"fileFormatter": {
235-
"format": "SA-PYTHON-SDK - %(levelname)s - %(asctime)s - %(message)s"
236-
}
237-
},
238-
"root": { # root logger
239-
"level": "DEBUG",
240-
"handlers": ["console", "fileHandler"],
241-
},
242-
}
243-
)
209+
# logging.config.dictConfig(
210+
# {
211+
# "version": 1,
212+
# "disable_existing_loggers": False,
213+
# "handlers": {
214+
# "console": {
215+
# "class": "logging.StreamHandler",
216+
# "level": "INFO",
217+
# "formatter": "consoleFormatter",
218+
# "stream": "ext://sys.stdout",
219+
# },
220+
# "fileHandler": {
221+
# "class": "logging.handlers.RotatingFileHandler",
222+
# "level": "DEBUG",
223+
# "formatter": "fileFormatter",
224+
# "filename": expanduser(constances.LOG_FILE_LOCATION),
225+
# "mode": "a",
226+
# "maxBytes": 5 * 1024 * 1024,
227+
# "backupCount": 5,
228+
# },
229+
# },
230+
# "formatters": {
231+
# "consoleFormatter": {
232+
# "format": "SA-PYTHON-SDK - %(levelname)s - %(message)s",
233+
# },
234+
# "fileFormatter": {
235+
# "format": "SA-PYTHON-SDK - %(levelname)s - %(asctime)s - %(message)s"
236+
# }
237+
# },
238+
# "root": { # root logger
239+
# "level": "DEBUG",
240+
# "handlers": ["console", "fileHandler"],
241+
# },
242+
# }
243+
# )
244244

245245

246246
def log_version_info():
@@ -266,4 +266,3 @@ def log_version_info():
266266

267267

268268
log_version_info()
269-

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from lib.core.entities import TeamEntity
1717
from lib.core.helpers import convert_to_video_editor_json
1818
from lib.core.helpers import fill_annotation_ids
19+
from lib.core.helpers import fill_document_tags
1920
from lib.core.helpers import handle_last_action
2021
from lib.core.helpers import map_annotation_classes_name
2122
from lib.core.reporter import Reporter
@@ -420,6 +421,8 @@ def prepare_annotations(
420421
annotations = convert_to_video_editor_json(
421422
annotations, annotation_classes_name_maps, reporter
422423
)
424+
if project_type == constances.ProjectType.DOCUMENT.value:
425+
fill_document_tags(annotations, annotation_classes_name_maps)
423426
handle_last_action(annotations, team)
424427
return annotations
425428

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import copy
22
import logging
3+
from collections import defaultdict
34
from typing import Iterable
45
from typing import List
56
from typing import Type
6-
from collections import defaultdict
77

88
import lib.core as constances
99
from lib.core.conditions import Condition
@@ -15,12 +15,12 @@
1515
from lib.core.entities import WorkflowEntity
1616
from lib.core.exceptions import AppException
1717
from lib.core.exceptions import AppValidationException
18+
from lib.core.reporter import Reporter
1819
from lib.core.repositories import BaseManageableRepository
1920
from lib.core.repositories import BaseReadOnlyRepository
2021
from lib.core.serviceproviders import SuerannotateServiceProvider
21-
from lib.core.usecases.base import BaseUseCase
2222
from lib.core.usecases.base import BaseReportableUseCae
23-
from lib.core.reporter import Reporter
23+
from lib.core.usecases.base import BaseUseCase
2424

2525
logger = logging.getLogger("root")
2626

src/superannotate/lib/infrastructure/validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def wrap_error(e: ValidationError) -> str:
2727
errors_list[1::] = [
2828
f"[{i}]" if isinstance(i, int) else f".{i}" for i in errors_list[1::]
2929
]
30-
error_messages["".join(errors_list)].append(error["msg"])
30+
error_messages["".join([str(item) for item in errors_list])].append(error["msg"])
3131
texts = ["\n"]
3232
for field, text in error_messages.items():
3333
texts.append(

tests/integration/annotations/test_annotation_upload_pixel.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,22 @@ def test_recursive_annotation_upload_pixel(self, s3_bucket):
3636
sa.upload_images_from_folder_to_project(
3737
destination, self.folder_path, recursive_subfolders=False
3838
)
39-
uploaded_annotations, _, _ = sa.upload_annotations_from_folder_to_project(destination,
40-
self.S3_FOLDER_PATH,
41-
from_s3_bucket="superannotate-python-sdk-test",
42-
recursive_subfolders=False)
43-
self.assertEqual(len(uploaded_annotations), 3)
44-
self.assertEqual(len(s3_bucket.method_calls), 6)
45-
self.assertIn(f"Uploading 3 annotations from {self.S3_FOLDER_PATH} to the project {destination}.",
46-
self._caplog.text)
39+
uploaded_annotations, _, _ = sa.upload_annotations_from_folder_to_project(
40+
destination,
41+
self.S3_FOLDER_PATH,
42+
from_s3_bucket="superannotate-python-sdk-test",
43+
recursive_subfolders=False
44+
)
45+
self.assertEqual(len(uploaded_annotations), 2)
46+
self.assertEqual(len(s3_bucket.method_calls), 4)
4747

48-
uploaded_annotations, _, _ = sa.upload_preannotations_from_folder_to_project(destination,
49-
self.S3_FOLDER_PATH,
50-
from_s3_bucket="superannotate-python-sdk-test",
51-
recursive_subfolders=False)
52-
self.assertEqual(len(s3_bucket.method_calls), 12)
53-
self.assertIn(f"Uploading 3 annotations from {self.S3_FOLDER_PATH} to the project {destination}.",
54-
self._caplog.text)
48+
uploaded_annotations, _, _ = sa.upload_preannotations_from_folder_to_project(
49+
destination,
50+
self.S3_FOLDER_PATH,
51+
from_s3_bucket="superannotate-python-sdk-test",
52+
recursive_subfolders=False
53+
)
54+
self.assertEqual(len(s3_bucket.method_calls), 8)
5555

5656
@pytest.mark.flaky(reruns=2)
5757
def test_annotation_upload_pixel(self):

tests/integration/annotations/test_annotation_upload_vector.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TestAnnotationUploadVector(BaseTestCase):
2323
def folder_path(self):
2424
return os.path.join(Path(__file__).parent.parent.parent, self.TEST_FOLDER_PATH)
2525

26-
@pytest.mark.flaky(reruns=2)
26+
@pytest.mark.flaky(reruns=3)
2727
@patch("lib.infrastructure.controller.Reporter")
2828
def test_annotation_upload(self, reporter):
2929
reporter_mock = MagicMock()
@@ -48,7 +48,8 @@ def test_annotation_upload(self, reporter):
4848
[i["attributes"]for i in origin_annotation["instances"]]
4949
)
5050

51-
def test_annotation_folder_upload_download(self, ):
51+
@pytest.mark.flaky(reruns=3)
52+
def test_annotation_folder_upload_download(self):
5253
sa.upload_images_from_folder_to_project(
5354
self.PROJECT_NAME, self.folder_path, annotation_status="InProgress"
5455
)

tests/integration/annotations/test_video_annotation_upload.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ def test_video_annotation_upload(self):
104104
for class_id in class_ids:
105105
annotation = annotation.replace(class_id, "0")
106106
uploaded_annotation = json.loads(annotation)
107+
107108
del downloaded_annotation["metadata"]["lastAction"]
109+
# status deleted because it changed by export
110+
del downloaded_annotation["metadata"]["status"]
111+
del uploaded_annotation["metadata"]["status"]
108112
self.assertEqual(downloaded_annotation, uploaded_annotation)
109113

110114
def test_upload_annotations_without_class_name(self):
@@ -135,5 +139,28 @@ def test_video_annotation_converter(self):
135139
converted_video = convert_to_video_editor_json(
136140
json.loads(open(f'{self.minimal_annotations_path}/video.mp4.json', 'r').read()), class_name_mapper={},
137141
reporter=Reporter())
138-
data = {'instances': [{'attributes': [], 'timeline': {'0': {'active': True, 'points': {'x1': 223.32, 'y1': 78.45, 'x2': 312.31, 'y2': 176.66}}, 17.271058: {'points': {'x1': 182.08, 'y1': 33.18, 'x2': 283.45, 'y2': 131.39}}, 18.271058: {'points': {'x1': 182.32, 'y1': 36.33, 'x2': 284.01, 'y2': 134.54}}, 19.271058: {'points': {'x1': 181.49, 'y1': 45.09, 'x2': 283.18, 'y2': 143.3}}, 19.725864: {'points': {'x1': 181.9, 'y1': 48.35, 'x2': 283.59, 'y2': 146.56}}, 20.271058: {'points': {'x1': 181.49, 'y1': 52.46, 'x2': 283.18, 'y2': 150.67}}, 21.271058: {'points': {'x1': 181.49, 'y1': 63.7, 'x2': 283.18, 'y2': 161.91}}, 22.271058: {'points': {'x1': 182.07, 'y1': 72.76, 'x2': 283.76, 'y2': 170.97}}, 23.271058: {'points': {'x1': 182.07, 'y1': 81.51, 'x2': 283.76, 'y2': 179.72}}, 24.271058: {'points': {'x1': 182.42, 'y1': 97.19, 'x2': 284.11, 'y2': 195.4}}, 30.526667: {'active': False, 'points': {'x1': 182.42, 'y1': 97.19, 'x2': 284.11, 'y2': 195.4}}}, 'type': 'bbox', 'locked': False, 'classId': -1, 'pointLabels': {'3': 'point label bro'}}, {'attributes': [], 'timeline': {29.713736: {'active': True, 'points': {'x1': 132.82, 'y1': 129.12, 'x2': 175.16, 'y2': 188}}, 30.526667: {'active': False, 'points': {'x1': 132.82, 'y1': 129.12, 'x2': 175.16, 'y2': 188}}}, 'type': 'bbox', 'locked': False, 'classId': -1}, {'attributes': [], 'timeline': {5.528212: {'active': True}, 6.702957: {}, 7.083022: {'active': False}}, 'type': 'event', 'locked': False, 'classId': -1}], 'tags': ['some tag'], 'name': 'video.mp4', 'metadata': {'name': 'video.mp4', 'width': None, 'height': None}}
142+
data = {'instances': [{'attributes': [], 'timeline': {
143+
'0': {'active': True, 'points': {'x1': 223.32, 'y1': 78.45, 'x2': 312.31, 'y2': 176.66}},
144+
17.271058: {'points': {'x1': 182.08, 'y1': 33.18, 'x2': 283.45, 'y2': 131.39}},
145+
18.271058: {'points': {'x1': 182.32, 'y1': 36.33, 'x2': 284.01, 'y2': 134.54}},
146+
19.271058: {'points': {'x1': 181.49, 'y1': 45.09, 'x2': 283.18, 'y2': 143.3}},
147+
19.725864: {'points': {'x1': 181.9, 'y1': 48.35, 'x2': 283.59, 'y2': 146.56}},
148+
20.271058: {'points': {'x1': 181.49, 'y1': 52.46, 'x2': 283.18, 'y2': 150.67}},
149+
21.271058: {'points': {'x1': 181.49, 'y1': 63.7, 'x2': 283.18, 'y2': 161.91}},
150+
22.271058: {'points': {'x1': 182.07, 'y1': 72.76, 'x2': 283.76, 'y2': 170.97}},
151+
23.271058: {'points': {'x1': 182.07, 'y1': 81.51, 'x2': 283.76, 'y2': 179.72}},
152+
24.271058: {'points': {'x1': 182.42, 'y1': 97.19, 'x2': 284.11, 'y2': 195.4}},
153+
30.526667: {'active': False, 'points': {'x1': 182.42, 'y1': 97.19, 'x2': 284.11, 'y2': 195.4}}},
154+
'type': 'bbox', 'locked': False, 'classId': -1, 'pointLabels': {'3': 'point label bro'}},
155+
{'attributes': [], 'timeline': {29.713736: {'active': True,
156+
'points': {'x1': 132.82, 'y1': 129.12,
157+
'x2': 175.16, 'y2': 188}},
158+
30.526667: {'active': False,
159+
'points': {'x1': 132.82, 'y1': 129.12,
160+
'x2': 175.16, 'y2': 188}}},
161+
'type': 'bbox', 'locked': False, 'classId': -1}, {'attributes': [], 'timeline': {
162+
5.528212: {'active': True}, 6.702957: {}, 7.083022: {'active': False}}, 'type': 'event',
163+
'locked': False, 'classId': -1}],
164+
'tags': ['some tag'], 'name': 'video.mp4',
165+
'metadata': {'name': 'video.mp4', 'width': None, 'height': None}}
139166
self.assertEqual(data, converted_video)

tests/integration/test_depricated_functions_video.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def test_deprecated_functions(self):
166166
try:
167167
sa.set_project_default_image_quality_in_editor(self.PROJECT_NAME, "original")
168168
except AppException as e:
169-
self.assertIn(self.EXCEPTION_MESSAGE, str(e))
169+
self.assertIn(self.EXCEPTION_MESSAGE_DOCUMENT_VIDEO, str(e))
170170
try:
171171
sa.set_images_annotation_statuses(self.PROJECT_NAME, "Completed", [self.UPLOAD_IMAGE_NAME])
172172
except AppException as e:

tests/integration/test_interface.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ def test_upload_annotations_from_folder_to_project(self):
7575
)
7676
self.assertEqual(len(uploaded_annotations), 4)
7777

78-
@pytest.mark.flaky(reruns=2)
79-
def test_get_images_metadata(self):
80-
sa.upload_images_from_folder_to_project(self.PROJECT_NAME, self.folder_path)
81-
metadata = sa.search_images(self.PROJECT_NAME, self.EXAMPLE_IMAGE_1, return_metadata=True)
82-
self.assertIn("qa_id", metadata[0])
83-
8478
def test_download_image_annotations(self):
8579
sa.upload_images_from_folder_to_project(self.PROJECT_NAME, self.folder_path)
8680
with tempfile.TemporaryDirectory() as temp_dir:

tests/integration/test_recursive_folder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def test_annotations_recursive_s3_10(self):
196196
uploaded = sa.upload_annotations_from_folder_to_project(self.PROJECT_NAME, '8sep',
197197
from_s3_bucket="superannotate-python-sdk-test",
198198
recursive_subfolders=False)
199-
self.assertEqual(len(uploaded[0]), 8)
199+
self.assertEqual(len(uploaded[0]), 9)
200200

201201
def test_images_non_recursive(self):
202202
sa.upload_images_from_folder_to_project(

0 commit comments

Comments
 (0)