def test_label_entity_serialization(self):
        """
        This test serializes LabelEntity and checks serialized representation.
        Then it compares deserialized LabelEntity with original one.
        """

        cur_date = now()
        red = randint(0, 255)  # nosec
        green = randint(0, 255)  # nosec
        blue = randint(0, 255)  # nosec
        alpha = randint(0, 255)  # nosec

        label = LabelEntity(
            name="my_label",
            domain=Domain.DETECTION,
            color=Color(red, green, blue, alpha),
            hotkey="ctrl+1",
            creation_date=cur_date,
            is_empty=False,
            id=ID("0000213"),
        )
        serialized = LabelMapper.forward(label)

        assert serialized == {
            "_id": "0000213",
            "name": "my_label",
            "color": {"red": red, "green": green, "blue": blue, "alpha": alpha},
            "hotkey": "ctrl+1",
            "domain": "DETECTION",
            "creation_date": DatetimeMapper.forward(cur_date),
            "is_empty": False,
        }

        deserialized = LabelMapper.backward(serialized)
        assert label == deserialized
    def convert_to_annotation(
            self,
            predictions: np.ndarray,
            metadata: Optional[Dict] = None) -> AnnotationSceneEntity:
        """
        Converts a set of predictions into an AnnotationScene object

        :param predictions: Prediction with shape [num_predictions, 6] or
                            [num_predictions, 7]
        Supported detection formats are

        * [label, confidence, x1, y1, x2, y2]
        * [_, label, confidence, x1, y1, x2, y2]

        .. note::
           `label` can be any integer that can be mapped to `self.labels`
           `confidence` should be a value between 0 and 1
           `x1`, `x2`, `y1` and `y2` are expected to be normalized.

        :returns AnnotationScene: AnnotationScene Object containing the boxes
                                  obtained from the prediction
        """
        annotations = self.__convert_to_annotations(predictions)
        # media_identifier = ImageIdentifier(image_id=ID())
        annotation_scene = AnnotationSceneEntity(
            id=ID(),
            kind=AnnotationSceneKind.PREDICTION,
            editor="ote",
            creation_date=now(),
            annotations=annotations,
        )

        return annotation_scene
    def __init__(
        self,
        points: List[Point],
        labels: Optional[List[ScoredLabel]] = None,
        modification_date: Optional[datetime.datetime] = None,
    ):
        labels = [] if labels is None else labels
        modification_date = now(
        ) if modification_date is None else modification_date
        super().__init__(
            type=ShapeType.POLYGON,
            labels=labels,
            modification_date=modification_date,
        )

        if len(points) == 0:
            raise ValueError("Cannot create polygon with no points")

        self.points = points

        self.min_x = min(points, key=attrgetter("x")).x
        self.max_x = max(points, key=attrgetter("x")).x
        self.min_y = min(points, key=attrgetter("y")).y
        self.max_y = max(points, key=attrgetter("y")).y

        is_valid = True
        for (x, y) in [(self.min_x, self.min_y), (self.max_x, self.max_y)]:
            is_valid = is_valid and self._validate_coordinates(x, y)
        if not is_valid:
            points_str = "; ".join(str(p) for p in self.points)
            warnings.warn(
                f"{type(self).__name__} coordinates are invalid : {points_str}",
                UserWarning,
            )
    def __init__(
        self,
        x1: float,
        y1: float,
        x2: float,
        y2: float,
        labels: Optional[List[ScoredLabel]] = None,
        modification_date: Optional[datetime.datetime] = None,
    ):
        labels = [] if labels is None else labels
        modification_date = now(
        ) if modification_date is None else modification_date
        super().__init__(
            type=ShapeType.ELLIPSE,
            labels=labels,
            modification_date=modification_date,
        )

        for (x, y) in [(x1, y1), (x2, y2)]:
            self._validate_coordinates(x, y)

        self.x1 = x1
        self.y1 = y1
        self.x2 = x2
        self.y2 = y2
        if self.width <= 0 or self.height <= 0:
            raise ValueError(
                f"Invalid Ellipse with coordinates: x1={self.x1}, y1={self.y1}, x2={self.x2},"
                f" y2={self.y2}")
    def __init__(
        self,
        x1: float,
        y1: float,
        x2: float,
        y2: float,
        labels: Optional[List[ScoredLabel]] = None,
        modification_date: Optional[datetime.datetime] = None,
    ):
        labels = [] if labels is None else labels
        modification_date = now(
        ) if modification_date is None else modification_date
        super().__init__(
            type=ShapeType.RECTANGLE,
            labels=labels,
            modification_date=modification_date,
        )

        is_valid = True
        for (x, y) in [(x1, y1), (x2, y2)]:
            is_valid = is_valid and self._validate_coordinates(x, y)
        if not is_valid:
            warnings.warn(
                f"{type(self).__name__} coordinates are invalid : x1={x1}, y1={y1}, x2={x2}, y2={y2}",
                UserWarning,
            )

        self.x1 = x1
        self.y1 = y1
        self.x2 = x2
        self.y2 = y2
        if self.width <= 0 or self.height <= 0:
            raise ValueError(
                f"Invalid rectangle with coordinates: x1={self.x1}, y1={self.y1}, "
                f"x2={self.x2}, y2={self.y2}")
Exemple #6
0
    def backward(instance: Union[None, str]) -> datetime.datetime:
        """Deserializes datetime from str or create new one if it is None"""

        if isinstance(instance, str):
            modification_date = datetime.datetime.strptime(
                instance, "%Y-%m-%dT%H:%M:%S.%f"
            )
            return modification_date.replace(tzinfo=datetime.timezone.utc)

        return now()
Exemple #7
0
    def test_serialization_deserialization(self):
        """
        This test serializes datetime, deserializes serialized datetime and compares with original one.
        """

        original_time = now()
        serialized_time = DatetimeMapper.forward(original_time)
        assert serialized_time == original_time.strftime(
            "%Y-%m-%dT%H:%M:%S.%f")

        deserialized_time = DatetimeMapper.backward(serialized_time)
        assert original_time == deserialized_time
 def __init__(
     self,
     annotations: List[Annotation],
     kind: AnnotationSceneKind,
     editor: str = "",
     creation_date: Optional[datetime.datetime] = None,
     id: Optional[ID] = None,
 ):
     self.__annotations = annotations
     self.__kind = kind
     self.__editor = editor
     self.__creation_date = now(
     ) if creation_date is None else creation_date
     self.__id = ID() if id is None else id
 def __init__(
     self,
     model: ModelEntity,
     ground_truth_dataset: DatasetEntity,
     prediction_dataset: DatasetEntity,
     purpose: ResultsetPurpose = ResultsetPurpose.EVALUATION,
     performance: Optional[Performance] = None,
     creation_date: Optional[datetime.datetime] = None,
     id: Optional[ID] = None,
 ):
     id = ID() if id is None else id
     performance = NullPerformance() if performance is None else performance
     creation_date = now() if creation_date is None else creation_date
     self.__id = id
     self.__model = model
     self.__prediction_dataset = prediction_dataset
     self.__ground_truth_dataset = ground_truth_dataset
     self.__performance = performance
     self.__purpose = purpose
     self.__creation_date = creation_date
    def __init__(
        self,
        name: str,
        domain: Domain,
        color: Optional[Color] = None,
        hotkey: str = "",
        creation_date: Optional[datetime.datetime] = None,
        is_empty: bool = False,
        id: Optional[ID] = None,
    ):
        id = ID() if id is None else id
        color = Color.random() if color is None else color
        creation_date = now() if creation_date is None else creation_date
        if not hotkey and is_empty:
            hotkey = "ctrl+0"

        self._name = name
        self._color = color
        self._hotkey = hotkey
        self._domain = domain
        self._is_empty = is_empty
        self._creation_date = creation_date
        self._id = id
