Skip to content

Commit dfc1e42

Browse files
committed
Add class id test - error wrapper test
1 parent 490a32e commit dfc1e42

File tree

3 files changed

+120
-21
lines changed

3 files changed

+120
-21
lines changed

src/superannotate/lib/core/entities/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def enum_error_handling(self) -> str:
2626

2727
DATE_REGEX = r"\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d(?:\.\d{3})Z"
2828

29-
DATE_TIME_FORMAT_ERROR_MESSAGE = "Expected format: YYYY-mm-ddTHH:MM:SS.055Z"
29+
DATE_TIME_FORMAT_ERROR_MESSAGE = "does not match expected format YYYY-MM-DDTHH:MM:SS.fffZ"
3030

3131

3232
class BaseModel(PyDanticBaseModel):
@@ -151,7 +151,7 @@ class LastUserAction(BaseModel):
151151

152152

153153
class BaseInstance(TrackableModel, TimedBaseModel):
154-
class_id: Optional[str] = Field(None, alias="classId")
154+
class_id: Optional[int] = Field(None, alias="classId")
155155
class_name: Optional[str] = Field(None, alias="className")
156156

157157

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,38 @@
1-
{"metadata":{"name":"text_file_example_1","status":"Completed","url":"https://sa-public-files.s3.us-west-2.amazonaws.com/Text+project/text_file_example_1.txt","projectId":160158,"annotatorEmail":null,"qaEmail":null,"lastAction":{"email":"shab.prog@gmail.com","timestamp":1634899229953}},"instances":[{"start":253,"end":593,"classId":873208,"createdAt":"2021-10-22T10:40:26.151Z","createdBy":{"email":"shab.prog@gmail.com","role":"Admin"},"updatedAt":"2021-10-22T10:40:29.953Z","updatedBy":{"email":"shab.prog@gmail.com","role":"Admin"},"attributes":[],"creationType":"Manual","className":"vid"}],"tags":["vid"],"freeText":""}
1+
{
2+
"metadata": {
3+
"name": "text_file_example_1",
4+
"status": "Completed",
5+
"url": "https://sa-public-files.s3.us-west-2.amazonaws.com/Text+project/text_file_example_1.txt",
6+
"projectId": 160158,
7+
"annotatorEmail": null,
8+
"qaEmail": null,
9+
"lastAction": {
10+
"email": "shab.prog@gmail.com",
11+
"timestamp": 1634899229953
12+
}
13+
},
14+
"instances": [
15+
{
16+
"start": 253,
17+
"end": 593,
18+
"classId": 873208,
19+
"createdAt": "2021-10-22T10:40:26.151Z",
20+
"createdBy": {
21+
"email": "shab.prog@gmail.com",
22+
"role": "Admin"
23+
},
24+
"updatedAt": "2021-10-22T10:40:29.953Z",
25+
"updatedBy": {
26+
"email": "shab.prog@gmail.com",
27+
"role": "Admin"
28+
},
29+
"attributes": [],
30+
"creationType": "Manual",
31+
"className": "vid"
32+
}
33+
],
34+
"tags": [
35+
"vid"
36+
],
37+
"freeText": ""
38+
}

tests/unit/test_validators.py

Lines changed: 80 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"width": 1024,
1717
"height": 683,
1818
"status": "Completed",
19-
"pinned": False,
20-
"isPredicted": None,
21-
"projectId": None,
22-
"annotatorEmail": None,
23-
"qaEmail": None
19+
"pinned": false,
20+
"isPredicted": null,
21+
"projectId": null,
22+
"annotatorEmail": null,
23+
"qaEmail": null
2424
},
2525
"instances": [
2626
{
@@ -35,8 +35,8 @@
3535
},
3636
"groupId": 0,
3737
"pointLabels": {},
38-
"locked": False,
39-
"visible": False,
38+
"locked": false,
39+
"visible": false,
4040
"attributes": [
4141
{
4242
"id": 117845,
@@ -46,12 +46,12 @@
4646
}
4747
],
4848
"trackingId": "aaa97f80c9e54a5f2dc2e920fc92e5033d9af45b",
49-
"error": None,
50-
"createdAt": None,
51-
"createdBy": None,
52-
"creationType": None,
53-
"updatedAt": None,
54-
"updatedBy": None,
49+
"error": null,
50+
"createdAt": null,
51+
"createdBy": null,
52+
"creationType": null,
53+
"updatedAt": null,
54+
"updatedBy": null,
5555
"className": "Personal vehicle"
5656
}
5757
]
@@ -76,7 +76,7 @@ def test_validate_annotation_with_wrong_bbox(self):
7676
vector_json.write(VECTOR_ANNOTATION_JSON_WITH_BBOX)
7777
with catch_prints() as out:
7878
sa.validate_annotations("Vector", os.path.join(self.vector_folder_path, f"{tmpdir_name}/vector.json"))
79-
self.assertEqual("instances[0].points[x1]fieldrequired", out.getvalue().strip().replace(" ", ""))
79+
self.assertIn("instances[0].points.x1fieldrequired", out.getvalue().strip().replace(" ", ""))
8080

8181
def test_validate_annotation_without_metadata(self):
8282
with tempfile.TemporaryDirectory() as tmpdir_name:
@@ -89,7 +89,7 @@ def test_validate_annotation_without_metadata(self):
8989
self.assertIn("metadatafieldrequired", out.getvalue().strip().replace(" ", ""))
9090

9191
def test_validate_annotation_invalid_date_time_format(self):
92-
with self.assertRaisesRegexp(ValidationError,"Expected format: YYYY-mm-ddTHH:MM:SS.055Z"):
92+
with self.assertRaisesRegexp(ValidationError,"does not match expected format YYYY-MM-DDTHH:MM:SS.fffZ"):
9393
TimedBaseModel(createdAt="2021-11-02T15:11:50.065000Z")
9494

9595
def test_validate_annotation_valid_date_time_format(self):
@@ -187,7 +187,7 @@ def test_validate_document_annotation(self):
187187
"annotatorEmail": null,
188188
"qaEmail": null,
189189
"lastAction": {
190-
"email": "some.email@gmail.com"
190+
"email": "some.email@gmail.com",
191191
"timestamp": 1636620976450
192192
}
193193
},
@@ -208,7 +208,7 @@ def test_validate_pixel_annotation(self):
208208
{
209209
"metadata": {
210210
"lastAction": {
211-
"email": "some.email@gmail.com"
211+
"email": "some.email@gmail.com",
212212
"timestamp": 1636627539398
213213
},
214214
"width": 1024,
@@ -269,7 +269,7 @@ def test_validate_vector_empty_annotation(self):
269269
{
270270
"metadata": {
271271
"lastAction": {
272-
"email": "shab.prog@gmail.com",
272+
"email": "some.email@gmail.com",
273273
"timestamp": 1636627956948
274274
},
275275
"width": 1024,
@@ -290,3 +290,65 @@ def test_validate_vector_empty_annotation(self):
290290
)
291291
self.assertTrue(sa.validate_annotations("Vector", os.path.join(self.vector_folder_path,
292292
f"{tmpdir_name}/vector_empty.json")))
293+
294+
def test_validate_error_message_format(self):
295+
with tempfile.TemporaryDirectory() as tmpdir_name:
296+
with open(f"{tmpdir_name}/test_validate_error_message_format.json", "w") as test_validate_error_message_format:
297+
test_validate_error_message_format.write(
298+
'''
299+
{
300+
"metadata": {}
301+
}
302+
'''
303+
)
304+
with catch_prints() as out:
305+
sa.validate_annotations("Vector", os.path.join(self.vector_folder_path,
306+
f"{tmpdir_name}/test_validate_error_message_format.json"))
307+
self.assertIn("metadata.namefieldrequired", out.getvalue().strip().replace(" ", ""))
308+
309+
310+
def test_validate_document_annotation_wrong_class_id(self):
311+
with tempfile.TemporaryDirectory() as tmpdir_name:
312+
with open(f"{tmpdir_name}/test_validate_document_annotation_wrong_class_id.json", "w") as test_validate_document_annotation_wrong_class_id:
313+
test_validate_document_annotation_wrong_class_id.write(
314+
'''
315+
{
316+
"metadata": {
317+
"name": "text_file_example_1",
318+
"status": "NotStarted",
319+
"url": "https://sa-public-files.s3.us-west-2.amazonaws.com/Text+project/text_file_example_1.txt",
320+
"projectId": 167826,
321+
"annotatorEmail": null,
322+
"qaEmail": null,
323+
"lastAction": {
324+
"email": "some.email@gmail.com",
325+
"timestamp": 1636620976450
326+
}
327+
},
328+
"instances": [{
329+
"start": 253,
330+
"end": 593,
331+
"classId": "string",
332+
"createdAt": "2021-10-22T10:40:26.151Z",
333+
"createdBy": {
334+
"email": "some.email@gmail.com",
335+
"role": "Admin"
336+
},
337+
"updatedAt": "2021-10-22T10:40:29.953Z",
338+
"updatedBy": {
339+
"email": "some.email@gmail.com",
340+
"role": "Admin"
341+
},
342+
"attributes": [],
343+
"creationType": "Manual",
344+
"className": "vid"
345+
}],
346+
"tags": [],
347+
"freeText": ""
348+
}
349+
'''
350+
)
351+
with catch_prints() as out:
352+
sa.validate_annotations("Document", os.path.join(self.vector_folder_path, f"{tmpdir_name}/test_validate_document_annotation_wrong_class_id.json"))
353+
self.assertIn("instances[0].classIdintegertypeexpected", out.getvalue().strip().replace(" ", ""))
354+

0 commit comments

Comments
 (0)