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

Test cases for OGC Test Suit #391

Draft
wants to merge 3 commits into
base: 317-add-tests-for-the-ogc-kml-22-conformance-test-suite
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ tests = [
"pytest-cov",
"pytz",
"tzdata",
"xmldiff",
]
typing = [
"mypy",
Expand Down
121 changes: 121 additions & 0 deletions tests/ogc_conformance/ogc_kml_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
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)
# TODO: Add NetworkLinkControl parser
doc = fastkml.kml.KML.parse(clean_doc)

diff = main.diff_texts(
doc.to_string().encode("utf-8"),
expected_xml,
)

assert fastkml.validator.validate(file_to_validate=clean_doc)
assert fastkml.validator.validate(element=doc.etree_element())

def test_docunemt_empty_placemark_without_id(self) -> None:
Copy link
Preview

Copilot AI Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name 'test_docunemt_empty_placemark_without_id' contains a typo. It should be 'test_document_empty_placemark_without_id'.

Suggested change
def test_docunemt_empty_placemark_without_id(self) -> None:
def test_document_empty_placemark_without_id(self) -> None:

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
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,
)
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,
)

# assert diff is None
Copy link
Preview

Copilot AI Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commented-out assertion should either be removed or uncommented and corrected to 'assert diff == []' to be consistent with other tests.

Suggested change
# assert diff is None
assert diff == []

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options

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,
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,
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,
formatter=formatter,
)

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

Copilot AI Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commented-out assertion should either be removed or uncommented and corrected to 'assert fastkml.validator.validate(element=doc.etree_element())'.

Suggested change
# assert fastkml.validate.validate(element=doc.etree_element())
assert fastkml.validator.validate(element=doc.etree_element())

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options

def test_read_kml_samples(self) -> None:
for p in KMLFILEDIR.glob("**/models/*.kml"):
doc = fastkml.kml.KML.parse(p)
diff = main.diff_texts(
doc.to_string(),
p.open("rb").read()
)
assert diff == []
assert doc.validate()

Loading