Exemple #11
0
class TestLabelEntity:

    creation_date = now()

    label_car_params = {
        "name": "car",
        "domain": Domain.DETECTION,
        "color": Color(255, 0, 0),
        "hotkey": "ctrl+1",
        "creation_date": creation_date,
        "is_empty": False,
        "id": ID(123456789),
    }

    label_person_params = {
        "name": "person",
        "domain": Domain.DETECTION,
        "color": Color(255, 17, 17),
        "hotkey": "ctrl+2",
        "creation_date": creation_date,
        "is_empty": False,
        "id": ID(987654321),
    }
    car = LabelEntity(**label_car_params)  # type: ignore
    empty = LabelEntity(name="empty",
                        domain=Domain.SEGMENTATION,
                        is_empty=True)
    person = LabelEntity(**label_person_params)  # type: ignore

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_label_entity(self):
        """
        <b>Description:</b>
        Check the LabelEntity can correctly return the value

        <b>Input data:</b>
        Dummy data

        <b>Expected results:</b>
        Test passes if incoming data is processed correctly

        <b>Steps</b>
        1. Use already created dummy data
        2. Check the processing of default values
        3. Check the processing of changed values
        """

        assert self.car == LabelEntity(**self.label_car_params)
        assert self.car != Domain
        assert self.car != self.person

        for attr in [
                "name",
                "domain",
                "color",
                "hotkey",
                "creation_date",
                "is_empty",
                "id",
        ]:
            assert getattr(self.car, attr) == self.label_car_params[attr]

        label_car_new_name = "electric car"
        label_car_new_domain = Domain.CLASSIFICATION
        label_car_new_color = Color(0, 255, 0)
        label_car_new_hotkey = "ctrl+2"
        label_car_new_id = ID(987654321)

        setattr(self.car, "name", label_car_new_name)
        setattr(self.car, "domain", label_car_new_domain)
        setattr(self.car, "color", label_car_new_color)
        setattr(self.car, "hotkey", label_car_new_hotkey)
        setattr(self.car, "id", label_car_new_id)

        assert self.car.name == label_car_new_name
        assert self.car.domain == label_car_new_domain
        assert self.car.color == label_car_new_color
        assert self.car.hotkey == label_car_new_hotkey
        assert self.car.id == label_car_new_id

        test_label_entity_repr = [
            f"{self.car.id}",
            f"name={self.car.name}",
            f"hotkey={self.car.hotkey}",
            f"domain={self.car.domain}",
            f"color={self.car.color}",
        ]

        for i in test_label_entity_repr:
            assert i in self.car.__repr__()

        assert hash(self.car) == hash(str(self.car))
        assert self.car.__lt__(Domain) is False
        assert self.car.__gt__(Domain) is False

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_empty_label_entity(self):
        """
        <b>Description:</b>
        Check the LabelEntity can correctly return the value for empty label

        <b>Input data:</b>
        Dummy data

        <b>Expected results:</b>
        Test passes if incoming data is processed correctly

        <b>Steps</b>
        1. Use already created dummy data
        2. Check the processing of default values
        """

        assert self.empty.hotkey == "ctrl+0"
        assert self.empty.id == ID()
        assert type(self.empty.color) == Color

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_label_comparison(self):
        """
        <b>Description:</b>
        Check the LabelEntity __lt__, __gt__ methods with changed id

        <b>Input data:</b>
        Dummy data

        <b>Expected results:</b>
        Test passes if incoming data is processed correctly

        <b>Steps</b>
        1. Use already created dummy data
        2. Check the processing of changed id
        """

        self.empty.id = ID(999999999)
        assert self.empty > self.car
        assert self.car < self.empty
class TestModelEntity:
    creation_date = now()

    def generate_random_image(self):
        with generate_random_single_image() as path:
            image = Image(file_path=path)
            return DatasetItemEntity(
                media=image, annotation_scene=NullAnnotationSceneEntity())

    def dataset(self):
        return DatasetEntity(items=[self.generate_random_image()])

    def configuration(self):
        parameters = ConfigurableParameters(header="Test header")
        label_schema = LabelSchemaEntity()
        return ModelConfiguration(configurable_parameters=parameters,
                                  label_schema=label_schema)

    def other_configuration(self):
        parameters = ConfigurableParameters(header="Other test header")
        label_schema = LabelSchemaEntity()
        return ModelConfiguration(configurable_parameters=parameters,
                                  label_schema=label_schema)

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_model_entity_default_values(self):
        """
        <b>Description:</b>
        Check that ModelEntity correctly returns the default values

        <b>Expected results:</b>
        Test passes if ModelEntity correctly returns the default values

        <b>Steps</b>
        1. Check default values in the ModelEntity
        """

        model_entity = ModelEntity(train_dataset=self.dataset(),
                                   configuration=self.configuration())

        assert model_entity.id == ID()
        assert type(model_entity.configuration) == ModelConfiguration
        assert type(model_entity.creation_date) == datetime
        assert type(model_entity.train_dataset) == DatasetEntity
        assert model_entity.version == 1
        assert model_entity.model_status == ModelStatus.SUCCESS
        assert model_entity.model_format == ModelFormat.OPENVINO
        assert model_entity.precision == [ModelPrecision.FP32]
        assert model_entity.target_device == TargetDevice.CPU
        assert model_entity.optimization_type == ModelOptimizationType.NONE
        assert model_entity.performance == NullPerformance()

        for default_val_none in [
                "previous_trained_revision",
                "previous_revision",
                "target_device_type",
        ]:
            assert getattr(model_entity, default_val_none) is None

        for default_val_0_0 in ["training_duration", "model_size_reduction"]:
            assert getattr(model_entity, default_val_0_0) == 0.0

        for default_val_empty_list in ["tags", "optimization_methods"]:
            assert getattr(model_entity, default_val_empty_list) == []

        for default_val_empty_dict in [
                "model_adapters",
                "optimization_objectives",
                "performance_improvement",
        ]:
            assert getattr(model_entity, default_val_empty_dict) == {}

        for default_val_zero in ["latency", "fps_throughput"]:
            assert getattr(model_entity, default_val_zero) == 0

        assert model_entity.is_optimized() is False

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_model_entity_sets_values(self):
        """
        <b>Description:</b>
        Check that ModelEntity correctly returns the set values

        <b>Expected results:</b>
        Test passes if ModelEntity correctly returns the set values

        <b>Steps</b>
        1. Check set values in the ModelEntity
        """
        def __get_path_to_file(filename: str):
            """
            Return the path to the file named 'filename', which lives in the tests/entities directory
            """
            return str(Path(__file__).parent / Path(filename))

        car = LabelEntity(name="car", domain=Domain.DETECTION)
        labels_list = [car]
        dummy_template = __get_path_to_file("./dummy_template.yaml")
        model_template = parse_model_template(dummy_template)
        hyper_parameters = model_template.hyper_parameters.data
        params = ote_config_helper.create(hyper_parameters)
        labels_schema = LabelSchemaEntity.from_labels(labels_list)
        environment = TaskEnvironment(
            model=None,
            hyper_parameters=params,
            label_schema=labels_schema,
            model_template=model_template,
        )

        item = self.generate_random_image()
        dataset = DatasetEntity(items=[item])
        score_metric = ScoreMetric(name="Model accuracy", value=0.5)

        model_entity = ModelEntity(train_dataset=self.dataset(),
                                   configuration=self.configuration())

        set_params = {
            "configuration": environment.get_model_configuration(),
            "train_dataset": dataset,
            "id": ID(1234567890),
            "creation_date": self.creation_date,
            "previous_trained_revision": 5,
            "previous_revision": 2,
            "version": 2,
            "tags": ["tree", "person"],
            "model_status": ModelStatus.TRAINED_NO_STATS,
            "model_format": ModelFormat.BASE_FRAMEWORK,
            "performance": Performance(score_metric),
            "training_duration": 5.8,
            "precision": [ModelPrecision.INT8],
            "latency": 328,
            "fps_throughput": 20,
            "target_device": TargetDevice.GPU,
            "target_device_type": "notebook",
            "optimization_methods": [OptimizationMethod.QUANTIZATION],
            "optimization_type": ModelOptimizationType.MO,
            "optimization_objectives": {
                "param": "Test param"
            },
            "performance_improvement": {"speed", 0.5},
            "model_size_reduction": 1.0,
        }

        for key, value in set_params.items():
            setattr(model_entity, key, value)
            assert getattr(model_entity, key) == value

        assert model_entity.is_optimized() is True

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_model_entity_model_adapters(self):
        """
        <b>Description:</b>
        Check that ModelEntity correctly returns the adapters

        <b>Expected results:</b>
        Test passes if ModelEntity correctly returns the adapters

        <b>Steps</b>
        1. Create a ModelEntity with adapters
        2. Change data source for an adapter
        3. Remove an adapter
        """

        data_source_0 = b"{0: binaryrepo://localhost/repo/data_source/0}"
        data_source_1 = b"binaryrepo://localhost/repo/data_source/1"
        data_source_2 = b"binaryrepo://localhost/repo/data_source/2"
        data_source_3 = b"binaryrepo://localhost/repo/data_source/3"

        temp_dir = tempfile.TemporaryDirectory()
        temp_file = os.path.join(temp_dir.name, "data_source_0")

        with open(temp_file, "wb") as tmp:
            tmp.write(data_source_0)

        model_adapters = {
            "0": ModelAdapter(data_source=data_source_0),
            "1": ModelAdapter(data_source=data_source_1),
            "2": ModelAdapter(data_source=data_source_2),
        }

        model_entity = ModelEntity(
            train_dataset=self.dataset(),
            configuration=self.configuration(),
            model_adapters=model_adapters,
        )

        assert model_entity.weight_paths == {}

        # Adapter with key 0 not from file
        assert model_entity.model_adapters["0"].from_file_storage is False

        model_entity.set_data("0", temp_file)

        for adapter in model_entity.model_adapters:
            if adapter == "0":
                # Adapter with key 0 from file
                assert model_entity.model_adapters[
                    adapter].from_file_storage is True
            else:
                assert model_entity.model_adapters[
                    adapter].from_file_storage is False

        assert model_entity.get_data("1") == data_source_1

        model_entity.set_data("2", data_source_1)
        assert model_entity.get_data("2") == data_source_1
        assert len(model_entity.model_adapters) == 3

        model_entity.set_data("3", data_source_3)
        assert model_entity.get_data("3") == data_source_3
        assert len(model_entity.model_adapters) == 4

        model_entity.delete_data("3")
        assert len(model_entity.model_adapters) == 3

        # Attempt to retrieve a missing and deleted key
        with pytest.raises(KeyError):
            model_entity.get_data("5")

        with pytest.raises(KeyError):
            model_entity.get_data("3")

        # The presence of outdated code in ModelEntity "model_adapter.data_source.binary_url"
        with pytest.raises(AttributeError):
            assert model_entity.weight_paths == {"0": temp_file}

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_model_entity__eq__(self):
        """
        <b>Description:</b>
        Check that ModelEntity __eq__ method

        <b>Expected results:</b>
        Test passes if ModelEntity equal ModelEntity and not equal another type
        """
        dataset = self.dataset()
        other_model_entity = ModelEntity(train_dataset=dataset,
                                         configuration=self.configuration())
        model_entity = ModelEntity(train_dataset=dataset,
                                   configuration=self.configuration())
        third_model_entity = ModelEntity(
            train_dataset=self.dataset(),
            configuration=self.other_configuration())
        assert model_entity.__eq__("") is False
        assert model_entity == other_model_entity
        assert model_entity != third_model_entity
    def test_flat_label_schema_serialization(self):
        """
        This test serializes flat LabelSchema and checks serialized representation.
        Then it compares deserialized LabelSchema with original one.
        """

        cur_date = now()
        names = ["cat", "dog", "mouse"]
        colors = [
            Color(
                randint(0, 255),  # nosec
                randint(0, 255),  # nosec
                randint(0, 255),  # nosec
                randint(0, 255),  # nosec
            )  # nosec  # noqa
            for _ in range(3)
        ]
        labels = [
            LabelEntity(
                name=name,
                domain=Domain.CLASSIFICATION,
                creation_date=cur_date,
                id=ID(i),
                color=colors[i],
            )
            for i, name in enumerate(names)
        ]
        label_shema = LabelSchemaEntity.from_labels(labels)
        serialized = LabelSchemaMapper.forward(label_shema)

        assert serialized == {
            "label_tree": {"type": "tree", "directed": True, "nodes": [], "edges": []},
            "exclusivity_graph": {
                "type": "graph",
                "directed": False,
                "nodes": [],
                "edges": [],
            },
            "label_groups": [
                {
                    "_id": label_shema.get_groups()[0].id,
                    "name": "from_label_list",
                    "label_ids": ["0", "1", "2"],
                    "relation_type": "EXCLUSIVE",
                }
            ],
            "all_labels": {
                "0": {
                    "_id": "0",
                    "name": "cat",
                    "color": ColorMapper.forward(colors[0]),
                    "hotkey": "",
                    "domain": "CLASSIFICATION",
                    "creation_date": DatetimeMapper.forward(cur_date),
                    "is_empty": False,
                },
                "1": {
                    "_id": "1",
                    "name": "dog",
                    "color": ColorMapper.forward(colors[1]),
                    "hotkey": "",
                    "domain": "CLASSIFICATION",
                    "creation_date": DatetimeMapper.forward(cur_date),
                    "is_empty": False,
                },
                "2": {
                    "_id": "2",
                    "name": "mouse",
                    "color": ColorMapper.forward(colors[2]),
                    "hotkey": "",
                    "domain": "CLASSIFICATION",
                    "creation_date": DatetimeMapper.forward(cur_date),
                    "is_empty": False,
                },
            },
        }

        deserialized = LabelSchemaMapper.backward(serialized)
        assert label_shema == deserialized
class TestAnnotationSceneEntity:

    creation_date = now()
    labels: List[ScoredLabel] = []
    rectangle = Rectangle(x1=0.5, x2=1.0, y1=0.0, y2=0.5)
    annotation = Annotation(shape=rectangle, labels=labels)

    point1 = Point(0.3, 0.1)
    point2 = Point(0.8, 0.3)
    point3 = Point(0.6, 0.2)
    points = [point1, point2, point3]
    polygon = Polygon(points=points)
    annotation2 = Annotation(shape=polygon, labels=labels)

    annotations = [annotation, annotation2]

    annotation_scene_entity = AnnotationSceneEntity(
        annotations=annotations, kind=AnnotationSceneKind.ANNOTATION)

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_annotation_scene_entity_default_value(self):
        """
        <b>Description:</b>
        Check that AnnotationSceneEntity default values

        <b>Input data:</b>
        AnnotationSceneEntity class

        <b>Expected results:</b>
        Test passes if the AnnotationSceneEntity return correct values

        <b>Steps</b>
        1. Create AnnotationSceneEntity instances
        2. Check default values
        """

        annotation_scene_entity = self.annotation_scene_entity

        assert annotation_scene_entity.id == ID()
        assert annotation_scene_entity.kind == AnnotationSceneKind.ANNOTATION
        assert annotation_scene_entity.editor_name == ""
        assert type(annotation_scene_entity.creation_date) == datetime.datetime
        assert "Annotation(shape=Rectangle" in str(
            annotation_scene_entity.annotations)
        assert "Annotation(shape=Polygon" in str(
            annotation_scene_entity.annotations)
        assert annotation_scene_entity.shapes == [self.rectangle, self.polygon]

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_annotation_scene_entity_setters(self):
        """
        <b>Description:</b>
        Check that AnnotationSceneEntity can correctly return modified property value

        <b>Input data:</b>
        Annotation class

        <b>Expected results:</b>
        Test passes if the AnnotationSceneEntity return correct values

        <b>Steps</b>
        1. Create AnnotationSceneEntity instances
        2. Set another values
        3. Check changed values
        """

        annotation_scene_entity = self.annotation_scene_entity

        creation_date = self.creation_date
        annotation_scene_entity.id = ID(123456789)
        annotation_scene_entity.kind = AnnotationSceneKind.PREDICTION
        annotation_scene_entity.editor_name = "editor"
        annotation_scene_entity.creation_date = creation_date
        annotation_scene_entity.annotations = self.annotation

        assert annotation_scene_entity.id == ID(123456789)
        assert annotation_scene_entity.kind == AnnotationSceneKind.PREDICTION
        assert annotation_scene_entity.editor_name == "editor"
        assert annotation_scene_entity.creation_date == creation_date
        assert annotation_scene_entity.annotations == self.annotation

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_annotation_scene_entity_magic_methods(self):
        """
        <b>Description:</b>
        Check Annotation __repr__ method

        <b>Input data:</b>
        Initialized instance of AnnotationSceneEntity

        <b>Expected results:</b>
        Test passes if AnnotationSceneEntity magic method returns correct values

        <b>Steps</b>
        1. Create AnnotationSceneEntity instances
        2. Check returning value of magic method
        """

        annotation_scene_entity = self.annotation_scene_entity

        annotation_scene_entity_repr = [
            f"{annotation_scene_entity.__class__.__name__}("
            f"annotations={annotation_scene_entity.annotations}, "
            f"kind={annotation_scene_entity.kind}, "
            f"editor={annotation_scene_entity.editor_name}, "
            f"creation_date={annotation_scene_entity.creation_date}, "
            f"id={annotation_scene_entity.id})"
        ]

        for i in annotation_scene_entity_repr:
            assert i in repr(annotation_scene_entity)

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_annotation_scene_entity_contains_any(self):
        """
        <b>Description:</b>
        Check Annotation contains_any method

        <b>Input data:</b>
        Initialized instance of AnnotationSceneEntity

        <b>Expected results:</b>
        Test passes if AnnotationSceneEntity contains_any method returns correct values

        <b>Steps</b>
        1. Create AnnotationSceneEntity instances
        2. Check returning value of contains_any method
        """

        annotation_scene_entity = self.annotation_scene_entity
        annotation_scene_entity.annotations = self.annotations

        car = LabelEntity(name="car", domain=Domain.DETECTION, is_empty=True)
        person = LabelEntity(name="person", domain=Domain.DETECTION)
        tree = LabelEntity(name="tree", domain=Domain.DETECTION)
        car_label = ScoredLabel(car)
        person_label = ScoredLabel(person)
        tree_label = ScoredLabel(tree)
        labels = [car_label]
        labels2 = [car_label, person_label]

        annotation = Annotation(shape=self.rectangle, labels=labels2)
        annotations = [annotation]
        annotation_scene_entity2 = AnnotationSceneEntity(
            annotations=annotations, kind=AnnotationSceneKind.ANNOTATION)

        assert annotation_scene_entity.contains_any(labels=labels) is False
        assert annotation_scene_entity2.contains_any(labels=labels2) is True
        assert annotation_scene_entity2.contains_any(
            labels=[tree_label]) is False

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_annotation_scene_entity_append_annotation(self):
        """
        <b>Description:</b>
        Check Annotation append_annotation method

        <b>Input data:</b>
        Initialized instance of AnnotationSceneEntity

        <b>Expected results:</b>
        Test passes if AnnotationSceneEntity append_annotation method returns correct values

        <b>Steps</b>
        1. Create AnnotationSceneEntity instances
        2. Check returning value of append_annotation method
        """

        annotation_scene_entity = self.annotation_scene_entity

        tree = LabelEntity(name="tree", domain=Domain.DETECTION)
        tree_label = ScoredLabel(tree)
        labels = [tree_label]
        annotation = Annotation(shape=self.rectangle, labels=labels)

        assert len(annotation_scene_entity.annotations) == 2

        annotation_scene_entity.append_annotation(annotation)
        assert len(annotation_scene_entity.annotations) == 3

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_annotation_scene_entity_append_annotations(self):
        """
        <b>Description:</b>
        Check Annotation append_annotations method

        <b>Input data:</b>
        Initialized instance of AnnotationSceneEntity

        <b>Expected results:</b>
        Test passes if AnnotationSceneEntity append_annotations method returns correct values

        <b>Steps</b>
        1. Create AnnotationSceneEntity instances
        2. Check returning value of append_annotations method
        """

        annotation_scene_entity = self.annotation_scene_entity

        annotation_scene_entity.append_annotations(self.annotations)
        assert len(annotation_scene_entity.annotations) == 6

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_annotation_scene_entity_get_labels(self):
        """
        <b>Description:</b>
        Check Annotation get_labels method

        <b>Input data:</b>
        Initialized instance of AnnotationSceneEntity

        <b>Expected results:</b>
        Test passes if AnnotationSceneEntity get_labels method returns correct values

        <b>Steps</b>
        1. Create AnnotationSceneEntity instances
        2. Check returning value of get_labels method
        """

        annotation_scene_entity = self.annotation_scene_entity

        assert len(annotation_scene_entity.get_labels()) == 1
        assert "name=tree" in str(annotation_scene_entity.get_labels())

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_annotation_scene_entity_get_label_ids(self):
        """
        <b>Description:</b>
        Check Annotation get_label_ids method

        <b>Input data:</b>
        Initialized instance of AnnotationSceneEntity

        <b>Expected results:</b>
        Test passes if AnnotationSceneEntity get_label_ids method returns correct values

        <b>Steps</b>
        1. Create AnnotationSceneEntity instances
        2. Check returning value of get_label_ids method
        """

        annotation_scene_entity = self.annotation_scene_entity

        assert annotation_scene_entity.get_label_ids() == {ID()}

        bus = LabelEntity(id=ID(123456789),
                          name="bus",
                          domain=Domain.DETECTION)
        bus_label = ScoredLabel(bus)
        labels = [bus_label]
        annotation = Annotation(shape=self.rectangle, labels=labels)
        annotation_scene_entity.append_annotation(annotation)

        assert annotation_scene_entity.get_label_ids() == {ID(), ID(123456789)}
