diff --git a/ohsome_quality_api/indicators/attribute_completeness/indicator.py b/ohsome_quality_api/indicators/attribute_completeness/indicator.py index 2f7f9fb5f..e069d36ea 100644 --- a/ohsome_quality_api/indicators/attribute_completeness/indicator.py +++ b/ohsome_quality_api/indicators/attribute_completeness/indicator.py @@ -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 @@ -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. diff --git a/tests/integrationtests/indicators/test_attribute_completeness.py b/tests/integrationtests/indicators/test_attribute_completeness.py index d54581635..3b6bdccf6 100644 --- a/tests/integrationtests/indicators/test_attribute_completeness.py +++ b/tests/integrationtests/indicators/test_attribute_completeness.py @@ -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. ' ) diff --git a/tests/unittests/indicators/test_attribute_completeness.py b/tests/unittests/indicators/test_attribute_completeness.py new file mode 100644 index 000000000..52efb189d --- /dev/null +++ b/tests/unittests/indicators/test_attribute_completeness.py @@ -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" \ No newline at end of file