Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for the OGC KML 2.2 Conformance Test Suite #317

Open
cleder opened this issue Apr 21, 2024 · 7 comments
Open

Add tests for the OGC KML 2.2 Conformance Test Suite #317

cleder opened this issue Apr 21, 2024 · 7 comments

Comments

@cleder
Copy link
Owner

cleder commented Apr 21, 2024

The kml and kmz files to be tested are present in:
/tests/ogc_conformance/
to be done after #284

@cleder cleder added this to FastKML Apr 21, 2024
@cleder cleder added this to the Version 1.0 milestone Apr 21, 2024
@cleder cleder modified the milestones: Version 1.0, Version 1.1 Nov 13, 2024
@apurvabanka
Copy link
Contributor

@cleder Can you assign me this issue?

@cleder
Copy link
Owner Author

cleder commented Nov 17, 2024

I gave it a bit of a start.
The idea is to read each file in fastkml and it then has to reproduce the original with to_string, i.e. the xmldiff should be empty.

import pathlib

from xmldiff import formatting
from xmldiff import main

import fastkml
import fastkml.validator
from tests.base import Lxml

BASEDIR = pathlib.Path(__file__).parent
KMLFILEDIR = BASEDIR / "data" / "kml"


class TestLxml(Lxml):
    """Test with the standard library."""

    def test_document_clean(self) -> None:
        clean_doc = KMLFILEDIR / "Document-clean.kml"
        expected_xml = clean_doc.open("rb").read()
        formatter = formatting.XmlDiffFormatter(normalize=formatting.WS_BOTH)

        doc = fastkml.kml.KML.parse(clean_doc)

        diff = main.diff_texts(
            doc.to_string(),
            expected_xml,
            # diff_options={"uniqueattrs": "{http://www.opengis.net/kml/2.2}id"},
            # formatter=formatter,
        )

        assert fastkml.validator.validate(file_to_validate=clean_doc)
        assert fastkml.validator.validate(element=doc.etree_element())
        # assert diff == []

    def test_docunemt_empty_placemark_without_id(self) -> None:
        empty_placemark = KMLFILEDIR / "emptyPlacemarkWithoutId.xml"
        expected_xml = empty_placemark.open("rb").read()
        formatter = formatting.DiffFormatter(normalize=formatting.WS_BOTH)

        doc = fastkml.kml.KML.parse(empty_placemark)

        diff = main.diff_texts(
            doc.to_string(),
            expected_xml,
            # diff_options={"uniqueattrs": "{http://www.opengis.net/kml/2.2}id"},
            # formatter=formatter,
        )
        assert diff == []
        assert fastkml.validator.validate(file_to_validate=empty_placemark)
        assert fastkml.validator.validate(element=doc.etree_element())

    def test_document_deprecated(self) -> None:
        deprecated_doc = KMLFILEDIR / "Document-deprecated.kml"
        expected_xml = deprecated_doc.open("rb").read()
        formatter = formatting.DiffFormatter(normalize=formatting.WS_BOTH)

        doc = fastkml.kml.KML.parse(deprecated_doc)

        diff = main.diff_texts(
            doc.to_string(),
            expected_xml,
            # diff_options={"uniqueattrs": "{http://www.opengis.net/kml/2.2}id"},
            # formatter=formatter,
        )

        # assert diff is None

    def test_document_places(self) -> None:
        places_doc = KMLFILEDIR / "Document-places.kml"
        expected_xml = places_doc.open("rb").read()
        formatter = formatting.DiffFormatter(normalize=formatting.WS_BOTH)

        doc = fastkml.kml.KML.parse(places_doc)

        diff = main.diff_texts(
            doc.to_string(precision=2),
            expected_xml,
            # diff_options={"uniqueattrs": "{http://www.opengis.net/kml/2.2}id"},
            formatter=formatter,
        )

        assert diff == ""
        assert fastkml.validator.validate(file_to_validate=places_doc)
        assert fastkml.validator.validate(element=doc.etree_element())

    def test_document_kml_samples(self) -> None:
        kml_samples_doc = KMLFILEDIR / "KML_Samples.kml"
        expected_xml = kml_samples_doc.open("rb").read()
        formatter = formatting.DiffFormatter(normalize=formatting.WS_BOTH)

        doc = fastkml.kml.KML.parse(kml_samples_doc)

        diff = main.diff_texts(
            doc.to_string(),
            expected_xml,
            # diff_options={"uniqueattrs": "{http://www.opengis.net/kml/2.2}id"},
            formatter=formatter,
        )

        # assert diff is None
        assert fastkml.validator.validate(file_to_validate=kml_samples_doc)
        assert fastkml.validator.validate(element=doc.etree_element())

    def test_document_linearring_with_1d_tuple(self) -> None:
        linearring_1d_tuples = KMLFILEDIR / "LinearRingWith1DTuple.kml"
        expected_xml = linearring_1d_tuples.open("rb").read()
        formatter = formatting.DiffFormatter(normalize=formatting.WS_BOTH)

        doc = fastkml.kml.KML.parse(linearring_1d_tuples)

        diff = main.diff_texts(
            doc.to_string(precision=1),
            expected_xml,
            # diff_options={"uniqueattrs": "{http://www.opengis.net/kml/2.2}id"},
            formatter=formatter,
        )

        # assert diff is None
        assert fastkml.validator.validate(file_to_validate=linearring_1d_tuples)
        # assert fastkml.validate.validate(element=doc.etree_element())

    def test_read_kml_samples(self) -> None:
        for p in KMLFILEDIR.glob("**/*.kml"):
            print(p)
            doc = fastkml.kml.KML.parse(p)
            # assert doc.validate()
            # assert doc.to_string() == p.open("rb").read()

@apurvabanka
Copy link
Contributor

@cleder This change requires to install "xmldiff". Should this be added to the requirement.txt or the pyproject.toml.?
For pyproject.toml, how do we add the dependency? I have used poetry in the past but I don't see you use poetry for this repo.

@cleder
Copy link
Owner Author

cleder commented Nov 18, 2024

pyproject.toml

[project.optional-dependencies]
tests = [
    "hypothesis[dateutil]",
    "pytest",
    "pytest-cov",
    "pytz",
    "tzdata",
    "xmldiff", # here
]

@apurvabanka
Copy link
Contributor

@cleder Trying to understand what we are comparing here. I tried to create a KML file after using the Parse function on "Document-clean.kml" file. I see there are components that the Parser function doesn't account for.
For eg. <NetworkLinkControl> tag. Our parser doesn't parse this tag. How do we handle this?

@cleder
Copy link
Owner Author

cleder commented Nov 19, 2024

Create an Issue to implement the tag.

@apurvabanka
Copy link
Contributor

@cleder Created the issue #390. Can you verify if any fields are missing?

@cleder cleder linked a pull request Dec 2, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

2 participants