Exemple #15
0
    def __init__(
        self,
        train_dataset: "DatasetEntity",
        configuration: ModelConfiguration,
        *,
        creation_date: Optional[datetime.datetime] = None,
        performance: Optional[Performance] = None,
        previous_trained_revision: Optional["ModelEntity"] = None,
        previous_revision: Optional["ModelEntity"] = None,
        version: int = 1,
        tags: Optional[List[str]] = None,
        model_status: ModelStatus = ModelStatus.SUCCESS,
        model_format: ModelFormat = ModelFormat.OPENVINO,
        training_duration: float = 0.0,
        model_adapters: Optional[Dict[str, ModelAdapter]] = None,
        exportable_code_adapter: Optional[ExportableCodeAdapter] = None,
        precision: Optional[List[ModelPrecision]] = None,
        latency: int = 0,
        fps_throughput: int = 0,
        target_device: TargetDevice = TargetDevice.CPU,
        target_device_type: Optional[str] = None,
        optimization_type: ModelOptimizationType = ModelOptimizationType.NONE,
        optimization_methods: List[OptimizationMethod] = None,
        optimization_objectives: Dict[str, str] = None,
        performance_improvement: Dict[str, float] = None,
        model_size_reduction: float = 0.0,
        _id: Optional[ID] = None,
    ):
        _id = ID() if _id is None else _id
        performance = NullPerformance() if performance is None else performance
        creation_date = now() if creation_date is None else creation_date

        optimization_methods = (
            [] if optimization_methods is None else optimization_methods
        )
        optimization_objectives = (
            {} if optimization_objectives is None else optimization_objectives
        )
        performance_improvement = (
            {} if performance_improvement is None else performance_improvement
        )

        tags = [] if tags is None else tags
        precision = [ModelPrecision.FP32] if precision is None else precision

        if model_adapters is None:
            model_adapters = {}

        self.__id = _id
        self.__creation_date = creation_date
        self.__train_dataset = train_dataset
        self.__previous_trained_revision = previous_trained_revision
        self.__previous_revision = previous_revision
        self.__version = version
        self.__tags = tags
        self.__model_status = model_status
        self.__model_format = model_format
        self.__performance = performance
        self.__training_duration = training_duration
        self.__configuration = configuration
        self.__model_adapters = model_adapters
        self.__exportable_code_adapter = exportable_code_adapter
        self.model_adapters_to_delete: List[ModelAdapter] = []
        self.__precision = precision
        self.__latency = latency
        self.__fps_throughput = fps_throughput
        self.__target_device = target_device
        self.__target_device_type = target_device_type
        self.__optimization_type = optimization_type
        self.__optimization_methods = optimization_methods
        self.__optimization_objectives = optimization_objectives
        self.__performance_improvement = performance_improvement
        self.__model_size_reduction = model_size_reduction
