Skip to content

Commit

Permalink
test/refactor: started work on a new unittest and made a function in …
Browse files Browse the repository at this point in the history
…indicator.py more readable #828
  • Loading branch information
JanReifenrath authored and Gigaszi committed Nov 12, 2024
1 parent fe3af83 commit 23ebe53
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
17 changes: 10 additions & 7 deletions ohsome_quality_api/indicators/attribute_completeness/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,7 @@ def calculate(self) -> None:
if self.result.value is None:
self.result.description += " No features in this region"
return
self.description = Template(self.templates.result_description).substitute(
result=round(self.result.value, 2),
all=round(self.absolute_value_1, 1),
matched=round(self.absolute_value_2, 1),
topic=self.topic.name,
tag=self.attribute_key[0],
)
self.create_description()

if self.result.value >= self.threshold_yellow:
self.result.class_ = 5
Expand All @@ -94,6 +88,15 @@ def calculate(self) -> None:
self.description + self.templates.label_description["red"]
)

def create_description(self):
self.description = Template(self.templates.result_description).substitute(
result=round(self.result.value, 2),
all=round(self.absolute_value_1, 1),
matched=round(self.absolute_value_2, 1),
topic=self.topic.name,
tag=self.attribute_key[0],
)

def create_figure(self) -> None:
"""Create a gauge chart.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def indicator(
indicator.description
== (
"The ratio of the topic Building Count in the "
"selected area (all: 29936.0) " # too specific, needs regex
"selected area (all: 29936.0) "
"compared to the topic Building Count with the "
'expected tag "height" (matched: 8702.0) is 0.29. '
)
Expand Down
8 changes: 8 additions & 0 deletions tests/unittests/indicators/test_attribute_completeness.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from ohsome_quality_api.indicators.attribute_completeness.indicator import AttributeCompleteness


def test_create_description():
indicator = AttributeCompleteness() # Grundschritte hier setzen
indicator.result = # nötige result Werte hier setzen
description = indicator.create_description()
assert description == "expected text here"

0 comments on commit 23ebe53

Please sign in to comment.