예제 #1
0
    def it_raises_value_error_if_filename_is_empty(annotation_path: Path):
        annotation_path.write_text("<root><filename></filename></root>")

        with pytest.raises(ValueError) as info:
            parse_path(annotation_path)

        assert str(info.value) == "filename element does not have a text value"
예제 #2
0
    def it_raises_value_error_if_filename_tag_not_found(annotation_path: Path):
        annotation_path.write_text("<root></root>")

        with pytest.raises(ValueError) as info:
            parse_path(annotation_path)

        assert str(
            info.value) == "Could not find filename element in annotation file"
예제 #3
0
    def it_raises_if_name_tag_not_found_in_object(annotation_path: Path):
        annotation_path.write_text(
            "<root><filename>image.jpg</filename><object></object></root>")

        with pytest.raises(ValueError) as info:
            parse_path(annotation_path)

        assert str(
            info.value) == "Could not find name element in annotation file"
예제 #4
0
    def it_raises_if_xmax_tag_not_found_in_object(annotation_path: Path):
        annotation_path.write_text(
            "<root><filename>image.jpg</filename><object><name>Class</name><bndbox><xmin>10</xmin></bndbox></object></root>"
        )

        with pytest.raises(ValueError) as info:
            parse_path(annotation_path)

        assert str(
            info.value) == "Could not find xmax element in annotation file"
예제 #5
0
    def it_returns_annotation_file_with_empty_annotations_otherwise(
            annotation_path: Path):
        annotation_path.write_text(
            "<root><filename>image.jpg</filename></root>")

        annotation_file = parse_path(annotation_path)

        assert annotation_file is not None
        assert annotation_file.path == annotation_path
        assert annotation_file.filename == "image.jpg"
        assert not annotation_file.annotation_classes
        assert not annotation_file.annotations
        assert annotation_file.remote_path == "/"
예제 #6
0
    def it_returns_annotation_file_with_correct_annotations_with_float_values(
            annotation_path: Path):
        annotation_path.write_text(
            "<root><filename>image.jpg</filename><object><name>Class</name><bndbox><xmin>10.0</xmin><xmax>10.0</xmax><ymin>10.0</ymin><ymax>10.0</ymax></bndbox></object></root>"
        )

        annotation_file = parse_path(annotation_path)

        assert annotation_file is not None
        assert annotation_file.path == annotation_path
        assert annotation_file.filename == "image.jpg"

        class_ = annotation_file.annotation_classes.pop()
        assert class_.name == "Class"
        assert class_.annotation_type == "bounding_box"

        annotation: Annotation = cast(Annotation,
                                      annotation_file.annotations.pop())
        assert annotation.annotation_class == class_
        assert annotation.data == {"x": 10, "y": 10, "w": 0, "h": 0}
        assert annotation.subs == []

        assert annotation_file.remote_path == "/"
예제 #7
0
    def it_raises_file_not_found_error_if_file_does_not_exist():
        path = Path("path/to/file.xml")

        with pytest.raises(FileNotFoundError):
            parse_path(path)
예제 #8
0
 def it_returns_none_if_path_suffix_is_not_xml():
     path = Path("path/to/file.json")
     assert parse_path(path) is None