class TestRectangle:
    modification_date = now()

    @staticmethod
    def rectangle_labels() -> list:
        rectangle_label = LabelEntity(
            name="Rectangle label",
            domain=Domain.DETECTION,
            color=Color(red=100, green=50, blue=200),
            id=ID("rectangle_label_1"),
        )
        other_rectangle_label = LabelEntity(
            name="Other rectangle label",
            domain=Domain.SEGMENTATION,
            color=Color(red=200, green=80, blue=100),
            id=ID("rectangle_label_2"),
        )
        return [
            ScoredLabel(label=rectangle_label),
            ScoredLabel(label=other_rectangle_label),
        ]

    @staticmethod
    def horizontal_rectangle_params() -> dict:
        return {"x1": 0.1, "y1": 0.0, "x2": 0.4, "y2": 0.2}

    def horizontal_rectangle(self) -> Rectangle:
        return Rectangle(**self.horizontal_rectangle_params())

    def vertical_rectangle_params(self) -> dict:
        return {
            "x1": 0.1,
            "y1": 0.1,
            "x2": 0.3,
            "y2": 0.4,
            "labels": self.rectangle_labels(),
            "modification_date": datetime(
                year=2020, month=1, day=1, hour=9, minute=30, second=15, microsecond=2
            ),
        }

    def vertical_rectangle(self) -> Rectangle:
        return Rectangle(**self.vertical_rectangle_params())

    @staticmethod
    def square_params() -> dict:
        return {"x1": 0.1, "y1": 0.1, "x2": 0.3, "y2": 0.3}

    def square(self) -> Rectangle:
        return Rectangle(**self.square_params())

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_rectangle_required_parameters(self):
        """
        <b>Description:</b>
        Check Rectangle class instance required parameters

        <b>Input data:</b>
        Rectangle class initiation parameters

        <b>Expected results:</b>
        Test passes if Rectangle instance has expected attributes specified during required parameters initiation

        <b>Steps</b>
        1. Compare x1, y1, x2, y2 and type Rectangle instance parameters with expected values
        """
        rectangle = self.horizontal_rectangle()
        assert rectangle.x1 == 0.1
        assert rectangle.y1 == 0.0
        assert rectangle.x2 == 0.4
        assert rectangle.y2 == 0.2
        assert rectangle.type == ShapeType.RECTANGLE

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_rectangle_optional_parameters(self):
        """
        <b>Description:</b>
        Check Rectangle optional parameters

        <b>Input data:</b>
        Instance of Rectangle class

        <b>Expected results:</b>
        Test passes if Rectangle instance has expected labels and modification attributes specified during Rectangle
        class object initiation with optional parameters

        <b>Steps</b>
        1. Compare default label Rectangle instance attribute with expected value
        2. Check type of default modification_date Rectangle instance attribute
        3. Compare specified label Rectangle instance attribute with expected value
        4. Compare specified modification_date Rectangle instance attribute with expected value
        """
        # Checking default values of optional parameters
        default_params_rectangle = self.horizontal_rectangle()
        assert default_params_rectangle._labels == []
        assert isinstance(default_params_rectangle.modification_date, datetime)
        # check for specified values of optional parameters
        specified_params_rectangle = self.vertical_rectangle()
        assert specified_params_rectangle._labels == self.rectangle_labels()
        assert specified_params_rectangle.modification_date == datetime(
            year=2020, month=1, day=1, hour=9, minute=30, second=15, microsecond=2
        )

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_rectangle_coordinates_validation(self):
        """
        <b>Description:</b>
        Check Rectangle coordinates

        <b>Input data:</b>
        Rectangle class initiation parameters

        <b>Expected results:</b>
        Test passes if Rectangle correctly checks coordinates during initiation of Rectangle object

        <b>Steps</b>
        1. Check Rectangle coordinates with correct width and height
        2. Check Rectangle coordinates with incorrect width: (x2 - x1) <= 0
        3. Check Rectangle coordinates with incorrect height: (y2 - y1) <= 0
        4. Check Rectangle coordinates with all coordinates equal 0
        """
        # checks for correct width and height
        self.horizontal_rectangle()
        self.vertical_rectangle()
        self.square()
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore", "Rectangle coordinates")
            Rectangle(x1=0.2, y1=0.1, x2=1.4, y2=1.5)
        Rectangle(x1=0.2, y1=0.1, x2=0.4, y2=0.5)
        # checks for incorrect coordinates
        width_less_than_zero_params = {"x1": 0.4, "y1": 0.0, "x2": 0.1, "y2": 0.2}
        width_equal_zero_params = {"x1": 0.1, "y1": 0.0, "x2": 0.1, "y2": 0.2}
        height_less_than_zero_params = {"x1": 0.1, "y1": 0.4, "x2": 0.3, "y2": 0.1}
        height_params_equal_zero_params = {"x1": 0.1, "y1": 0.4, "x2": 0.3, "y2": 0.4}
        zero_rectangle_params = {"x1": 0.0, "x2": 0.0, "y1": 0.0, "y2": 0.0}
        for incorrect_coordinates in [
            width_less_than_zero_params,
            width_equal_zero_params,
            height_less_than_zero_params,
            height_params_equal_zero_params,
            zero_rectangle_params,
        ]:
            with pytest.raises(ValueError):
                Rectangle(**incorrect_coordinates)

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_rectangle_repr(self):
        """
        <b>Description:</b>
        Check Rectangle __repr__ method

        <b>Input data:</b>
        Instance of Rectangle class

        <b>Expected results:</b>
        Test passes if __repr__ method prints expected message for Rectangle class instance

        <b>Steps</b>
        1. Check message printed by __repr__ method
        """
        rectangle = self.horizontal_rectangle()
        assert (
            repr(rectangle)
            == "Rectangle(x=0.1, y=0.0, width=0.30000000000000004, height=0.2)"
        )

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_rectangle_eq(self):
        """
        <b>Description:</b>
        Check Rectangle __eq__ method

        <b>Input data:</b>
        Instances of Rectangle class

        <b>Expected results:</b>
        Test passes if __eq__ method returns expected bool value

        <b>Steps</b>
        1. Check __eq__ method for instances of Rectangle class with equal parameters
        2. Check __eq__ method for different instances of Rectangle class
        3. Check __eq__ method for instances of different classes
        4. Check __eq__ method for instances of Rectangle class with unequal labels attribute
        5. Check __eq__ method for instances of Rectangle class with unequal x1, y1, x2, y2 and
        modification_date attributes
        """
        rectangle = self.vertical_rectangle()
        # Check for instances with equal parameters
        equal_rectangle = self.vertical_rectangle()
        assert rectangle == equal_rectangle
        # Check for different instances of Rectangle class
        assert rectangle != self.horizontal_rectangle()
        # Check for different types branch
        assert rectangle != str
        # Check for unequal labels parameters. Expected that different labels are not affecting equality
        unequal_label = LabelEntity(
            name="Unequal label", domain=Domain.SEGMENTATION, id=ID("unequal_label_1")
        )
        unequal_scored_label = ScoredLabel(label=unequal_label)
        equal_rectangle._labels.append(unequal_scored_label)
        assert rectangle == equal_rectangle
        # Check for instances with unequal parameters combinations
        # Generating all possible scenarios of parameter values submission
        keys_list = ["x1", "y1", "x2", "y2", "modification_date"]
        parameter_combinations = []
        for i in range(1, len(keys_list) + 1):
            parameter_combinations.append(list(itertools.combinations(keys_list, i)))
        # In each of scenario creating a copy of equal Rectangle parameters and replacing to values from prepared
        # dictionary
        unequal_values_dict = {
            "x1": 0.09,
            "y1": 0.09,
            "x2": 0.29,
            "y2": 0.39,
            "modification_date": datetime(
                year=2019, month=2, day=3, hour=7, minute=15, second=10, microsecond=1
            ),
        }
        for scenario in parameter_combinations:
            for rectangle_parameters in scenario:
                unequal_rectangle_params_dict = dict(self.vertical_rectangle_params())
                for key in rectangle_parameters:
                    unequal_rectangle_params_dict[key] = unequal_values_dict.get(key)
                unequal_rectangle = Rectangle(**unequal_rectangle_params_dict)
                assert rectangle != unequal_rectangle, (
                    "Failed to check that Rectangle instances with different "
                    f"{rectangle_parameters} are unequal"
                )

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_rectangle_hash(self):
        """
        <b>Description:</b>
        Check Rectangle __hash__ method

        <b>Input data:</b>
        Instance of Rectangle class

        <b>Expected results:</b>
        Test passes if __hash__ method returns expected value

        <b>Steps</b>
        1. Check value returned by __hash__ method
        """
        rectangle = self.horizontal_rectangle()
        assert hash(rectangle) == hash(str(rectangle))

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_rectangle_clip_to_visible_region(self):
        """
        <b>Description:</b>
        Check Rectangle clip_to_visible_region method

        <b>Input data:</b>
        Rectangle class initiation parameters

        <b>Expected results:</b>
        Test passes if clip_to_visible_region method return correct value

        <b>Steps</b>
        1. Check values returned by clip_to_visible_region method for 0<x1<x2, 0<y1<y2, x1<x2<1, y1<y2<1
        2. Check values returned by clip_to_visible_region method for x1<0, y1<0, x2>1, y2>1
        3. Check values returned by clip_to_visible_region method for x1=0, y1=0, x2=1, y2=1
        4. Check ValueError exception raised if x1<0 and x1<x2<0: clipped Rectangle width will be equal 0
        5. Check ValueError exception raised if 1<x1<x2 and x2>1: clipped Rectangle width will be equal 0
        6. Check ValueError exception raised if y1<0 and y1<y2<0: clipped Rectangle height will be equal 0
        7. Check ValueError exception raised if 1<y1<y2 and y2>1: clipped Rectangle height will be equal 0
        """
        positive_scenarios = [
            {
                "input_params": {
                    "x1": 0.3,
                    "y1": 0.2,
                    "x2": 0.6,
                    "y2": 0.4,
                    "labels": self.rectangle_labels(),
                },
                "params_expected": {"x1": 0.3, "y1": 0.2, "x2": 0.6, "y2": 0.4},
            },
            {
                "input_params": {
                    "x1": -0.2,
                    "y1": -0.3,
                    "x2": 1.6,
                    "y2": 1.4,
                    "labels": self.rectangle_labels(),
                },
                "params_expected": {"x1": 0.0, "y1": 0.0, "x2": 1.0, "y2": 1.0},
            },
            {
                "input_params": {
                    "x1": 0.0,
                    "y1": 0.0,
                    "x2": 1.0,
                    "y2": 1.0,
                    "labels": self.rectangle_labels(),
                },
                "params_expected": {"x1": 0.0, "y1": 0.0, "x2": 1.0, "y2": 1.0},
            },
        ]
        for scenario in positive_scenarios:
            with warnings.catch_warnings():
                warnings.filterwarnings("ignore", "Rectangle coordinates")
                rectangle_actual = Rectangle(**scenario.get("input_params"))
            rectangle_expected = Rectangle(**scenario.get("params_expected"))
            rectangle_actual.modification_date = self.modification_date
            rectangle_expected.modification_date = self.modification_date
            assert rectangle_actual.clip_to_visible_region() == rectangle_expected
        negative_scenarios = [
            {"x1": -0.4, "y1": 0.2, "x2": -0.2, "y2": 0.4},
            {"x1": 1.2, "y1": 0.2, "x2": 1.6, "y2": 0.4},
            {"x1": 0.4, "y1": -0.4, "x2": 0.6, "y2": -0.2},
            {"x1": 1.2, "y1": 1.2, "x2": 1.6, "y2": 1.4},
        ]
        for scenario in negative_scenarios:
            with warnings.catch_warnings():
                warnings.filterwarnings("ignore", "Rectangle coordinates")
                rectangle_actual = Rectangle(**scenario)
            with pytest.raises(ValueError):
                rectangle_actual.clip_to_visible_region()

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_rectangle_normalize_wrt_roi_shape(self):
        """
        <b>Description:</b>
        Check Rectangle normalize_wrt_roi_shape method

        <b>Input data:</b>
        Instance of Rectangle class

        <b>Expected results:</b>
        Test passes if normalize_wrt_roi_shape method returns expected instance of Rectangle class

        <b>Steps</b>
        1. Check values returned by normalized Rectangle instance
        2. Check raise ValueError exception when roi parameter has unexpected type
        """
        # Positive scenario
        rectangle = self.horizontal_rectangle()
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore", "Rectangle coordinates")
            roi_shape = Rectangle(x1=0.0, y1=0.0, x2=2.1, y2=2.2)
        normalized = rectangle.normalize_wrt_roi_shape(roi_shape)
        assert normalized.x1 == 0.1
        assert normalized.y1 == 0.0
        assert normalized.x2 == 0.4
        assert normalized.y2 == 0.2
        assert normalized.modification_date == rectangle.modification_date
        # Negative scenario
        with pytest.raises(ValueError):
            rectangle.normalize_wrt_roi_shape(str)

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_rectangle_denormalize_wrt_roi_shape(self):
        """
        <b>Description:</b>
        Check Rectangle denormalize_wrt_roi_shape method

        <b>Input data:</b>
        Instance of Rectangle class

        <b>Expected results:</b>
        Test passes if denormalize_wrt_roi_shape method return expected instance of Rectangle class

        <b>Steps</b>
        1. Check values returned by denormalized Rectangle instance
        2. Check raise ValueError exception when roi parameter has unexpected type
        """
        # Positive scenario
        rectangle = self.horizontal_rectangle()
        roi_shape = Rectangle(x1=0.2, y1=0.2, x2=0.4, y2=0.4)
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore", "Rectangle coordinates")
            denormalized = rectangle.denormalize_wrt_roi_shape(roi_shape)
        assert denormalized.x1 == -0.5
        assert denormalized.y1 == -1.0
        assert denormalized.x2 == 1.0
        assert denormalized.y2 == 0.0
        assert denormalized.modification_date == rectangle.modification_date
        # Negative scenario
        with pytest.raises(ValueError):
            rectangle.denormalize_wrt_roi_shape(str)

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_rectangle_as_shapely_polygon(self):
        """
        <b>Description:</b>
        Check Rectangle _as_shapely_polygon method

        <b>Input data:</b>
        Instance of Rectangle class

        <b>Expected results:</b>
        Test passes if _as_shapely_polygon method returns expected instance of Polygon class

        <b>Steps</b>
        1. Check Polygon instance returned by _as_shapely_polygon method
        """
        rectangle = self.horizontal_rectangle()
        shapely_polygon = rectangle._as_shapely_polygon()
        assert shapely_polygon.__class__ == Polygon
        assert shapely_polygon.bounds == (0.1, 0.0, 0.4, 0.2)
        assert shapely_polygon.area == 0.06000000000000001

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_rectangle_generate_full_box(self):
        """
        <b>Description:</b>
        Check Rectangle generate_full_box method

        <b>Input data:</b>
        Labels specified for full_box instance of Rectangle class

        <b>Expected results:</b>
        Test passes if generate_full_box method returns instance of Rectangle class with coordinates
        (x1=0.0, y1=0.0, x2=1.0, y2=1.0)

        <b>Steps</b>
        1. Check generate_full_box method for Rectangle instance with no labels specified
        2. Check generate_full_box method for Rectangle instance with labels specified
        """
        detection_label = ScoredLabel(
            LabelEntity(name="detection", domain=Domain.DETECTION)
        )
        for label_actual, label_expected in [
            (None, []),
            ([detection_label], [detection_label]),
        ]:
            full_box = Rectangle.generate_full_box(label_actual)
            assert full_box.type == ShapeType.RECTANGLE
            assert full_box.x1 == full_box.y1 == 0.0
            assert full_box.x2 == full_box.y2 == 1.0
            assert full_box._labels == label_expected

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_rectangle_is_full_box(self):
        """
        <b>Description:</b>
        Check Rectangle is_full_box method

        <b>Input data:</b>
        Rectangle class initiation parameters

        <b>Expected results:</b>
        Test passes if is_full_box method return expected bool value

        <b>Steps</b>
        1. Check positive scenario for is_full_box method: x1=y1=0, x2=y2=1
        2. Check negative scenarios for is_full_box method
        """
        full_box_rectangle_params = {"x1": 0.0, "y1": 0.0, "x2": 1.0, "y2": 1.0}
        # Positive scenario for Rectangle instance
        full_box_rectangle = Rectangle(**full_box_rectangle_params)
        assert Rectangle.is_full_box(full_box_rectangle)
        # Negative scenarios for Rectangle instance
        # Generating all scenarios when Rectangle object not a full_box
        keys_list = ["x1", "y1", "x2", "y2"]
        parameter_combinations = []
        for i in range(1, len(keys_list) + 1):
            parameter_combinations.append(list(itertools.combinations(keys_list, i)))
        # In each of scenario creating a copy of full_Box rectangle parameters and replacing to values from prepared
        # dictionary
        not_full_box_values_dict = {"x1": 0.01, "y1": 0.01, "x2": 0.9, "y2": 0.9}
        for combination in parameter_combinations:
            for scenario in combination:
                not_full_box_params = dict(full_box_rectangle_params)
                for key in scenario:
                    not_full_box_params[key] = not_full_box_values_dict.get(key)
                not_full_box_rectangle = Rectangle(**not_full_box_params)
                assert not Rectangle.is_full_box(not_full_box_rectangle), (
                    f"Expected False returned by is_full_box method for rectangle with parameters "
                    f"{not_full_box_params}"
                )
        # Negative scenario for not Rectangle class instance
        assert not Rectangle.is_full_box(str)

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_rectangle_crop_numpy_array(self):
        """
        <b>Description:</b>
        Check Rectangle crop_numpy_array method

        <b>Input data:</b>
        Rectangle class initiation parameters

        <b>Expected results:</b>
        Test passes if crop_numpy_array method return expected cropped array
        <b>Steps</b>
        1. Check crop_numpy_array method for Rectangle with parameters less than 0
        2. Check crop_numpy_array method for Rectangle with parameters range from 0 to 1
        3. Check crop_numpy_array method for Rectangle with parameters more than 1
        """
        image_height = image_width = 128
        numpy_image_array = np.random.uniform(
            low=0.0, high=255.0, size=(image_height, image_width, 3)
        )
        scenarios = [
            {
                "input_params": {"x1": -0.2, "x2": -0.1, "y1": -0.3, "y2": -0.2},
                "cropped_expected": {"x1": 0, "y1": 0, "x2": 0, "y2": 0},
            },
            {
                "input_params": {"x1": 0.2, "x2": 0.3, "y1": 0.4, "y2": 0.8},
                "cropped_expected": {"x1": 26, "y1": 51, "x2": 38, "y2": 102},
            },
            {
                "input_params": {"x1": 1.1, "x2": 1.3, "y1": 1.1, "y2": 1.5},
                "cropped_expected": {"x1": 141, "y1": 141, "x2": 166, "y2": 192},
            },
        ]
        for rectangle_parameters in scenarios:
            with warnings.catch_warnings():
                warnings.filterwarnings("ignore", "Rectangle coordinates")
                rectangle = Rectangle(**rectangle_parameters.get("input_params"))
            expected_output = rectangle_parameters.get("cropped_expected")
            actual_cropped_image_array = rectangle.crop_numpy_array(numpy_image_array)
            expected_image_array = numpy_image_array[
                expected_output.get("y1") : expected_output.get("y2"),
                expected_output.get("x1") : expected_output.get("x2"),
                ::,
            ]
            assert actual_cropped_image_array.shape[2] == 3
            try:
                assert (expected_image_array == actual_cropped_image_array).all()
            except AttributeError:
                raise AssertionError("Unequal expected and cropped image arrays")

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_rectangle_width(self):
        """
        <b>Description:</b>
        Check Rectangle width method

        <b>Input data:</b>
        Instances of Rectangle class

        <b>Expected results:</b>
        Test passes if width method returns expected value of Rectangle width

        <b>Steps</b>
        1. Check width method for Rectangle instances
        """
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore", "Rectangle coordinates")
            negative_x1_rectangle = Rectangle(x1=-0.3, y1=0.2, x2=0.7, y2=0.5)
        for rectangle, expected_width in [
            (self.horizontal_rectangle(), 0.30000000000000004),
            (self.vertical_rectangle(), 0.19999999999999998),
            (self.square(), 0.19999999999999998),
            (negative_x1_rectangle, 1.0),
        ]:
            assert rectangle.width == expected_width

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_rectangle_height(self):
        """
        <b>Description:</b>
        Check Rectangle height method

        <b>Input data:</b>
        Instances of Rectangle class

        <b>Expected results:</b>
        Test passes if height method returns expected value of Rectangle height

        <b>Steps</b>
        1. Check height method for Rectangle instances
        """
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore", "Rectangle coordinates")
            negative_y1_rectangle = Rectangle(x1=0.3, y1=-0.4, x2=0.7, y2=0.5)
        for rectangle, expected_height in [
            (self.horizontal_rectangle(), 0.2),
            (self.vertical_rectangle(), 0.30000000000000004),
            (self.square(), 0.19999999999999998),
            (negative_y1_rectangle, 0.9),
        ]:
            assert rectangle.height == expected_height

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_rectangle_diagonal(self):
        """
        <b>Description:</b>
        Check Rectangle diagonal method

        <b>Input data:</b>
        Instances of Rectangle class

        <b>Expected results:</b>
        Test passes if diagonal method returns expected value of Rectangle diagonal

        <b>Steps</b>
        1. Check diagonal method for Rectangle instance
        """
        for rectangle, expected_diagonal in [
            (self.horizontal_rectangle(), 0.360555127546399),
            (self.vertical_rectangle(), 0.3605551275463989),
            (self.square(), 0.282842712474619),
        ]:
            assert rectangle.diagonal == expected_diagonal

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_rectangle_get_area(self):
        """
        <b>Description:</b>
        Check Rectangle get_area method

        <b>Input data:</b>
        Instances of Rectangle class

        <b>Expected results:</b>
        Test passes if get_area method returns expected value of Rectangle diagonal

        <b>Steps</b>
        1. Check get_area method for Rectangle instance
        """
        for rectangle, expected_area in [
            (self.horizontal_rectangle(), 0.06000000000000001),
            (self.vertical_rectangle(), 0.060000000000000005),
            (self.square(), 0.039999999999999994),
        ]:
            assert rectangle.get_area() == expected_area
