Skip to content

Commit 948dbae

Browse files
committed
Merge branch 'test-refactor' into develop
2 parents 605e51e + 7087f11 commit 948dbae

40 files changed

+408
-465
lines changed

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[pytest]
2-
timeout = 300
2+
timeout = 600
33
timeout_method=thread

superannotate/api.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import logging
44
import sys
5+
import time
56
from pathlib import Path
67

78
import requests
@@ -137,14 +138,20 @@ def send_request(self, req_type, path, params=None, json_req=None):
137138
for key, value in params.items():
138139
if isinstance(value, str):
139140
params[key] = value.replace("\\", "\\\\")
140-
141141
req = requests.Request(
142142
method=req_type, url=url, json=json_req, params=params
143143
)
144144
if self._session is None:
145145
self._session = self._create_session()
146146
prepared = self._session.prepare_request(req)
147147
resp = self._session.send(request=prepared, verify=self._verify)
148+
if resp.status_code not in [200,201]:
149+
time.sleep(4)
150+
resp = self._session.send(request=prepared, verify=self._verify)
151+
152+
if req_type.lower() == "get" and not resp.text:
153+
time.sleep(4)
154+
resp = self._session.send(request=prepared, verify=self._verify)
148155
return resp
149156

150157
def _create_session(self):
@@ -153,11 +160,11 @@ def _create_session(self):
153160
total=5,
154161
read=5,
155162
connect=5,
156-
backoff_factor=0.3,
163+
backoff_factor=2,
157164
# use on any request type
158165
method_whitelist=False,
159166
# force retry on those status responses
160-
status_forcelist=(501, 502, 503, 504, 505, 506, 507, 508, 510, 511),
167+
status_forcelist=(501, 502, 503, 504, 505, 506, 507, 508, 510, 511, 403, 400),
161168
raise_on_status=False
162169
)
163170
adapter = requests.adapters.HTTPAdapter(

tests/common.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import time
12
from pathlib import Path
23
import superannotate as sa
34

@@ -14,11 +15,8 @@ def upload_project(
1415
if isinstance(project_path, str):
1516
project_path = Path(project_path)
1617

17-
projects = sa.search_projects(project_name, return_metadata=True)
18-
for project in projects:
19-
sa.delete_project(project)
20-
21-
project = sa.create_project(project_name, description, ptype)
18+
from .test_assign_images import safe_create_project
19+
project = safe_create_project(project_name,description,ptype)
2220

2321
sa.create_annotation_classes_from_classes_json(
2422
project,
@@ -35,5 +33,5 @@ def upload_project(
3533
sa.upload_annotations_from_folder_to_project(
3634
project, project_path, from_s3_bucket=from_s3_bucket
3735
)
38-
36+
time.sleep(2)
3937
return project

tests/consensus_benchmark/test_benchmark.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import time
12
from pathlib import Path
23

34
import superannotate as sa
@@ -17,22 +18,27 @@ def test_benchmark():
1718
export_path = test_root / 'consensus_benchmark' / 'consensus_test_data'
1819
if len(sa.search_projects(project_name)) != 0:
1920
sa.delete_project(project_name)
20-
21+
time.sleep(2)
2122
sa.create_project(project_name, "test bench", "Vector")
23+
time.sleep(2)
2224
for i in range(1, 4):
2325
sa.create_folder(project_name, "consensus_" + str(i))
26+
time.sleep(2)
2427
sa.create_annotation_classes_from_classes_json(
2528
project_name, export_path / 'classes' / 'classes.json'
2629
)
30+
time.sleep(2)
2731
sa.upload_images_from_folder_to_project(
2832
project_name, export_path / "images", annotation_status="Completed"
2933
)
34+
time.sleep(2)
3035
for i in range(1, 4):
3136
sa.upload_images_from_folder_to_project(
3237
project_name + '/consensus_' + str(i),
3338
export_path / "images",
3439
annotation_status="Completed"
3540
)
41+
time.sleep(2)
3642
sa.upload_annotations_from_folder_to_project(project_name, export_path)
3743
for i in range(1, 4):
3844
sa.upload_annotations_from_folder_to_project(

tests/consensus_benchmark/test_consensus.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import time
12
from pathlib import Path
23

34
import superannotate as sa
@@ -16,13 +17,15 @@ def test_consensus():
1617
export_path = test_root / 'consensus_benchmark' / 'consensus_test_data'
1718
if len(sa.search_projects(project_name)) != 0:
1819
sa.delete_project(project_name)
19-
20+
time.sleep(2)
2021
sa.create_project(project_name, "test bench", "Vector")
22+
time.sleep(2)
2123
for i in range(1, 4):
2224
sa.create_folder(project_name, "consensus_" + str(i))
2325
sa.create_annotation_classes_from_classes_json(
2426
project_name, export_path / 'classes' / 'classes.json'
2527
)
28+
time.sleep(2)
2629
sa.upload_images_from_folder_to_project(
2730
project_name, export_path / "images", annotation_status="Completed"
2831
)

tests/converter_test/test_conversion.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import time
12
from pathlib import Path
23
from mixpanel import json_dumps
34

@@ -154,10 +155,12 @@ def test_upload_annotations_with_template_id(tmpdir):
154155
project_name = "test_templates"
155156
for project in sa.search_projects(project_name):
156157
sa.delete_project(project)
158+
time.sleep(2)
157159
project = sa.create_project(project_name, "test", "Vector")
158160
sa.upload_images_from_folder_to_project(
159161
project, "./tests/sample_coco_with_templates"
160162
)
163+
time.sleep(2)
161164
input_dir = Path("tests") / "sample_coco_with_templates"
162165
out_path = Path(
163166
tmpdir
@@ -168,5 +171,6 @@ def test_upload_annotations_with_template_id(tmpdir):
168171
"keypoint_detection"
169172
)
170173
sa.upload_annotations_from_folder_to_project(project, out_path)
174+
time.sleep(2)
171175
image_metadata = sa.get_image_annotations(project_name, "t.png")
172176
assert image_metadata['annotation_json']['instances'][0]['templateId'] == -1

tests/sample_project_vector/example_image_1.jpg___objects.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220
"id": 117846
221221
}
222222
],
223-
"templateId": 91,
223+
"templateId": -1,
224224
"trackingId": "cbde2787e76c41be77c1079e8d090252ad701ea",
225225
"createdAt": null,
226226
"createdBy": null,
@@ -1315,7 +1315,7 @@
13151315
"locked": false,
13161316
"visible": false,
13171317
"attributes": [],
1318-
"templateId": 92,
1318+
"templateId": -1,
13191319
"trackingId": "2c89e809614523cf56c9aeab932e90b87aaf5e4f",
13201320
"createdAt": null,
13211321
"createdBy": null,
@@ -1552,7 +1552,7 @@
15521552
"locked": false,
15531553
"visible": false,
15541554
"attributes": [],
1555-
"templateId": 92,
1555+
"templateId": -1,
15561556
"trackingId": "bab62dc810b0cee390f8d5fb5fa62fade3c8da7",
15571557
"createdAt": null,
15581558
"createdBy": null,
@@ -1789,7 +1789,7 @@
17891789
"locked": false,
17901790
"visible": false,
17911791
"attributes": [],
1792-
"templateId": 92,
1792+
"templateId": -1,
17931793
"trackingId": "f8f542a9e9da918d5d5cb8eed9052713302089",
17941794
"createdAt": null,
17951795
"createdBy": null,
@@ -2028,7 +2028,7 @@
20282028
"locked": false,
20292029
"visible": false,
20302030
"attributes": [],
2031-
"templateId": 89,
2031+
"templateId": -1,
20322032
"trackingId": "4fd95b7d6d95b7b84750e65aa89c70b9c86eb3b8",
20332033
"createdAt": null,
20342034
"createdBy": null,
@@ -2267,7 +2267,7 @@
22672267
"locked": false,
22682268
"visible": false,
22692269
"attributes": [],
2270-
"templateId": 89,
2270+
"templateId": -1,
22712271
"trackingId": "8894b2a1727f62631d26e885a5aaf9bc2ac2a578",
22722272
"createdAt": null,
22732273
"createdBy": null,
@@ -2506,7 +2506,7 @@
25062506
"locked": false,
25072507
"visible": false,
25082508
"attributes": [],
2509-
"templateId": 89,
2509+
"templateId": -1,
25102510
"trackingId": "2fe1f0c6c4af879955d6f19cfcf113a6b929b73",
25112511
"createdAt": null,
25122512
"createdBy": null,

tests/test_annotation_adding.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1+
import time
12
from pathlib import Path
23
import json
34

45
import superannotate as sa
5-
6-
PROJECT_NAME = "Example Project test annotation add"
7-
PROJECT_NAME_NOINIT = "Example Project test annotation add no init"
8-
PROJECT_DESCRIPTION = "test vector"
9-
PATH_TO_SAMPLE_PROJECT = Path("./tests/sample_project_vector")
6+
from .test_assign_images import safe_create_project
107

118

129
def test_add_bbox(tmpdir):
1310
tmpdir = Path(tmpdir)
1411

15-
projects_found = sa.search_projects(PROJECT_NAME, return_metadata=True)
16-
for pr in projects_found:
17-
if pr["name"] == PROJECT_NAME:
18-
sa.delete_project(pr)
12+
PROJECT_NAME = "Example Project test annotation add"
13+
PROJECT_DESCRIPTION = "test vector"
14+
PATH_TO_SAMPLE_PROJECT = Path("./tests/sample_project_vector")
1915

20-
project = sa.create_project(PROJECT_NAME, PROJECT_DESCRIPTION, "Vector")
16+
project = safe_create_project(PROJECT_NAME,PROJECT_DESCRIPTION,"Vector")
2117
sa.upload_images_from_folder_to_project(
2218
PROJECT_NAME, PATH_TO_SAMPLE_PROJECT, annotation_status="InProgress"
2319
)
@@ -40,8 +36,8 @@ def test_add_bbox(tmpdir):
4036
project, PATH_TO_SAMPLE_PROJECT
4137
)
4238

39+
time.sleep(2)
4340
images = sa.search_images(project, "example_image_1")
44-
4541
image_name = images[0]
4642
annotations = sa.get_image_annotations(project,
4743
image_name)["annotation_json"]
@@ -77,10 +73,10 @@ def test_add_bbox(tmpdir):
7773
project, image_name, "hey", [100, 100], "hovnatan@superannotate.com",
7874
True
7975
)
76+
time.sleep(2)
8077
annotations_new = sa.get_image_annotations(project,
8178
image_name)["annotation_json"]
8279
json.dump(annotations_new, open(tmpdir / "new_anns.json", "w"))
83-
8480
assert len(annotations_new["instances"]) + len(
8581
annotations_new["comments"]
8682
) == len(annotations["instances"]) + len(annotations["comments"]) + 8
@@ -101,19 +97,15 @@ def test_add_bbox(tmpdir):
10197

10298
def test_add_bbox_noinit(tmpdir):
10399
tmpdir = Path(tmpdir)
100+
PROJECT_NAME_NOINIT = "Example Project test annotation add no init"
101+
PROJECT_DESCRIPTION = "tt"
102+
PATH_TO_SAMPLE_PROJECT = Path("./tests/sample_project_vector")
104103

105-
projects_found = sa.search_projects(
106-
PROJECT_NAME_NOINIT, return_metadata=True
107-
)
108-
for pr in projects_found:
109-
sa.delete_project(pr)
110-
111-
project = sa.create_project(
112-
PROJECT_NAME_NOINIT, PROJECT_DESCRIPTION, "Vector"
113-
)
104+
project = safe_create_project(PROJECT_NAME_NOINIT,PROJECT_DESCRIPTION,"Vector")
114105
sa.upload_images_from_folder_to_project(
115106
project, PATH_TO_SAMPLE_PROJECT, annotation_status="InProgress"
116107
)
108+
time.sleep(2)
117109
sa.create_annotation_classes_from_classes_json(
118110
project, PATH_TO_SAMPLE_PROJECT / "classes" / "classes.json"
119111
)
@@ -127,11 +119,13 @@ def test_add_bbox_noinit(tmpdir):
127119
sa.add_annotation_polygon_to_image(
128120
project, image_name, [100, 100, 500, 500, 200, 300], "test_add"
129121
)
122+
time.sleep(2)
130123
annotations_new = sa.get_image_annotations(project,
131124
image_name)["annotation_json"]
132125

133126
assert len(annotations_new["instances"]) == 2
134127
export = sa.prepare_export(project, include_fuse=True)
128+
time.sleep(2)
135129
sa.download_export(project, export, tmpdir)
136130

137131
non_empty_annotations = 0

tests/test_annotation_class_new.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
1+
import time
12
from pathlib import Path
23
import pytest
34
import superannotate as sa
4-
5-
PROJECT_NAME = "test annotation class new 1"
6-
PROJECT_NAME_JSON = "test annotation class new json 2"
5+
from .test_assign_images import safe_create_project
76

87

98
def test_anntotation_class_new():
10-
projects = sa.search_projects(PROJECT_NAME, return_metadata=True)
11-
for project in projects:
12-
sa.delete_project(project)
13-
14-
sa.create_project(PROJECT_NAME, "tt", "Vector")
159

10+
PROJECT_NAME = "test_anntotation_class_new"
11+
safe_create_project(PROJECT_NAME,'test','Vector')
12+
time.sleep(2)
1613
sa.create_annotation_class(PROJECT_NAME, "tt", "#FFFFFF")
1714

15+
time.sleep(2)
16+
1817
assert len(sa.search_annotation_classes(PROJECT_NAME)) == 1
1918

2019
sa.create_annotation_class(PROJECT_NAME, "tt", "#FFFFFF")
21-
20+
time.sleep(2)
2221
assert len(sa.search_annotation_classes(PROJECT_NAME)) == 1
2322

2423

2524
def test_anntotation_class_new_json():
26-
projects = sa.search_projects(PROJECT_NAME_JSON, return_metadata=True)
27-
for project in projects:
28-
sa.delete_project(project)
2925

30-
sa.create_project(PROJECT_NAME_JSON, "tt", "Vector")
26+
PROJECT_NAME_JSON = "test_anntotation_class_new_json"
27+
safe_create_project(PROJECT_NAME_JSON,'test','Vector')
3128

3229
sa.create_annotation_classes_from_classes_json(
3330
PROJECT_NAME_JSON, "./tests/sample_project_vector/classes/classes.json"
3431
)
3532

33+
time.sleep(2)
3634
assert len(sa.search_annotation_classes(PROJECT_NAME_JSON)) == 4
3735

3836
sa.create_annotation_classes_from_classes_json(
3937
PROJECT_NAME_JSON, "./tests/sample_project_vector/classes/classes.json"
4038
)
39+
time.sleep(2)
4140

4241
assert len(sa.search_annotation_classes(PROJECT_NAME_JSON)) == 4

0 commit comments

Comments
 (0)