Skip to content

Commit

Permalink
formatting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
apurvabanka committed Oct 12, 2024
1 parent 712587e commit c106b2c
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 37 deletions.
11 changes: 6 additions & 5 deletions tests/containers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def test_document_boolean_visibility_invalid(self) -> None:

assert d.features[0].visibility is None
assert d.features[0].isopen
def test_container_creation(self)->None:

def test_container_creation(self) -> None:
container = containers._Container(
ns="ns",
id="id",
Expand All @@ -75,7 +75,8 @@ def test_container_creation(self)->None:
)
assert container.ns == "ns"
assert container.name == "name"
def test_container_feature_append(self)->None:

def test_container_feature_append(self) -> None:
container = containers._Container(
ns="ns",
id="id",
Expand All @@ -86,8 +87,8 @@ def test_container_feature_append(self)->None:
assert container.append(feature) is None
with pytest.raises(ValueError):
container.append(container)
def test_document_container_get_style_url(self)->None:

def test_document_container_get_style_url(self) -> None:
document = containers.Document(
name="Document",
ns="ns",
Expand Down
3 changes: 2 additions & 1 deletion tests/geometries/boundaries_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def test_outer_boundary(self) -> None:
"1.000000,2.000000 2.000000,0.000000 0.000000,0.000000 1.000000,2.000000"
"</kml:coordinates></kml:LinearRing></kml:outerBoundaryIs>"
)

def test_outer_boundry_geometry_error(self) -> None:
"""Test GeometryError."""
p = geo.Point(1, 2)
Expand Down Expand Up @@ -84,7 +85,7 @@ def test_inner_boundary(self) -> None:
"1.000000,2.000000 2.000000,0.000000 0.000000,0.000000 1.000000,2.000000"
"</kml:coordinates></kml:LinearRing></kml:innerBoundaryIs>"
)

def test_inner_boundry_geometry_error(self) -> None:
"""Test GeometryError."""
p = geo.Point(1, 2)
Expand Down
43 changes: 27 additions & 16 deletions tests/geometries/functions_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from typing_extensions import Protocol
from unittest.mock import Mock, patch
import pytest
from fastkml.exceptions import KMLParseError, KMLWriteError
from fastkml.geometry import handle_invalid_geometry_error, coordinates_subelement, create_kml_geometry
from fastkml.types import Element
from fastkml.geometry import handle_invalid_geometry_error
from fastkml.geometry import coordinates_subelement
from tests.base import StdLibrary
from fastkml import base


class TestGeometryFunctions(StdLibrary):
"""Test functions in Geometry"""
Expand All @@ -14,45 +13,57 @@ class TestGeometryFunctions(StdLibrary):
def test_handle_invalid_geometry_error_true(self, mock_to_string) -> None:
mock_element = Mock()
with pytest.raises(KMLParseError):
handle_invalid_geometry_error(error=ValueError, element=mock_element, strict=True)

handle_invalid_geometry_error(
error=ValueError,
element=mock_element,
strict=True
)

@patch('fastkml.config.etree.tostring')
def test_handle_invalid_geometry_error_false(self, mock_to_string) -> None:
mock_element = Mock()
assert handle_invalid_geometry_error(error=ValueError, element=mock_element, strict=False) is None

assert handle_invalid_geometry_error(
error=ValueError,
element=mock_element,
strict=False
) is None

def test_coordinates_subelement_exception(self) -> None:
obj = Mock()
setattr(obj, 'coordinates', [(1.123456, 2.654321, 3.111111, 4.222222)]) # Invalid 4D coordinates

setattr(obj,
'coordinates',
[(1.123456, 2.654321, 3.111111, 4.222222)]
)

element = Mock()

precision = None
attr_name = 'coordinates'

with pytest.raises(KMLWriteError):
coordinates_subelement(
obj=obj,
attr_name=attr_name,
node_name=None,
node_name=None,
element=element,
precision=precision,
verbosity=None,
default=None
)

def test_coordinates_subelement_getattr(self) -> None:
obj = Mock()
setattr(obj, 'coordinates', [(1.123456, 2.654321), (3.123456, 4.654321)])

element = Mock()

precision = 4
attr_name = 'coordinates'

assert coordinates_subelement(
obj=None,
attr_name=attr_name,
node_name=None,
node_name=None,
element=element,
precision=precision,
verbosity=None,
Expand Down
2 changes: 1 addition & 1 deletion tests/geometries/linestring_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_init(self) -> None:
assert line_string.geometry == ls
assert line_string.altitude_mode is None
assert line_string.extrude is None

def test_geometry_error(self) -> None:
"""Test GeometryError."""
p = geo.Point(1, 2)
Expand Down
2 changes: 1 addition & 1 deletion tests/geometries/multigeometry_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def test_multi_geometries_verbose(self) -> None:
assert xml.count("tessellate>0<") == 12 # points do not have tessellate
assert xml.count("extrude>0<") == 13
assert xml.count("altitudeMode>clampToGround<") == 13

def test_geometry_error(self) -> None:
"""Test GeometryError."""
p = geo.Point(1, 2)
Expand Down
2 changes: 1 addition & 1 deletion tests/geometries/point_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_init(self) -> None:
assert point.geometry == p
assert point.altitude_mode is None
assert point.extrude is None

def test_geometry_error(self) -> None:
"""Test GeometryError."""
p = geo.Point(1, 2)
Expand Down
2 changes: 1 addition & 1 deletion tests/geometries/polygon_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def test_to_string_verbose_none(self) -> None:
polygon = Polygon(ns="", geometry=poly)

assert "extrude>0</" in polygon.to_string(verbosity=Verbosity.verbose)

def test_geometry_error(self) -> None:
"""Test GeometryError."""
poly = geo.Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)])
Expand Down
2 changes: 1 addition & 1 deletion tests/gx_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_track(self) -> None:
"bbox": (0.0, 0.0, 1.0, 1.0),
"coordinates": ((0.0, 0.0), (1.0, 1.0)),
}

def test_track_etree_element(self) -> None:
g = Track()

Expand Down
23 changes: 15 additions & 8 deletions tests/helper_test.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
from unittest.mock import Mock, patch
from fastkml.helpers import attribute_enum_kwarg, attribute_float_kwarg, enum_attribute, float_attribute, node_text, subelement_enum_kwarg, subelement_float_kwarg, subelement_int_kwarg
from fastkml.types import Element
from fastkml.helpers import attribute_enum_kwarg
from fastkml.helpers import attribute_float_kwarg
from fastkml.helpers import enum_attribute
from fastkml.helpers import float_attribute
from fastkml.helpers import node_text
from fastkml.helpers import subelement_enum_kwarg
from fastkml.helpers import subelement_float_kwarg
from fastkml.helpers import subelement_int_kwarg
from tests.base import StdLibrary
from enum import Enum


class Node:
text: str


class Color(Enum):
RED = 1


class TestStdLibrary(StdLibrary):
@patch('fastkml.helpers.get_value')
def test_node_text(self, mock_get_value) -> None:
Expand Down Expand Up @@ -39,7 +47,7 @@ def test_float_attribute(self, mock_get_value) -> None:
default="default"
)
assert res is None

@patch('fastkml.helpers.get_value')
def test_enum_attribute(self, mock_get_value) -> None:
mock_get_value.return_value = None
Expand All @@ -53,7 +61,7 @@ def test_enum_attribute(self, mock_get_value) -> None:
default="default"
)
assert res is None

def test_subelement_int_kwarg(self):
node = Node()
node.text = None
Expand All @@ -69,7 +77,7 @@ def test_subelement_int_kwarg(self):
strict=False
)
assert res == {}

def test_subelement_float_kwarg(self):
node = Node()
node.text = None
Expand All @@ -85,7 +93,7 @@ def test_subelement_float_kwarg(self):
strict=False
)
assert res == {}

@patch('fastkml.helpers.handle_error')
def test_attribute_float_kwarg(self, mock_handle_error) -> None:
element = Mock()
Expand All @@ -102,7 +110,6 @@ def test_attribute_float_kwarg(self, mock_handle_error) -> None:
)
assert res == {}


def test_subelement_enum_kwarg(self) -> None:
node = Node()
node.text = None
Expand All @@ -118,7 +125,7 @@ def test_subelement_enum_kwarg(self) -> None:
strict=True
)
assert res == {}

def test_attribute_enum_kwarg(self) -> None:
element = Mock()
element.get.return_value = None
Expand Down
10 changes: 8 additions & 2 deletions tests/kml_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def test_parse_kml_fileobject(self) -> None:
),
],
)

@patch('fastkml.config.etree')
def test_kml_etree_element(self, mock_etree) -> None:

Expand All @@ -184,7 +184,12 @@ def test_kml_etree_element(self, mock_etree) -> None:

doc = kml.KML.parse(empty_placemark)

assert doc.etree_element() == config.etree.Element( f"{doc.ns}{doc.get_tag_name()}", nsmap={None: doc.ns[1:-1]},)
res = config.etree.Element(
f"{doc.ns}{doc.get_tag_name()}",
nsmap={None: doc.ns[1:-1]}
)

assert doc.etree_element() == res

def test_kml_append(self) -> None:
empty_placemark = KMLFILEDIR / "emptyPlacemarkWithoutId.xml"
Expand All @@ -194,6 +199,7 @@ def test_kml_append(self) -> None:
with pytest.raises(ValueError):
doc.append(doc)


class TestParseKMLNone(StdLibrary):
def test_kml_parse(self) -> None:
empty_placemark = KMLFILEDIR / "emptyPlacemarkWithoutId.xml"
Expand Down

0 comments on commit c106b2c

Please sign in to comment.