Skip to content

Commit ffb09f1

Browse files
committed
Add test - fix meta validation
1 parent 8909f91 commit ffb09f1

File tree

2 files changed

+64
-6
lines changed

2 files changed

+64
-6
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,15 @@ def __get_validators__(cls):
9999
@classmethod
100100
def return_action(cls, values):
101101
try:
102+
loc = []
102103
try:
103-
instance_type = values["meta"]["type"]
104+
loc = ["meta"]
105+
meta_data = values["meta"]
106+
loc.append("type")
107+
instance_type = meta_data["type"]
104108
except KeyError:
105109
raise ValidationError(
106-
[ErrorWrapper(ValueError("meta.field required"), "type")], cls
110+
[ErrorWrapper(ValueError("field required"), ".".join(loc))], cls
107111
)
108112
return INSTANCES[instance_type](**values)
109113
except KeyError:
@@ -119,7 +123,17 @@ def return_action(cls, values):
119123
cls,
120124
)
121125
except TypeError as e:
122-
raise TypeError(INVALID_DICT_MESSAGE) from e
126+
raise ValidationError(
127+
[
128+
ErrorWrapper(
129+
ValueError(
130+
INVALID_DICT_MESSAGE
131+
),
132+
"meta",
133+
)
134+
],
135+
cls,
136+
)
123137

124138

125139
class VideoAnnotation(BaseModel):

tests/unit/test_validators.py

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,10 +1193,11 @@ def test_validate_video_invalid_instace_without_type_and_attr_annotation(self):
11931193
'''
11941194
)
11951195

1196+
11961197
with catch_prints() as out:
11971198
sa.validate_annotations("Video", os.path.join(self.vector_folder_path,
11981199
f"{tmpdir_name}/test_validate_video_invalid_instace_without_type_and_attr_annotation.json"))
1199-
self.assertIn("instances[2].typemeta.fieldrequired", out.getvalue().strip().replace(" ", ""))
1200+
self.assertIn("instances[2].meta.typefieldrequired", out.getvalue().strip().replace(" ", ""))
12001201

12011202
def test_validate_vector_temlpate_polygon_polyline_min_annotation(self):
12021203
with tempfile.TemporaryDirectory() as tmpdir_name:
@@ -1933,7 +1934,8 @@ def test_validate_video_point_labels_bad_keys(self):
19331934
"classId": 859496,
19341935
"className": "vid",
19351936
"start": 5528212,
1936-
"end": 7083022
1937+
"end": 7083022,
1938+
"pointLabels": {}
19371939
},
19381940
"parameters": [
19391941
{
@@ -1969,6 +1971,48 @@ def test_validate_video_point_labels_bad_keys(self):
19691971
]
19701972
}
19711973
]
1974+
},
1975+
{
1976+
"parameters": [
1977+
{
1978+
"start": 5528212,
1979+
"end": 7083022,
1980+
"timestamps": [
1981+
{
1982+
"timestamp": 5528212,
1983+
"attributes": []
1984+
},
1985+
{
1986+
"timestamp": 6702957,
1987+
"attributes": [
1988+
{
1989+
"id": 1175876,
1990+
"groupId": 338357,
1991+
"name": "attr",
1992+
"groupName": "attr g"
1993+
}
1994+
]
1995+
},
1996+
{
1997+
"timestamp": "7083022",
1998+
"attributes": [
1999+
{
2000+
"id": 1175876,
2001+
"groupId": 338357,
2002+
"name": "attr",
2003+
"groupName": "attr g"
2004+
}
2005+
]
2006+
}
2007+
]
2008+
}
2009+
]
2010+
},
2011+
{
2012+
"meta": "afsdfadsf"
2013+
},
2014+
{
2015+
"meta" : []
19722016
}
19732017
],
19742018
"tags": [
@@ -1982,5 +2026,5 @@ def test_validate_video_point_labels_bad_keys(self):
19822026
sa.validate_annotations("Video", os.path.join(self.vector_folder_path,
19832027
f"{tmpdir_name}/test_validate_video_point_labels_bad_keys.json"))
19842028
self.assertEqual(
1985-
"instances[0].meta.pointLabels.bad_key_1doesnotmatchexpectedformat^[0-9]*$\ninstances[0].meta.pointLabels.bad_key_2doesnotmatchexpectedformat^[0-9]*$\ninstances[0].meta.pointLabels.doesnotmatchexpectedformat^[0-9]*$\ninstances[0].meta.pointLabels.1strtypeexpected\ninstances[2].parameters[0].timestamps[2].timestampintegertypeexpected\ntags[0]strtypeexpected",
2029+
"instances[0].meta.pointLabels.bad_key_1doesnotmatchexpectedformat^[0-9]*$\ninstances[0].meta.pointLabels.bad_key_2doesnotmatchexpectedformat^[0-9]*$\ninstances[0].meta.pointLabels.doesnotmatchexpectedformat^[0-9]*$\ninstances[0].meta.pointLabels.1strtypeexpected\ninstances[2].meta.pointLabelsextrafieldsnotpermitted\ninstances[2].parameters[0].timestamps[2].timestampintegertypeexpected\ninstances[3].metafieldrequired\ninstances[4].metavalueisnotavaliddict\ninstances[5].metavalueisnotavaliddict\ntags[0]strtypeexpected",
19862030
out.getvalue().strip().replace(" ", ""))

0 commit comments

Comments
 (0)