class TestResultset:
    creation_date = now()

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_resultset_purpose(self):
        """
        <b>Description:</b>
        Check the ResultsetPurpose can correctly return the value

        <b>Input data:</b>
        Denotes, stages

        <b>Expected results:</b>
        Test passes if the results match
        """

        denotes = ["EVALUATION", "TEST", "PREEVALUATION"]
        stages = ["Validation", "Test", "Pre-validation"]

        resultset_purpose = ResultsetPurpose
        assert len(resultset_purpose) == 3

        for i in ResultsetPurpose:
            resultset_purpose = ResultsetPurpose(i)
            assert repr(resultset_purpose) == denotes[i.value]
            assert str(resultset_purpose) == stages[i.value]

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_resultset_entity(self):
        """
        <b>Description:</b>
        Check the ResultSetEntity can correctly return the value

        <b>Input data:</b>
        Mock data

        <b>Expected results:</b>
        Test passes if incoming data is processed correctly

        <b>Steps</b>
        1. Create dummy data
        2. Check the processing of default values
        3. Check the processing of changed values
        """

        test_data = {
            "model": None,
            "ground_truth_dataset": None,
            "prediction_dataset": None,
            "purpose": None,
            "performance": None,
            "creation_date": None,
            "id": None,
        }

        result_set = ResultSetEntity(**test_data)

        for name, value in test_data.items():
            set_attr_name = f"test_{name}"
            if name in [
                "model",
                "ground_truth_dataset",
                "prediction_dataset",
                "purpose",
            ]:
                assert getattr(result_set, name) == value
                setattr(result_set, name, set_attr_name)
                assert getattr(result_set, name) == set_attr_name

        assert result_set.performance == NullPerformance()
        assert type(result_set.creation_date) == datetime.datetime
        assert result_set.id == ID()

        assert result_set.has_score_metric() is False
        result_set.performance = "test_performance"
        assert result_set.performance != NullPerformance()
        assert result_set.has_score_metric() is True

        creation_date = self.creation_date
        result_set.creation_date = creation_date
        assert result_set.creation_date == creation_date

        set_attr_id = ID(123456789)
        result_set.id = set_attr_id
        assert result_set.id == set_attr_id

        test_result_set_repr = [
            f"model={result_set.model}",
            f"ground_truth_dataset={result_set.ground_truth_dataset}",
            f"prediction_dataset={result_set.prediction_dataset}",
            f"purpose={result_set.purpose}",
            f"performance={result_set.performance}",
            f"creation_date={result_set.creation_date}",
            f"id={result_set.id}",
        ]

        for i in test_result_set_repr:
            assert i in repr(result_set)
