-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
206 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,88 @@ | ||
from unittest.mock import Mock, patch | ||
# Copyright (C) 2024 Rishit Chaudhary, Christian Ledermann | ||
# | ||
# This library is free software; you can redistribute it and/or modify it under | ||
# the terms of the GNU Lesser General Public License as published by the Free | ||
# Software Foundation; either version 2.1 of the License, or (at your option) | ||
# any later version. | ||
# | ||
# This library is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this library; if not, write to the Free Software Foundation, Inc., | ||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
"""Test the geometry error handling.""" | ||
from typing import Callable | ||
from unittest.mock import Mock | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from fastkml.exceptions import KMLParseError, KMLWriteError | ||
from fastkml.geometry import handle_invalid_geometry_error | ||
|
||
from fastkml.enums import Verbosity | ||
from fastkml.exceptions import KMLParseError | ||
from fastkml.exceptions import KMLWriteError | ||
from fastkml.geometry import coordinates_subelement | ||
from fastkml.geometry import handle_invalid_geometry_error | ||
from tests.base import StdLibrary | ||
|
||
|
||
class TestGeometryFunctions(StdLibrary): | ||
"""Test functions in Geometry""" | ||
"""Test functions in Geometry.""" | ||
|
||
@patch('fastkml.config.etree.tostring') | ||
def test_handle_invalid_geometry_error_true(self, mock_to_string) -> None: | ||
@patch("fastkml.config.etree.tostring", return_value=b"<kml:../>") | ||
def test_handle_invalid_geometry_error_true( | ||
self, | ||
mock_to_string: Callable[..., str], | ||
) -> None: | ||
mock_element = Mock() | ||
with pytest.raises(KMLParseError): | ||
with pytest.raises( | ||
KMLParseError, | ||
match=mock_to_string.return_value.decode(), # type: ignore[attr-defined] | ||
): | ||
handle_invalid_geometry_error( | ||
error=ValueError, | ||
error=ValueError(), | ||
element=mock_element, | ||
strict=True | ||
strict=True, | ||
) | ||
mock_to_string.assert_called_once_with( # type: ignore[attr-defined] | ||
mock_element, | ||
encoding="UTF-8", | ||
) | ||
|
||
@patch('fastkml.config.etree.tostring') | ||
def test_handle_invalid_geometry_error_false(self, mock_to_string) -> None: | ||
@patch("fastkml.config.etree.tostring", return_value=b"<kml:... />") | ||
def test_handle_invalid_geometry_error_false( | ||
self, | ||
mock_to_string: Callable[..., str], | ||
) -> None: | ||
mock_element = Mock() | ||
assert handle_invalid_geometry_error( | ||
error=ValueError, | ||
handle_invalid_geometry_error( | ||
error=ValueError(), | ||
element=mock_element, | ||
strict=False | ||
) is None | ||
strict=False, | ||
) | ||
mock_to_string.assert_called_once_with( # type: ignore[attr-defined] | ||
mock_element, | ||
encoding="UTF-8", | ||
) | ||
|
||
def test_coordinates_subelement_exception(self) -> None: | ||
obj = Mock() | ||
setattr(obj, | ||
'coordinates', | ||
[(1.123456, 2.654321, 3.111111, 4.222222)] | ||
) | ||
obj.coordinates = [(1.123456, 2.654321, 3.111111, 4.222222)] | ||
|
||
element = Mock() | ||
|
||
precision = None | ||
attr_name = 'coordinates' | ||
precision = 9 | ||
attr_name = "coordinates" | ||
|
||
with pytest.raises(KMLWriteError): | ||
coordinates_subelement( | ||
obj=obj, | ||
attr_name=attr_name, | ||
node_name=None, | ||
node_name="", | ||
element=element, | ||
precision=precision, | ||
verbosity=None, | ||
default=None | ||
verbosity=Verbosity.terse, | ||
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, | ||
element=element, | ||
precision=precision, | ||
verbosity=None, | ||
default=None | ||
) is None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.