-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improving Test coverage #365
Changes from all commits
056095a
84e1787
ad4d00c
d5bf4c9
a101c82
f0eaa11
4b8a9ed
bf96ebf
8e48250
040d092
589a00f
712587e
c106b2c
349436a
84e8bb9
5ebf637
5ad43b6
200bcb5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
from unittest.mock import Mock, patch | ||
import pytest | ||
from fastkml.exceptions import KMLParseError, KMLWriteError | ||
from fastkml.geometry import handle_invalid_geometry_error | ||
from fastkml.geometry import coordinates_subelement | ||
from tests.base import StdLibrary | ||
|
||
|
||
class TestGeometryFunctions(StdLibrary): | ||
"""Test functions in Geometry""" | ||
|
||
@patch('fastkml.config.etree.tostring') | ||
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 | ||
) | ||
|
||
@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 | ||
|
||
def test_coordinates_subelement_exception(self) -> None: | ||
obj = Mock() | ||
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, | ||
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, | ||
element=element, | ||
precision=precision, | ||
verbosity=None, | ||
default=None | ||
) is None | ||
Comment on lines
+54
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix discrepancy between setup and function call. There's an important issue in this test that needs to be addressed. The test sets up a mock object with valid 2D coordinates, but then passes To fix this, replace: assert coordinates_subelement(
obj=None,
# ... other arguments ...
) is None with: assert coordinates_subelement(
obj=obj,
# ... other arguments ...
) is None This change ensures that the test actually uses the mock object with the valid coordinates you've set up, making the test more effective and meaningful. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Expand test coverage for get_style_by_url method
The current test verifies that
get_style_by_url
returnsNone
for a valid style_url. However, it's unclear if this is the expected behavior. Consider the following improvements:get_style_by_url
returnsNone
for a valid style_url. Is this the intended behavior?get_style_by_url
returns a non-None value to demonstrate when it successfully retrieves a style.Here's a suggested improvement: