Skip to content

Commit

Permalink
Corrected the usage of .metadata or .get_metadata() in certain tests.…
Browse files Browse the repository at this point in the history
… In test_metadata.py I have updated the assertion to "typing.Optional[str]".
  • Loading branch information
A-Artemis committed May 23, 2022
1 parent fcf4925 commit cf33dcb
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
8 changes: 4 additions & 4 deletions ote_sdk/ote_sdk/entities/dataset_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,21 @@ 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)
)

def set_metadata(self, metadata: List[MetadataItemEntity]):
def set_metadata(self, metadata: Sequence[MetadataItemEntity]):
"""
Sets the metadata
"""
self.__metadata = metadata

def get_metadata(self) -> List[MetadataItemEntity]:
def get_metadata(self) -> Sequence[MetadataItemEntity]:
"""
Returns the metadata
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def check_configurable_integer(
assert integer_instance._default == 100
assert integer_instance.type == int
assert len(integer_instance._validator._validators) == 2
assert integer_instance.get_metadata() == expected_metadata
assert integer_instance.metadata == expected_metadata

# Checking _CountingAttr object returned by "configurable_integer" for default values of optional parameters
default_value = 100
Expand Down Expand Up @@ -243,7 +243,7 @@ def check_configurable_float(
assert isinstance(float_instance, _make._CountingAttr)
assert float_instance._default == 100.1
assert float_instance.type == float
assert float_instance.get_metadata() == expected_metadata
assert float_instance.metadata == expected_metadata

# Checking _CountingAttr object returned by "configurable_float" for default values of optional parameters
default_value = 100.1
Expand Down Expand Up @@ -343,7 +343,7 @@ def check_configurable_boolean(
boolean_instance._validator, validators._InstanceOfValidator # type: ignore
)
assert boolean_instance._validator.type == bool
assert boolean_instance.get_metadata() == expected_metadata
assert boolean_instance.metadata == expected_metadata

# Checking _CountingAttr object returned by "configurable_boolean" for default values of optional parameters
default_value = True
Expand Down Expand Up @@ -435,7 +435,7 @@ def check_float_selectable(
assert isinstance(float_selectable_instance, _make._CountingAttr)
assert float_selectable_instance._default
assert float_selectable_instance.type == float
assert float_selectable_instance.get_metadata() == expected_metadata
assert float_selectable_instance.metadata == expected_metadata

# Checking _CountingAttr object returned by "float_selectable" for default values of optional parameters
default_value = 0.1
Expand Down Expand Up @@ -534,7 +534,7 @@ def check_selectable(
assert isinstance(selectable_instance, _make._CountingAttr)
assert selectable_instance._default == SomeEnumSelectable.OPTION_C
assert selectable_instance.type == ConfigurableEnum
assert selectable_instance.get_metadata() == expected_metadata
assert selectable_instance.metadata == expected_metadata

# Checking _CountingAttr object returned by "selectable" for default values of optional parameters
default_value = SomeEnumSelectable.OPTION_C
Expand Down
4 changes: 2 additions & 2 deletions ote_sdk/ote_sdk/tests/configuration/helper/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def test_gather_parameter_arguments_and_values_from_dict(self):
)
assert isinstance(argument, _make._CountingAttr)
assert argument.type == int
metadata = argument.get_metadata()
metadata = argument.metadata
assert metadata.get("default_value") == 70
assert metadata.get("description") == "Default integer description"
assert metadata.get("header") == "non selectable parameter header"
Expand All @@ -492,7 +492,7 @@ def test_gather_parameter_arguments_and_values_from_dict(self):
argument = arguments_and_values_dict.get("make_arguments").get("selectable")
assert isinstance(argument, _make._CountingAttr)
assert argument.type == ConfigurableEnum
metadata = argument.get_metadata()
metadata = argument.metadata
assert type(metadata.get("default_value")).__name__ == "test enum"
assert metadata.get("default_value").name == "test_2"
assert metadata.get("default_value").value == 2
Expand Down
10 changes: 5 additions & 5 deletions ote_sdk/ote_sdk/tests/entities/test_dataset_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def test_dataset_item_initialization(self):
assert default_values_dataset_item.ignored_labels == set()
# Checking attributes of DatasetItemEntity object initialized with specified optional parameters
roi = DatasetItemParameters().roi()
metadata = DatasetItemParameters.get_metadata()
metadata = DatasetItemParameters.metadata
subset = Subset.TESTING
ignored_labels = set(DatasetItemParameters().labels())
specified_values_dataset_item = DatasetItemEntity(
Expand Down Expand Up @@ -946,15 +946,15 @@ 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.get_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",
numpy=np.random.uniform(low=0.0, high=255.0, size=(10, 15, 3)),
)
expected_metadata.append(MetadataItemEntity(data=data_to_append))
dataset_item.append_metadata_item(data=data_to_append)
assert list(dataset_item.get_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
Expand All @@ -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.get_metadata()) == expected_metadata
assert dataset_item.get_metadata() == expected_metadata

@pytest.mark.priority_medium
@pytest.mark.unit
Expand Down Expand Up @@ -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.get_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]
Expand Down
2 changes: 1 addition & 1 deletion ote_sdk/ote_sdk/tests/entities/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 7 additions & 7 deletions ote_sdk/ote_sdk/tests/entities/test_task_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_compare_learning_parameters_num_workers(self):
env.get_hyper_parameters().learning_parameters.num_workers
) # "default_value"
config_example_learning_parameters_num_workers = (
config_example.learning_parameters._default.factory.num_workers.get_metadata()[
config_example.learning_parameters._default.factory.num_workers.metadata[
"default_value"
]
)
Expand Down Expand Up @@ -199,7 +199,7 @@ def test_compare_learning_parameters_batch_size(self):
env.get_hyper_parameters().learning_parameters.batch_size
) # "default_value"
config_example_learning_parameters_batch_size = (
config_example.learning_parameters._default.factory.batch_size.get_metadata()[
config_example.learning_parameters._default.factory.batch_size.metadata[
"default_value"
]
)
Expand Down Expand Up @@ -234,7 +234,7 @@ def test_compare_learning_parameters_num_iters(self):
env.get_hyper_parameters().learning_parameters.num_iters
) # "default_value"
config_example_learning_parameters_num_iters = (
config_example.learning_parameters._default.factory.num_iters.get_metadata()[
config_example.learning_parameters._default.factory.num_iters.metadata[
"default_value"
]
)
Expand Down Expand Up @@ -269,7 +269,7 @@ def test_compare_learning_parameters_learning_rate(self):
env.get_hyper_parameters().learning_parameters.learning_rate
) # "default_value"
config_example_learning_parameters_learning_rate = (
config_example.learning_parameters._default.factory.learning_rate.get_metadata()[
config_example.learning_parameters._default.factory.learning_rate.metadata[
"default_value"
]
)
Expand Down Expand Up @@ -313,7 +313,7 @@ def test_compare_learning_parameters_num_checkpoints(self):
# Attempt to access the missing parameter in ConfigExample
with pytest.raises(AttributeError):
# AttributeError: type object '__LearningParameters' has no attribute 'num_checkpoints'
config_example.learning_parameters._default.factory.num_checkpoints.get_metadata()[
config_example.learning_parameters._default.factory.num_checkpoints.metadata[
"default_value"
]

Expand Down Expand Up @@ -368,7 +368,7 @@ def test_compare_postprocessing_confidence_threshold(self):
)
cep = config_example.postprocessing
config_example_postprocessing_confidence_threshold = (
cep._default.factory.confidence_threshold.get_metadata()["default_value"]
cep._default.factory.confidence_threshold.metadata["default_value"]
)

# From dummy_config.yaml because it is missing in dummy_template.yaml "parameter_overrides"
Expand Down Expand Up @@ -404,7 +404,7 @@ def test_compare_postprocessing_result_based_confidence_threshold(self):
cep = config_example.postprocessing
def_factory = cep._default.factory
rbct = def_factory.result_based_confidence_threshold
config_example_postprocessing_result_based_confidence_threshold = rbct.get_metadata()[
config_example_postprocessing_result_based_confidence_threshold = rbct.metadata[
"default_value"
]

Expand Down

0 comments on commit cf33dcb

Please sign in to comment.