diff --git a/tests/kml_test.py b/tests/kml_test.py index fb04fb25..547161b7 100644 --- a/tests/kml_test.py +++ b/tests/kml_test.py @@ -18,6 +18,7 @@ import io import pathlib +import zipfile import pygeoif as geo import pytest @@ -209,10 +210,16 @@ def test_write_kml_file(self) -> None: ) file_path = KMLFILEDIR / "output.kml" - doc.write(file_path=file_path, prettyprint=True, xml_declaration=True) + doc.write(file_path=file_path, prettyprint=True, xml_declaration=False) assert file_path.is_file(), "KML file was not created." + parsed_doc = kml.KML.parse(file_path) + + assert parsed_doc.to_string() == doc.to_string(), "Written and original documents don't match" + + file_path.unlink() + def test_write_kmz_file(self) -> None: doc = kml.KML( @@ -236,10 +243,22 @@ def test_write_kmz_file(self) -> None: file_path = KMLFILEDIR / "output.kmz" - doc.write(file_path=file_path, prettyprint=True, xml_declaration=True) + doc.write(file_path=file_path, prettyprint=True, xml_declaration=False) assert file_path.is_file(), "KMZ file was not created." + tree = doc.to_string() + + with zipfile.ZipFile(file_path, 'r') as kmz: + assert 'doc.kml' in kmz.namelist(), "doc.kml not found in the KMZ file" + + with kmz.open('doc.kml') as doc_kml: + kml_content = doc_kml.read().decode("utf-8") + + assert kml_content == tree, "KML content does not match expected content" + + file_path.unlink() + class TestLxml(Lxml, TestStdLibrary): """Test with lxml.""" diff --git a/tests/ogc_conformance/data/kml/output.kml b/tests/ogc_conformance/data/kml/output.kml deleted file mode 100644 index 1bf68287..00000000 --- a/tests/ogc_conformance/data/kml/output.kml +++ /dev/null @@ -1,2 +0,0 @@ - -Vestibulum eleifend lobortis lorem. \ No newline at end of file diff --git a/tests/ogc_conformance/data/kml/output.kmz b/tests/ogc_conformance/data/kml/output.kmz deleted file mode 100644 index bc737f2d..00000000 Binary files a/tests/ogc_conformance/data/kml/output.kmz and /dev/null differ