Skip to content
Snippets Groups Projects

Resolve "Change the processing of the `stories` rule to a `height` GEM Taxonomy tag"

Compare and Show latest version
2 files
+ 64
2
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 129
0
#!/usr/bin/env python3
# Copyright (c) 2024:
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
import logging
import pytest
logger = logging.getLogger()
def test_height_and_floorspace_rule(height_and_floorspace_rule):
"""
Test the retrieval of number of stories, height and the floorspace, based on the tags from
OSM and GHSL.
"""
building_information = {
"tags": {
"building:levels": 5,
"roof:levels": 2,
"building:min_level": 1,
"building:levels:underground": 0,
},
"area": 300.0,
}
result = height_and_floorspace_rule(**building_information)
message = (
f"The `height` attribute is not correct. "
f"Expected `H:6` but estimated {result['height']}"
)
assert result["height"] == "H:6", message
message = (
f"The `floorspace` attribute is not correct. "
f"Expected `1350` but estimated {result['floorspace']}"
)
assert result["floorspace"] == pytest.approx(1350.0), message
def test_get_stories_and_floorspace_from_osm(height_and_floorspace_rule):
"""
Test the retrieval of number of stories and the floorspace, based on the tags from OSM.
"""
rule_function = height_and_floorspace_rule.function.get_stories_and_floorspace_from_osm
test_list = [
# Check with only building levels.
[{"tags": {"building:levels": 5}, "area": 100.0}, "H:5", 450.0],
# Check with only roof levels.
[{"tags": {"roof:levels": 5}, "area": 100.0}, "H:5", 225.0],
# Check with only levels underground.
[{"tags": {"building:levels:underground": 5}, "area": 100.0}, "HBEX:5", 450.0],
# Check with a wrong type as input.
[{"tags": {"building:levels": "no"}, "area": 100.0}, None, None],
# Check with a negative value.
[{"tags": {"building:levels:underground": -1}, "area": 100.0}, None, None],
# Check with a `building:min_level` value higher than the `building_levels` value.
[{"tags": {"building:levels": 5, "building:min_level": 6}, "area": 100.0}, None, None],
# Check without any tags.
[{"tags": {}, "area": 100.0}, None, None],
# Check with all tags.
[
{
"tags": {
"building:levels": 4,
"roof:levels": 2,
"building:min_level": 1,
"building:levels:underground": 1,
},
"area": 100.0,
},
"H:5+HBEX:1",
450.0,
],
]
for input_values, correct_height, correct_floorspace in test_list:
height, floorspace = rule_function(**input_values)
# Check the height attribute
message = (
f"The `height` attribute is not correct. Expected `{correct_height}` but estimated "
f"`{height}` using {input_values} as input."
)
assert height == correct_height, message
# Check the floorspace attribute
message = (
f"The `floorspace` attribute is not correct. Expected `{correct_floorspace}` but "
f"estimated `{floorspace}` using {input_values} as input."
)
assert floorspace == correct_floorspace, message
def test_tag_to_float(height_and_floorspace_rule):
"""
Test the function `tag_to_float` of the `HeightAndFloorspaceRule.
"""
rule_function = height_and_floorspace_rule.function.tag_to_float
tags = {
"correct_01": "1",
"correct_02": "1.5",
"correct_03": "-1",
"incorrect_01": "ground_floor",
"incorrect_02": "1,5",
}
assert rule_function(tags, "correct_01") == pytest.approx(1.0)
assert rule_function(tags, "correct_02") == pytest.approx(1.5)
assert rule_function(tags, "correct_03") == pytest.approx(-1.0)
assert rule_function(tags, "incorrect_01") is None
assert rule_function(tags, "incorrect_02") is None
assert rule_function(tags, "incorrect_03") is None # Value is not there.
Loading