diff --git a/encord/objects/ontology_labels_impl.py b/encord/objects/ontology_labels_impl.py index ff982337..4a82d4dc 100644 --- a/encord/objects/ontology_labels_impl.py +++ b/encord/objects/ontology_labels_impl.py @@ -51,12 +51,13 @@ BitmaskCoordinates, BoundingBoxCoordinates, Coordinates, + HtmlCoordinates, PointCoordinate, PolygonCoordinates, PolylineCoordinates, RotatableBoundingBoxCoordinates, SkeletonCoordinates, - TextCoordinates, HtmlCoordinates, + TextCoordinates, ) from encord.objects.frames import Frames, Range, Ranges, frames_class_to_frames_list, frames_to_ranges from encord.objects.html_node import HtmlRange @@ -833,11 +834,15 @@ def add_object_instance(self, object_instance: ObjectInstance, force: bool = Tru # We want to ensure that we are only adding the object_instance to a label_row # IF AND ONLY IF the file type is text/html and the object_instance has range_html set if self.file_type == "text/html" and object_instance.range_html is None: - raise LabelRowError("Unable to assign object instance without a html range to a html file. " - f"Please ensure the object instance exists on frame=0, and has coordinates of type {HtmlCoordinates}.") + raise LabelRowError( + "Unable to assign object instance without a html range to a html file. " + f"Please ensure the object instance exists on frame=0, and has coordinates of type {HtmlCoordinates}." + ) elif self.file_type != "text/html" and object_instance.range_html is not None: - raise LabelRowError("Unable to assign object instance with a html range to a non-html file. " - f"Please ensure the object instance does not have coordinates of type {HtmlCoordinates}.") + raise LabelRowError( + "Unable to assign object instance with a html range to a non-html file. " + f"Please ensure the object instance does not have coordinates of type {HtmlCoordinates}." + ) if object_instance.is_assigned_to_label_row(): raise LabelRowError( diff --git a/encord/objects/ontology_object_instance.py b/encord/objects/ontology_object_instance.py index a4bf2961..ad8e3ad0 100644 --- a/encord/objects/ontology_object_instance.py +++ b/encord/objects/ontology_object_instance.py @@ -43,9 +43,11 @@ from encord.objects.constants import DEFAULT_CONFIDENCE, DEFAULT_MANUAL_ANNOTATION from encord.objects.coordinates import ( ACCEPTABLE_COORDINATES_FOR_ONTOLOGY_ITEMS, + NON_GEOMETRIC_COORDINATES, AudioCoordinates, Coordinates, - TextCoordinates, HtmlCoordinates, NON_GEOMETRIC_COORDINATES, + HtmlCoordinates, + TextCoordinates, ) from encord.objects.frames import ( Frames, @@ -960,7 +962,9 @@ def check_coordinate_type(coordinates: Coordinates, ontology_object: Object, par LabelRowError: If the coordinate type does not match the expected type. """ expected_coordinate_types = ACCEPTABLE_COORDINATES_FOR_ONTOLOGY_ITEMS[ontology_object.shape] - if all(not isinstance(coordinates, expected_coordinate_type) for expected_coordinate_type in expected_coordinate_types): + if all( + not isinstance(coordinates, expected_coordinate_type) for expected_coordinate_type in expected_coordinate_types + ): raise LabelRowError( f"Expected coordinates of one of the following types: `{expected_coordinate_types}`, but got type `{type(coordinates)}`." ) @@ -970,16 +974,14 @@ def check_coordinate_type(coordinates: Coordinates, ontology_object: Object, par # HTML files, and `TextCoordinates` are only used for plain text files. if isinstance(coordinates, TextCoordinates): if parent is not None and parent == "text/html": - raise LabelRowError( - f"Expected coordinates of type {HtmlCoordinates}`, but got type `{type(coordinates)}`." - ) + raise LabelRowError(f"Expected coordinates of type {HtmlCoordinates}`, but got type `{type(coordinates)}`.") elif isinstance(coordinates, HtmlCoordinates): if parent is not None and parent.file_type != "text/html": raise LabelRowError( - "For non-html labels, ensure the `range` property " - "is set when instantiating the TextCoordinates." + "For non-html labels, ensure the `range` property " "is set when instantiating the TextCoordinates." ) + class DynamicAnswerManager: """ Manages dynamic answers for different frames of an ObjectInstance. diff --git a/tests/objects/test_label_structure.py b/tests/objects/test_label_structure.py index 4badb8c9..7b556070 100644 --- a/tests/objects/test_label_structure.py +++ b/tests/objects/test_label_structure.py @@ -22,9 +22,10 @@ from encord.objects.coordinates import ( AudioCoordinates, BoundingBoxCoordinates, + HtmlCoordinates, PointCoordinate, PolygonCoordinates, - TextCoordinates, HtmlCoordinates, + TextCoordinates, ) from encord.objects.frames import Range from encord.objects.html_node import HtmlNode, HtmlRange @@ -1381,14 +1382,19 @@ def test_html_text_object_cannot_be_added_to_non_html_label_row( with pytest.raises(LabelRowError) as e: empty_audio_label_row.add_object_instance(obj_instance) - assert str(e.value.message) == ("Unable to assign object instance with a html range to a non-html file. " - f"Please ensure the object instance does not have coordinates of type {HtmlCoordinates}.") + assert str(e.value.message) == ( + "Unable to assign object instance with a html range to a non-html file. " + f"Please ensure the object instance does not have coordinates of type {HtmlCoordinates}." + ) with pytest.raises(LabelRowError) as e: empty_plain_text_label_row.add_object_instance(obj_instance) - assert str(e.value.message) == ("Unable to assign object instance with a html range to a non-html file. " - f"Please ensure the object instance does not have coordinates of type {HtmlCoordinates}.") + assert str(e.value.message) == ( + "Unable to assign object instance with a html range to a non-html file. " + f"Please ensure the object instance does not have coordinates of type {HtmlCoordinates}." + ) + def test_set_for_frames_with_range_html_throws_error_if_used_incorrectly( ontology, empty_html_text_label_row: LabelRowV2, empty_plain_text_label_row: LabelRowV2 @@ -1406,7 +1412,8 @@ def test_set_for_frames_with_range_html_throws_error_if_used_incorrectly( audio_obj_instance.set_for_frames(coordinates=HtmlCoordinates(range=range_html)) assert ( - str(e.value.message) == f"Expected coordinates of one of the following types: `[{AudioCoordinates}]`, but got type `{HtmlCoordinates}`." + str(e.value.message) + == f"Expected coordinates of one of the following types: `[{AudioCoordinates}]`, but got type `{HtmlCoordinates}`." ) # Adding HtmlCoordinates to an object instance which is attached to a label row where the @@ -1418,9 +1425,8 @@ def test_set_for_frames_with_range_html_throws_error_if_used_incorrectly( empty_plain_text_label_row.add_object_instance(html_text_obj_instance) assert ( - str(e.value.message) - == "Unable to assign object instance with a html range to a non-html file. " - f"Please ensure the object instance does not have coordinates of type {HtmlCoordinates}." + str(e.value.message) == "Unable to assign object instance with a html range to a non-html file. " + f"Please ensure the object instance does not have coordinates of type {HtmlCoordinates}." ) @@ -1506,5 +1512,7 @@ def test_plain_text_object_cannot_be_added_to_html_label_row(ontology, empty_htm with pytest.raises(LabelRowError) as e: label_row.add_object_instance(obj_instance) - assert str(e.value.message) == ("Unable to assign object instance without a html range to a html file. " - f"Please ensure the object instance exists on frame=0, and has coordinates of type {HtmlCoordinates}.") + assert str(e.value.message) == ( + "Unable to assign object instance without a html range to a html file. " + f"Please ensure the object instance exists on frame=0, and has coordinates of type {HtmlCoordinates}." + )