diff --git a/ote_sdk/ote_sdk/entities/dataset_item.py b/ote_sdk/ote_sdk/entities/dataset_item.py index a37b48c9dfe..d467b67454c 100644 --- a/ote_sdk/ote_sdk/entities/dataset_item.py +++ b/ote_sdk/ote_sdk/entities/dataset_item.py @@ -110,17 +110,24 @@ def __init__( break self.__roi = roi - self.__metadata: List[MetadataItemEntity] = [] + self.__metadata: Sequence[MetadataItemEntity] = [] if metadata is not None: - self.__metadata = list(metadata) + self.__metadata = metadata self.__ignored_labels: Set[LabelEntity] = ( set() if ignored_labels is None else set(ignored_labels) ) - @property - def metadata(self) -> Sequence[MetadataItemEntity]: - """Provides access to metadata.""" + def set_metadata(self, metadata: Sequence[MetadataItemEntity]): + """ + Sets the metadata + """ + self.__metadata = metadata + + def get_metadata(self) -> Sequence[MetadataItemEntity]: + """ + Returns the metadata + """ return self.__metadata @property @@ -486,6 +493,6 @@ def get_metadata_by_name_and_model( """ return [ meta - for meta in self.metadata + for meta in self.get_metadata() if meta.data.name == name and meta.model == model ] diff --git a/ote_sdk/ote_sdk/tests/entities/test_dataset_item.py b/ote_sdk/ote_sdk/tests/entities/test_dataset_item.py index 71fd3ed1053..3cda1537dc9 100644 --- a/ote_sdk/ote_sdk/tests/entities/test_dataset_item.py +++ b/ote_sdk/ote_sdk/tests/entities/test_dataset_item.py @@ -254,12 +254,12 @@ def test_dataset_item_initialization(self): default_values_dataset_item = DatasetItemEntity(media, annotations_scene) assert default_values_dataset_item.media == media assert default_values_dataset_item.annotation_scene == annotations_scene - assert not default_values_dataset_item.metadata + assert not default_values_dataset_item.get_metadata() assert default_values_dataset_item.subset == Subset.NONE assert default_values_dataset_item.ignored_labels == set() # Checking attributes of DatasetItemEntity object initialized with specified optional parameters roi = DatasetItemParameters().roi() - metadata = DatasetItemParameters.metadata() + metadata = DatasetItemParameters.metadata subset = Subset.TESTING ignored_labels = set(DatasetItemParameters().labels()) specified_values_dataset_item = DatasetItemEntity( @@ -268,7 +268,7 @@ def test_dataset_item_initialization(self): assert specified_values_dataset_item.media == media assert specified_values_dataset_item.annotation_scene == annotations_scene assert specified_values_dataset_item.roi == roi - assert specified_values_dataset_item.metadata == metadata + assert specified_values_dataset_item.get_metadata() == metadata assert specified_values_dataset_item.subset == subset assert specified_values_dataset_item.ignored_labels == ignored_labels @@ -923,7 +923,7 @@ def test_dataset_item_deepcopy(self): dataset_item.annotation_scene.shapes == copy_dataset.annotation_scene.shapes ) assert dataset_item.roi == copy_dataset.roi - assert dataset_item.metadata == copy_dataset.metadata + assert dataset_item.get_metadata() == copy_dataset.get_metadata() assert dataset_item.subset == copy_dataset.subset @pytest.mark.priority_medium @@ -946,7 +946,7 @@ def test_dataset_item_append_metadata_item(self): 2. Check "metadata" attribute after "append_metadata_item" method with specified "model" parameter """ dataset_item = DatasetItemParameters().dataset_item() - expected_metadata = list(dataset_item.metadata) + expected_metadata = dataset_item.get_metadata() # Checking metadata attribute returned after "append_metadata_item" method with non-specified "model" parameter data_to_append = TensorEntity( name="appended_metadata", @@ -954,7 +954,7 @@ def test_dataset_item_append_metadata_item(self): ) expected_metadata.append(MetadataItemEntity(data=data_to_append)) dataset_item.append_metadata_item(data=data_to_append) - assert list(dataset_item.metadata) == expected_metadata + assert dataset_item.get_metadata() == expected_metadata # Checking metadata attribute returned after "append_metadata_item" method with specified "model" parameter metadata_item_with_model = self.metadata_item_with_model() data_to_append = metadata_item_with_model.data @@ -964,7 +964,7 @@ def test_dataset_item_append_metadata_item(self): ) expected_metadata.append(new_metadata_item_with_model) dataset_item.append_metadata_item(data_to_append, model_to_append) - assert list(dataset_item.metadata) == expected_metadata + assert dataset_item.get_metadata() == expected_metadata @pytest.mark.priority_medium @pytest.mark.unit @@ -992,7 +992,7 @@ def test_dataset_item_get_metadata_by_name_and_model(self): metadata_item_with_model = self.metadata_item_with_model() dataset_model = metadata_item_with_model.model dataset_item.append_metadata_item(metadata_item_with_model.data, dataset_model) - dataset_metadata = list(dataset_item.metadata) + dataset_metadata = dataset_item.get_metadata() # Checking "get_metadata_by_name_and_model" method for "model" parameter is "None" assert dataset_item.get_metadata_by_name_and_model("test_metadata", None) == [ dataset_metadata[0] diff --git a/ote_sdk/ote_sdk/tests/entities/test_metadata.py b/ote_sdk/ote_sdk/tests/entities/test_metadata.py index eab01832ac9..9411b5f1a85 100644 --- a/ote_sdk/ote_sdk/tests/entities/test_metadata.py +++ b/ote_sdk/ote_sdk/tests/entities/test_metadata.py @@ -56,7 +56,7 @@ def test_imetadata(self): test_instance = IMetadata() assert isinstance(test_instance, IMetadata) - assert str(test_instance.name) == "typing.Union[str, NoneType]" + assert str(test_instance.name) == "typing.Optional[str]" test_instance.name = "String" assert test_instance.name == "String" diff --git a/ote_sdk/ote_sdk/utils/dataset_utils.py b/ote_sdk/ote_sdk/utils/dataset_utils.py index ae46412c061..02c5e09a86b 100644 --- a/ote_sdk/ote_sdk/utils/dataset_utils.py +++ b/ote_sdk/ote_sdk/utils/dataset_utils.py @@ -91,7 +91,7 @@ def get_local_subset( local_annotations, kind=item.annotation_scene.kind, ), - metadata=item.metadata, + metadata=item.get_metadata(), subset=item.subset, roi=item.roi, ignored_labels=item.ignored_labels, @@ -120,7 +120,7 @@ def get_global_subset(dataset: DatasetEntity) -> DatasetEntity: annotation_scene=AnnotationSceneEntity( global_annotations, kind=item.annotation_scene.kind ), - metadata=item.metadata, + metadata=item.get_metadata(), subset=item.subset, roi=item.roi, ignored_labels=item.ignored_labels,