Skip to content

Commit

Permalink
feat/test: plot description of the attribute completeness can now hav…
Browse files Browse the repository at this point in the history
…e multiple attributes/ tags. Also changed the tests to adjust to the changed description and wrote a unittest for a description with multiple attributes #828
  • Loading branch information
JanReifenrath authored and Gigaszi committed Nov 12, 2024
1 parent 1bf4292 commit 2082fe4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def create_description(self):
all=round(self.absolute_value_1, 1),
matched=round(self.absolute_value_2, 1),
topic=self.topic.name,
tag=self.attribute_key[0],
tags="tags " + ", ".join(self.attribute_key)
if len(self.attribute_key) > 1
else "tag " + self.attribute_key[0],
)

def create_figure(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ label_description:
The quality level could not be calculated for this indicator.
result_description: >-
The ratio of the topic $topic in the selected area (all: $all) compared to the topic $topic with the
expected tag "$tag" (matched: $matched) is $result.
expected $tags (matched: $matched) is $result.
13 changes: 5 additions & 8 deletions tests/integrationtests/indicators/test_attribute_completeness.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,11 @@ def indicator(
)
asyncio.run(indicator.preprocess())
indicator.calculate()
assert (
indicator.description
== (
"The ratio of the topic Building Count in the "
"selected area (all: 29936.0) "
"compared to the topic Building Count with the "
'expected tag "height" (matched: 8702.0) is 0.29. '
)
assert indicator.description == (
"The ratio of the topic Building Count in the "
"selected area (all: 29936.0) "
"compared to the topic Building Count with the "
"expected tag height (matched: 8702.0) is 0.29. "
)
return indicator

Expand Down
27 changes: 24 additions & 3 deletions tests/unittests/indicators/test_attribute_completeness.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@


def test_create_description():
def topic_building_count():
def topic_building_count(): # for getting an object with the attribute "name"
pass

indicator = AttributeCompleteness(
topic_building_count,
"feature_germany_heidelberg",
"feature",
"attribute_key",
)
indicator.result.value = 0.2
Expand All @@ -21,5 +21,26 @@ def topic_building_count():
assert indicator.description == (
"The ratio of the topic test-topic in "
"the selected area (all: 10) compared to the "
'topic test-topic with the expected tag "test-attribute" (matched: 2) is 0.2. '
"topic test-topic with the expected tag test-attribute (matched: 2) is 0.2. "
)


def test_create_description_multiple_attributes():
def topic_building_count():
pass

indicator = AttributeCompleteness(
topic_building_count,
"feature",
["tag_1", "tag_2", "tag_3"],
)
indicator.result.value = 0.2
indicator.absolute_value_1 = 10
indicator.absolute_value_2 = 2
indicator.topic.name = "test-topic"
indicator.create_description()
assert indicator.description == (
"The ratio of the topic test-topic in "
"the selected area (all: 10) compared to the topic "
"test-topic with the expected tags tag_1, tag_2, tag_3 (matched: 2) is 0.2. "
)

0 comments on commit 2082fe4

Please sign in to comment.