From b9d37e023b4ac09ed057fce428c11fc15ee30365 Mon Sep 17 00:00:00 2001 From: Christian Ledermann Date: Sat, 9 Nov 2024 13:23:26 +0000 Subject: [PATCH] Add hypothesis test for styles and refactor StyleUrl class --- docs/working_with_kml.rst | 9 +- fastkml/styles.py | 20 +-- tests/hypothesis/common.py | 6 + tests/hypothesis/strategies.py | 11 ++ tests/hypothesis/style_test.py | 267 +++++++++++++++++++++++++++++++++ tests/repr_eq_test.py | 14 -- tests/styles_test.py | 15 +- 7 files changed, 302 insertions(+), 40 deletions(-) create mode 100644 tests/hypothesis/style_test.py diff --git a/docs/working_with_kml.rst b/docs/working_with_kml.rst index 8cda819a..ab630a61 100644 --- a/docs/working_with_kml.rst +++ b/docs/working_with_kml.rst @@ -164,6 +164,8 @@ Now we can create a new KML object and confirm that the new element is parsed co To be able to open the KML file in Google Earth Pro, we need to transform the CascadingStyle element into a supported Style element. +To achieve this we copy the styles into the document styles and adjust their id +to match the id of the CascadingStyle. .. code-block:: pycon @@ -173,6 +175,11 @@ CascadingStyle element into a supported Style element. ... kml_style.id = cascading_style.id ... document.styles.append(kml_style) ... + +Now we can remove the CascadingStyle from the document and have a look at the result. + +.. code-block:: pycon + >>> document.gx_cascading_style = [] >>> print(document.to_string(prettyprint=True)) @@ -222,7 +229,7 @@ CascadingStyle element into a supported Style element. 80000000 - + Ort1 10.06256752902339 diff --git a/fastkml/styles.py b/fastkml/styles.py index c70de2c7..ebd9a1ff 100644 --- a/fastkml/styles.py +++ b/fastkml/styles.py @@ -62,7 +62,7 @@ logger = logging.getLogger(__name__) -class StyleUrl(_BaseObject): +class StyleUrl(_XMLObject): """ URL of a