Skip to content

Commit

Permalink
refactor: remove unnecessary check
Browse files Browse the repository at this point in the history
check is not needed anymore because of request validation by pydantic
models
  • Loading branch information
matthiasschaub committed Nov 20, 2024
1 parent 51475b6 commit 6de33c1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 32 deletions.
23 changes: 7 additions & 16 deletions ohsome_quality_api/indicators/attribute_completeness/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class AttributeCompleteness(BaseIndicator):
attribute: Additional (expected) tag(s) describing a map feature.
attribute_keys: a set of predefined attributes wich will be
translated to an ohsome filter
attribute_filter: a custom ohsome filter
attribute_filter: ohsome filter query representing custom attributes
attribute_names: Names of the attributed represented by the Attribute Filter
Example: How many buildings (topic) have height information (attribute)?
Expand Down Expand Up @@ -54,16 +55,6 @@ def __init__(
self.absolute_value_1 = None
self.absolute_value_2 = None
self.description = None
# fmt: off
# TODO: Remove once validated by pydantic request model
if (
all(v is None for v in (attribute_keys, attribute_filter)) or
all(v is not None for v in (attribute_keys, attribute_filter))
):
raise TypeError(
"Either `attribute_keys` or `attribute_filter` needs to be given"
)
# fmt: on
if self.attribute_keys:
self.attribute_filter = build_attribute_filter(
self.attribute_keys,
Expand Down Expand Up @@ -113,15 +104,15 @@ def calculate(self) -> None:
)

def create_description(self):
all, matched = self.compute_units_for_all_and_matched()
if self.result.value is None:
raise TypeError("result value should not be None")
raise TypeError("Result value should not be None.")
else:
result = round(self.result.value * 100, 1)
if len(self.attribute_names) > 1:
tags = "attributes " + ", ".join(self.attribute_names)
if self.attribute_names is None:
raise TypeError("Attribute names should not be None.")
else:
tags = "attribute " + self.attribute_names[0]
tags = "attributes " + ", ".join(self.attribute_names)
all, matched = self.compute_units_for_all_and_matched()
self.description = Template(self.templates.result_description).substitute(
result=result,
all=all,
Expand Down
15 changes: 0 additions & 15 deletions tests/integrationtests/indicators/test_attribute_completeness.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,6 @@
oqapi_vcr,
)

def test_preprocess_too_many_parameter(
self,
topic_building_count,
feature_germany_heidelberg,
attribute_key,
attribute_filter,
):
with pytest.raises(TypeError):
AttributeCompleteness(
topic_building_count,
feature_germany_heidelberg,
attribute_key,
attribute_filter,
)


class TestPreprocess:
@oqapi_vcr.use_cassette
Expand Down
2 changes: 1 addition & 1 deletion tests/integrationtests/test_ohsome_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_query_ohsome_api_exceptions_404():
asyncio.run(ohsome_client.query_ohsome_api(url, {}))


@oqapi_vcr.use_cassette()
@oqapi_vcr.use_cassette
def test_query_ohsome_api_exceptions_400():
url = "https://api.ohsome.org/v1/elements/length"
with pytest.raises(OhsomeApiError, match="Invalid filter syntax."):
Expand Down

0 comments on commit 6de33c1

Please sign in to comment.