Exemple #18
0
 def __init__(self, name: str, date: Optional[datetime.datetime] = None):
     self.name = name
     if date is None:
         date = now()
     self.date = date
class TestEllipse:
    modification_date = now()

    def ellipse_params(self):
        ellipse_params = {
            "x1": 0.5,
            "x2": 1.0,
            "y1": 0.0,
            "y2": 0.5,
            "modification_date": self.modification_date,
        }
        return ellipse_params

    def ellipse(self):
        return Ellipse(**self.ellipse_params())

    def width_gt_height_ellipse_params(self):
        width_gt_height_ellipse_params = {
            "x1": 0.5,
            "x2": 0.8,
            "y1": 0.1,
            "y2": 0.3,
        }
        return width_gt_height_ellipse_params

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_ellipse(self):
        """
        <b>Description:</b>
        Check ellipse parameters

        <b>Input data:</b>
        Coordinates

        <b>Expected results:</b>
        Test passes if Ellipse correctly calculates parameters and returns default values

        <b>Steps</b>
        1. Check ellipse params
        2. Check ellipse default values
        3. Check ellipse with incorrect coordinates
        """

        ellipse = self.ellipse()
        modification_date = self.modification_date

        assert ellipse.width == 0.5
        assert ellipse.height == 0.5
        assert ellipse.x_center == 0.75
        assert ellipse.y_center == 0.25
        assert ellipse.minor_axis == 0.25
        assert ellipse.major_axis == 0.25
        assert ellipse._labels == []
        assert ellipse.modification_date == modification_date

        incorrect_ellipse_params = {
            "x1": 0,
            "x2": 0,
            "y1": 0,
            "y2": 0,
        }

        with pytest.raises(ValueError):
            Ellipse(**incorrect_ellipse_params)

        width_lt_height_ellipse_params = {
            "x1": 0.4,
            "x2": 0.5,
            "y1": 0.3,
            "y2": 0.4,
        }

        width_lt_height_ellipse = Ellipse(**width_lt_height_ellipse_params)
        assert width_lt_height_ellipse.height > width_lt_height_ellipse.width
        assert width_lt_height_ellipse.major_axis == width_lt_height_ellipse.height / 2
        assert width_lt_height_ellipse.width == 0.09999999999999998
        assert width_lt_height_ellipse.height == 0.10000000000000003
        assert width_lt_height_ellipse.x_center == 0.45
        assert width_lt_height_ellipse.y_center == 0.35
        assert width_lt_height_ellipse.minor_axis == 0.04999999999999999
        assert width_lt_height_ellipse.major_axis == 0.05000000000000002

        width_gt_height_ellipse = Ellipse(
            **self.width_gt_height_ellipse_params())
        assert width_gt_height_ellipse.height < width_gt_height_ellipse.width
        assert width_gt_height_ellipse.minor_axis == width_gt_height_ellipse.height / 2
        assert width_gt_height_ellipse.width == 0.30000000000000004
        assert width_gt_height_ellipse.height == 0.19999999999999998
        assert width_gt_height_ellipse.x_center == 0.65
        assert width_gt_height_ellipse.y_center == 0.2
        assert width_gt_height_ellipse.minor_axis == 0.09999999999999999
        assert width_gt_height_ellipse.major_axis == 0.15000000000000002

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_ellipse_magic_methods(self):
        """
        <b>Description:</b>
        Check Ellipse __repr__, __eq__, __hash__ methods

        <b>Input data:</b>
        Initialized instance of Ellipse

        <b>Expected results:</b>
        Test passes if Ellipse magic methods returns correct values

        <b>Steps</b>
        1. Initialize Ellipse instance
        2. Check returning value of magic methods
        """

        x1 = self.ellipse_params()["x1"]
        x2 = self.ellipse_params()["x2"]
        y1 = self.ellipse_params()["y1"]
        y2 = self.ellipse_params()["y2"]

        ellipse = self.ellipse()
        assert repr(ellipse) == f"Ellipse(x1={x1}, y1={y1}, x2={x2}, y2={y2})"

        other_ellipse_params = {
            "x1": 0.5,
            "x2": 1.0,
            "y1": 0.0,
            "y2": 0.5,
            "modification_date": self.modification_date,
        }

        third_ellipse_params = {
            "x1": 0.3,
            "y1": 0.5,
            "x2": 0.4,
            "y2": 0.6,
            "modification_date": self.modification_date,
        }

        other_ellipse = Ellipse(**other_ellipse_params)
        third_ellipse = Ellipse(**third_ellipse_params)

        assert ellipse == other_ellipse
        assert ellipse != third_ellipse
        assert ellipse != str

        assert hash(ellipse) == hash(str(ellipse))

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_ellipse_normalize_wrt_roi_shape(self):
        """
        <b>Description:</b>
        Check Ellipse normalize_wrt_roi_shape methods

        <b>Input data:</b>
        Initialized instance of Ellipse
        Initialized instance of Rectangle

        <b>Expected results:</b>
        Test passes if Ellipse normalize_wrt_roi_shape returns correct values

        <b>Steps</b>
        1. Initialize Ellipse instance
        2. Check returning value
        """

        ellipse = self.ellipse()
        roi = Rectangle(x1=0.0, x2=0.5, y1=0.0, y2=0.5)
        normalized = ellipse.normalize_wrt_roi_shape(roi)
        assert normalized.x1 == 0.25
        assert normalized.y1 == 0.0
        assert normalized.x2 == 0.5
        assert normalized.y2 == 0.25

        with pytest.raises(ValueError):
            ellipse.normalize_wrt_roi_shape("123")

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_ellipse_denormalize_wrt_roi_shape(self):
        """
        <b>Description:</b>
        Check Ellipse denormalize_wrt_roi_shape methods

        <b>Input data:</b>
        Initialized instance of Ellipse
        Initialized instance of Rectangle

        <b>Expected results:</b>
        Test passes if Ellipse denormalize_wrt_roi_shape returns correct values

        <b>Steps</b>
        1. Initialize Ellipse instance
        2. Check returning value
        """

        ellipse = self.ellipse()
        roi = Rectangle(x1=0.5, x2=1.0, y1=0.0, y2=1.0)
        denormalized = ellipse.denormalize_wrt_roi_shape(roi)
        assert denormalized.x1 == 0.0
        assert denormalized.y1 == 0.0
        assert denormalized.x2 == 1.0
        assert denormalized.y2 == 0.5

        with pytest.raises(ValueError):
            ellipse.denormalize_wrt_roi_shape("123")

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_ellipse_get_evenly_distributed_ellipse_coordinates(self):
        """
        <b>Description:</b>
        Check Ellipse get_evenly_distributed_ellipse_coordinates methods

        <b>Input data:</b>
        Initialized instance of Ellipse

        <b>Expected results:</b>
        Test passes if Ellipse get_evenly_distributed_ellipse_coordinates returns correct values

        <b>Steps</b>
        1. Initialize Ellipse instance
        2. Check returning value
        """

        ellipse = self.ellipse()
        number_of_coordinates = 3
        coordinates_ellipse_line = ellipse.get_evenly_distributed_ellipse_coordinates(
            number_of_coordinates)
        assert len(coordinates_ellipse_line) == 3
        assert coordinates_ellipse_line[0] == (1.0, 0.25)
        assert coordinates_ellipse_line[1] == (0.625, 0.4665063509461097)
        assert coordinates_ellipse_line[2] == (0.6249999999999999,
                                               0.033493649053890406)

        width_gt_height_ellipse = Ellipse(
            **self.width_gt_height_ellipse_params())
        coordinates_ellipse_line = (
            width_gt_height_ellipse.get_evenly_distributed_ellipse_coordinates(
                number_of_coordinates))
        assert width_gt_height_ellipse.height < width_gt_height_ellipse.width
        assert len(coordinates_ellipse_line) == 3
        assert coordinates_ellipse_line[0] == (0.65, 0.3)
        assert coordinates_ellipse_line[1] == (0.7666223198362645,
                                               0.1371094972158116)
        assert coordinates_ellipse_line[2] == (0.5333776801637811,
                                               0.13710949721577403)

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_ellipse__as_shapely_polygon(self):
        """
        <b>Description:</b>
        Check Ellipse _as_shapely_polygon methods

        <b>Input data:</b>
        Initialized instance of Ellipse

        <b>Expected results:</b>
        Test passes if Ellipse _as_shapely_polygon returns correct values

        <b>Steps</b>
        1. Initialize Ellipse instance
        2. Check returning value
        """

        ellipse = self.ellipse()
        shapely_polygon = ellipse._as_shapely_polygon()
        assert shapely_polygon.__class__ == Polygon
        assert shapely_polygon.area == 0.1958331774442254

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_ellipse_get_area(self):
        """
        <b>Description:</b>
        Check Ellipse get_area methods

        <b>Input data:</b>
        Initialized instance of Ellipse

        <b>Expected results:</b>
        Test passes if Ellipse get_area returns correct values

        <b>Steps</b>
        1. Initialize Ellipse instance
        2. Check returning value
        """

        ellipse = self.ellipse()
        area = ellipse.get_area()
        assert area == 0.19634954084936207
Exemple #20
0
class TestPolygon:
    modification_date = now()

    def points(self):
        point1 = Point(0.5, 0.0)
        point2 = Point(0.75, 0.2)
        point3 = Point(0.6, 0.1)
        return [point1, point2, point3]

    def other_points(self):
        point1 = Point(0.3, 0.1)
        point2 = Point(0.8, 0.3)
        point3 = Point(0.6, 0.2)
        return [point1, point2, point3]

    def polygon(self):
        return Polygon(self.points(), modification_date=self.modification_date)

    def other_polygon(self):
        return Polygon(self.other_points(),
                       modification_date=self.modification_date)

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_polygon(self):
        """
        <b>Description:</b>
        Check Polygon parameters

        <b>Input data:</b>
        Points

        <b>Expected results:</b>
        Test passes if Polygon correctly calculates parameters and returns default values

        <b>Steps</b>
        1. Check Polygon params
        2. Check Polygon default values
        3. Check Polygon with empty points
        """

        polygon = self.polygon()
        modification_date = self.modification_date
        assert len(polygon.points) == 3
        assert polygon.modification_date == modification_date
        assert polygon.points == self.points()

        empty_points_list = []
        with pytest.raises(ValueError):
            Polygon(empty_points_list)

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_polygon_magic_methods(self):
        """
        <b>Description:</b>
        Check Polygon __repr__, __eq__, __hash__ methods

        <b>Input data:</b>
        Initialized instance of Polygon

        <b>Expected results:</b>
        Test passes if Polygon magic methods returns correct values

        <b>Steps</b>
        1. Initialize Polygon instance
        2. Check returning value of magic methods
        """

        polygon = self.polygon()
        points_len = len(self.points())
        min_x = min(self.points(), key=attrgetter("x")).x
        max_x = max(self.points(), key=attrgetter("x")).x
        min_y = min(self.points(), key=attrgetter("y")).y
        max_y = max(self.points(), key=attrgetter("y")).y

        assert f"Polygon(len(points)={points_len}, min_x={min_x}" in repr(
            polygon)
        assert f", max_x={max_x}, min_y={min_y}, max_y={max_y})" in repr(
            polygon)

        other_polygon = self.polygon()
        thirs_polygon = self.other_polygon()
        assert polygon == other_polygon
        assert polygon != thirs_polygon
        assert polygon != str

        assert hash(polygon) == hash(str(polygon))

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_polygon_normalize_wrt_roi_shape(self):
        """
        <b>Description:</b>
        Check Polygon normalize_wrt_roi_shape methods

        <b>Input data:</b>
        Initialized instance of Polygon
        Initialized instance of Rectangle

        <b>Expected results:</b>
        Test passes if Polygon normalize_wrt_roi_shape returns correct values

        <b>Steps</b>
        1. Initialize Polygon instance
        2. Check returning value
        """

        polygon = self.polygon()
        roi = Rectangle(x1=0.0, x2=0.5, y1=0.0, y2=0.5)
        normalized = polygon.normalize_wrt_roi_shape(roi)
        assert len(normalized.points) == 3
        assert normalized.min_x == 0.25
        assert normalized.max_x == 0.375
        assert normalized.min_y == 0.0
        assert normalized.max_y == 0.1

        with pytest.raises(ValueError):
            polygon.normalize_wrt_roi_shape("123")

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_polygon_denormalize_wrt_roi_shape(self):
        """
        <b>Description:</b>
        Check Polygon denormalize_wrt_roi_shape methods

        <b>Input data:</b>
        Initialized instance of Polygon
        Initialized instance of Rectangle

        <b>Expected results:</b>
        Test passes if Polygon denormalize_wrt_roi_shape returns correct values

        <b>Steps</b>
        1. Initialize Polygon instance
        2. Check returning value
        """

        polygon = self.polygon()
        roi = Rectangle(x1=0.5, x2=1.0, y1=0.0, y2=1.0)
        denormalized = polygon.denormalize_wrt_roi_shape(roi)
        assert len(denormalized.points) == 3
        assert denormalized.min_x == 0.0
        assert denormalized.max_x == 0.5
        assert denormalized.min_y == 0.0
        assert denormalized.max_y == 0.2

        with pytest.raises(ValueError):
            polygon.denormalize_wrt_roi_shape("123")

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_polygon__as_shapely_polygon(self):
        """
        <b>Description:</b>
        Check Polygon _as_shapely_polygon methods

        <b>Input data:</b>
        Initialized instance of Polygon

        <b>Expected results:</b>
        Test passes if Polygon _as_shapely_polygon returns correct values

        <b>Steps</b>
        1. Initialize Polygon instance
        2. Check returning value
        """

        polygon = self.polygon()
        polygon2 = self.other_polygon()
        shapely_polygon = polygon._as_shapely_polygon()
        shapely_polygon2 = polygon2._as_shapely_polygon()
        assert shapely_polygon.area == 0.0025000000000000022
        assert str(
            shapely_polygon) == "POLYGON ((0.5 0, 0.75 0.2, 0.6 0.1, 0.5 0))"
        assert shapely_polygon != shapely_polygon2

    @pytest.mark.priority_medium
    @pytest.mark.component
    @pytest.mark.reqids(Requirements.REQ_1)
    def test_polygon_get_area(self):
        """
        <b>Description:</b>
        Check Polygon get_area method

        <b>Input data:</b>
        Initialized instance of Polygon

        <b>Expected results:</b>
        Test passes if Polygon get_area returns correct values

        <b>Steps</b>
        1. Initialize Polygon instance
        2. Check returning value
        """

        polygon = self.polygon()
        polygon2 = self.other_polygon()
        area = polygon.get_area()
        area2 = polygon2.get_area()
        assert area == 0.0025000000000000022
        assert area != area2