Commit 89734dba authored by Felix Delattre's avatar Felix Delattre
Browse files

Added tests for diff analyzer

parent 72539dd1
Pipeline #29857 passed with stage
in 2 minutes and 13 seconds
......@@ -34,3 +34,4 @@ repos:
rev: ecd1e81915cba81f1caa9544adfd188b37fe5deb
hooks:
- id: codespell
entry: codespell --skip="*.xml" spearhead tests
......@@ -104,8 +104,7 @@ class DiffAnalyzer:
elif isinstance(n, osmdiff.osm.osm.Relation):
numbers.append(-int(n.attribs.get("id")))
await self.file_handler.write_diff_report(augmented_diff.sequence_number, numbers)
await self._set_buildings_on_message_bus(numbers)
return numbers
async def _set_buildings_on_message_bus(self, numbers: list) -> None:
"""Set a list of building ids on the message bus"""
......
......@@ -71,8 +71,12 @@ async def get_changed_buildings(config: Configuration):
diff = await diff_analyzer.get_augmented_diff()
# Get identifiers of all buildings that have changed
await diff_analyzer.get_buildings(diff)
numbers = await diff_analyzer.get_buildings(diff)
await diff_analyzer.file_handler.write_diff_report(
diff.sequence_number, numbers
)
await diff_analyzer._set_buildings_on_message_bus(numbers)
await diff_analyzer.update_state(diff_number + 1)
# Wait until requesting more data
......
......@@ -18,9 +18,22 @@
import pytest
import osmdiff
from rabotnik import MessageBus
from spearhead.configure import Configuration
@pytest.fixture()
def config():
yield Configuration("./tests/config.yml")
@pytest.fixture()
def diff_provider():
yield osmdiff.AugmentedDiff()
@pytest.fixture()
def message_bus():
yield MessageBus()
This diff is collapsed.
#!/usr/bin/env python3
# Copyright (c) 2021:
# 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 osmdiff
import random
import pytest
from spearhead.diff_analyzer import DiffAnalyzer
logger = logging.getLogger()
@pytest.fixture
async def augmented_diff(diff_analyzer):
augmented_diff = osmdiff.AugmentedDiff(file="./tests/data/augmented-diff-4749548.xml")
augmented_diff.sequence_number = 4749548
yield augmented_diff
@pytest.fixture
def diff_analyzer(diff_provider, config, message_bus):
return DiffAnalyzer(diff_provider, config, message_bus)
@pytest.mark.asyncio
async def test_get_list_of_new_diffs(diff_analyzer):
numbers = await diff_analyzer.get_list_of_new_diffs()
assert numbers[0] == 4749548
@pytest.mark.asyncio
async def test_get_augmented_diff(augmented_diff):
assert isinstance(augmented_diff, osmdiff.AugmentedDiff)
assert augmented_diff.sequence_number == 4749548
@pytest.mark.asyncio
async def test_update_state(diff_analyzer):
await diff_analyzer.update_state(4749545)
state_number = await diff_analyzer.file_handler.read_state_file()
assert state_number == 4749545
await diff_analyzer.update_state(4749548)
state_number = await diff_analyzer.file_handler.read_state_file()
assert state_number == 4749548
@pytest.mark.asyncio
async def test_get_buildings(diff_analyzer, augmented_diff):
buildings = await diff_analyzer.get_buildings(augmented_diff)
assert isinstance(random.choice(buildings), int)
assert len(buildings) == 356
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment