Skip to content

Commit

Permalink
Helpers test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
cleder committed Jan 29, 2024
1 parent 5e44ba1 commit bf27ca8
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 59 deletions.
42 changes: 42 additions & 0 deletions tests/containers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,55 @@

"""Test the kml classes."""


from fastkml import kml
from tests.base import Lxml
from tests.base import StdLibrary


class TestStdLibrary(StdLibrary):
"""Test with the standard library."""

def test_document_boolean_visibility(self) -> None:
doc = """<kml xmlns="http://www.opengis.net/kml/2.2">
<Document targetId="someTargetId">
<name>Document.kml</name>
<visibility>true</visibility>
<open>1</open>
</Document>
</kml>"""

k = kml.KML.class_from_string(doc, strict=False)
assert k.features[0].visibility
assert k.features[0].isopen

def test_document_boolean_open(self) -> None:
doc = """<kml xmlns="http://www.opengis.net/kml/2.2">
<Document targetId="someTargetId">
<name>Document.kml</name>
<visibility>0</visibility>
<open>false</open>
</Document>
</kml>"""

k = kml.KML.class_from_string(doc, strict=False)
assert k.features[0].visibility == 0
assert k.features[0].isopen is False

def test_document_boolean_visibility_invalid(self) -> None:
doc = """<kml xmlns="http://www.opengis.net/kml/2.2">
<Document targetId="someTargetId">
<name>Document.kml</name>
<visibility>invalid</visibility>
<open>1</open>
</Document>
</kml>"""

d = kml.KML.class_from_string(doc, strict=False)

assert d.features[0].visibility is None
assert d.features[0].isopen


class TestLxml(Lxml, TestStdLibrary):
"""Test with lxml."""
24 changes: 0 additions & 24 deletions tests/oldunit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,30 +219,6 @@ def test_document(self) -> None:
k2 = kml.KML.class_from_string(k.to_string())
assert k.to_string() == k2.to_string()

def test_document_booleans(self) -> None:
doc = """<kml xmlns="http://www.opengis.net/kml/2.2">
<Document targetId="someTargetId">
<name>Document.kml</name>
<visibility>true</visibility>
<open>1</open>
</Document>
</kml>"""

k = kml.KML.class_from_string(doc, strict=False)
assert k.features[0].visibility == 1
assert k.features[0].isopen == 1
doc = """<kml xmlns="http://www.opengis.net/kml/2.2">
<Document targetId="someTargetId">
<name>Document.kml</name>
<visibility>0</visibility>
<open>false</open>
</Document>
</kml>"""

k = kml.KML.class_from_string(doc, strict=False)
assert k.features[0].visibility == 0
assert k.features[0].isopen == 0

def test_folders(self) -> None:
doc = """<kml xmlns="http://www.opengis.net/kml/2.2">
<Folder>
Expand Down
55 changes: 20 additions & 35 deletions tests/overlays_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,6 @@
from tests.base import StdLibrary


class TestBaseOverlay(StdLibrary):
def test_color_string(self) -> None:
o = overlays._Overlay(name="An Overlay")
o.color = "00010203"
assert o.color == "00010203"

def test_color_none(self) -> None:
o = overlays._Overlay(name="An Overlay")
o.color = "00010203"
assert o.color == "00010203"
o.color = None
assert o.color is None

def test_draw_order_string(self) -> None:
o = overlays._Overlay(name="An Overlay")
o.draw_order = 1
assert o.draw_order == 1

def test_draw_order_int(self) -> None:
o = overlays._Overlay(name="An Overlay")
o.draw_order = 1
assert o.draw_order == 1

def test_draw_order_none(self) -> None:
o = overlays._Overlay(name="An Overlay")
o.draw_order = 1
assert o.draw_order == 1
o.draw_order = None
assert o.draw_order is None


class TestGroundOverlay(StdLibrary):
pass

Expand Down Expand Up @@ -116,6 +85,26 @@ def test_altitude_from_float(self) -> None:

assert g.to_string() == expected.to_string()

def test_altitude_invalid(self) -> None:
g = overlays.GroundOverlay.class_from_string(
'<kml:GroundOverlay xmlns:kml="http://www.opengis.net/kml/2.2">'
"<kml:altitude> one two</kml:altitude>"
"</kml:GroundOverlay>",
strict=False,
)

assert g.altitude is None

def test_draw_order_from_invalid(self) -> None:
g = overlays.GroundOverlay.class_from_string(
'<kml:GroundOverlay xmlns:kml="http://www.opengis.net/kml/2.2">'
"<kml:drawOrder>nan</kml:drawOrder>"
"</kml:GroundOverlay>",
strict=False,
)

assert g.draw_order is None

def test_altitude_from_string(self) -> None:
g = overlays.GroundOverlay(
altitude=123.4,
Expand Down Expand Up @@ -371,10 +360,6 @@ def test_camera_initialization(self) -> None:
assert po.view.altitude_mode == AltitudeMode("relativeToGround")


class TestBaseOverlayLxml(Lxml, TestBaseOverlay):
"""Test with lxml."""


class TestGroundOverlayLxml(Lxml, TestGroundOverlay):
"""Test with lxml."""

Expand Down

0 comments on commit bf27ca8

Please sign in to comment.